7 Functions

Procedure: check-version? major minor micro ⇒ %return

Like CHECK_VERSION, but the check for soup_check_version is at runtime instead of compile time.

This is useful for compiling against older versions of libsoup, but using features from newer versions.

major

Passed: an unsigned 32-bit integer.

the major version to check

minor

Passed: an unsigned 32-bit integer.

the minor version to check

micro

Passed: an unsigned 32-bit integer.

the micro version to check

%return

Returned: a boolean.

#t if the version of the libsoup currently loaded is the same as or newer than the passed-in version.

Parses header and returns a Cookie.

If header contains multiple cookies, only the first one will be parsed.

If header does not have "path" or "domain" attributes, they will be defaulted from origin. If origin is #f, path will default to "/", but domain will be left as #f. Note that this is not a valid state for a Cookie, and you will need to fill in some appropriate string for the domain if you want to actually make use of the cookie.

As of version 3.4.0 the default value of a cookie’s same-site-policy is lax.

header

Passed: a string.

a cookie string (eg, the value of a Set-Cookie header)

origin

Passed, or left out: a <GUri>, or #f.

origin of the cookie

%return

Returned: a <SoupCookie>, or #f.

a new <SoupCookie>, or #f if it could not be parsed, or contained an illegal "domain" attribute for a cookie originating from origin.

Procedure: cookies-from-request msg ⇒ %return

Parses msg’s Cookie request header and returns a <GSList> of <SoupCookie>s.

As the "Cookie" header, unlike "Set-Cookie", only contains cookie names and values, none of the other Cookie fields will be filled in. (Thus, you can’t generally pass a cookie returned from this method directly to cookies_to_response.)

msg

Passed: a <SoupMessage>.

a <SoupMessage> containing a "Cookie" request header

%return

Returned: a list, each a <SoupCookie>.

a GSList of <SoupCookie>s, which can be freed with Cookie.free.

Procedure: cookies-from-response msg ⇒ %return

Parses msg’s Set-Cookie response headers and returns a <GSList> of <SoupCookie>s.

Cookies that do not specify "path" or "domain" attributes will have their values defaulted from msg.

msg

Passed: a <SoupMessage>.

a <SoupMessage> containing a "Set-Cookie" response header

%return

Returned: a list, each a <SoupCookie>.

a GSList of <SoupCookie>s, which can be freed with Cookie.free.

Procedure: cookies-to-cookie-header cookies ⇒ %return

Serializes a <GSList> of Cookie into a string suitable for setting as the value of the "Cookie" header.

cookies

Passed: a list, each a <SoupCookie>.

a GSList of Cookie

%return

Returned: a string.

the serialization of cookies

Procedure: cookies-to-request cookies msg

Adds the name and value of each cookie in cookies to msg’s "Cookie" request.

If msg already has a "Cookie" request header, these cookies will be appended to the cookies already present. Be careful that you do not append the same cookies twice, eg, when requeuing a message.

cookies

Passed: a list, each a <SoupCookie>.

a GSList of Cookie

msg

Passed: a <SoupMessage>.

a <SoupMessage>

Procedure: cookies-to-response cookies msg

Appends a "Set-Cookie" response header to msg for each cookie in cookies.

This is in addition to any other "Set-Cookie" headers msg may already have.

cookies

Passed: a list, each a <SoupCookie>.

a GSList of Cookie

msg

Passed: a <SoupMessage>.

a <SoupMessage>

Procedure: date-time-new-from-http-string date-string ⇒ %return

Parses date-string and tries to extract a date from it.

This recognizes all of the "HTTP-date" formats from RFC 2616, RFC 2822 dates, and reasonable approximations thereof. (Eg, it is lenient about whitespace, leading "0"s, etc.)

date-string

Passed: a string.

The date as a string

%return

Returned: a <GDateTime>, or #f.

a new <GDateTime>, or #f if date-string could not be parsed.

Procedure: date-time-to-string date format ⇒ %return

Converts date to a string in the format described by format.

date

Passed: a <GDateTime>.

a <GDateTime>

format

Passed: a <SoupDateFormat>, or one of its symbols.

the format to generate the date in

%return

Returned: a string.

date as a string or #f

Procedure: form-decode encoded-form ⇒ %return

Decodes form.

which is an urlencoded dataset as defined in the HTML 4.01 spec.

encoded-form

Passed: a string.

data of type "application/x-www-form-urlencoded"

%return

Returned: a hash table, each key a string and each value a string.

a hash table containing the name/value pairs from encoded-form, which you can free with hash-table:destroy.

Procedure: form-decode-multipart multipart [file-control-name] ⇒ %return filename content-type file

Decodes the "multipart/form-data" request in multipart.

this is a convenience method for the case when you have a single file upload control in a form. (Or when you don’t have any file upload controls, but are still using "multipart/form-data" anyway.) Pass the name of the file upload control in file-control-name, and form_decode_multipart will extract the uploaded file data into filename, content-type, and file. All of the other form control data will be returned (as strings, as with form_decode in the returned <GHashTable>.

You may pass #f for filename, content-type and/or file if you do not care about those fields. form_decode_multipart may also return #f in those fields if the client did not provide that information. You must free the returned filename and content-type with byte-array:free, and the returned file data with Glib.Bytes.unref.

If you have a form with more than one file upload control, you will need to decode it manually, using Multipart.new_from_message and Multipart.get_part.

multipart

Passed: a <SoupMultipart>.

a <SoupMultipart>

file-control-name

Passed, or left out: a string, or #f.

the name of the HTML file upload control

%return

Returned: a hash table, each key a string and each value a string, or #f.

a hash table containing the name/value pairs (other than file-control-name) from msg, which you can free with hash-table:destroy. On error, it will return #f.

filename

Returned: a string.

return location for the name of the uploaded file

content-type

Returned: a string.

return location for the MIME type of the uploaded file

file

Returned: a <GBytes>.

return location for the uploaded file data

Procedure: form-encode-hash form-data-set ⇒ %return

Encodes form-data-set into a value of type "application/x-www-form-urlencoded".

Encodes as defined in the HTML 4.01 spec.

Note that the HTML spec states that "The control names/values are listed in the order they appear in the document." Since this method takes a hash table, it cannot enforce that; if you care about the ordering of the form fields, use form_encode_datalist.

See also: Message.new_from_encoded_form.

form-data-set

Passed: a hash table, each key a string and each value a string.

a hash table containing name/value pairs (as strings)

%return

Returned: a string.

the encoded form

Procedure: get-major-version ⇒ %return

Returns the major version number of the libsoup library.

e.g. in libsoup version 2.42.0 this is 2.

This function is in the library, so it represents the libsoup library your code is running against. Contrast with the SOUP_MAJOR_VERSION macro, which represents the major version of the libsoup headers you have included when compiling your code.

%return

Returned: an unsigned 32-bit integer.

the major version number of the libsoup library

Procedure: get-micro-version ⇒ %return

Returns the micro version number of the libsoup library.

e.g. in libsoup version 2.42.0 this is 0.

This function is in the library, so it represents the libsoup library your code is running against. Contrast with the SOUP_MICRO_VERSION macro, which represents the micro version of the libsoup headers you have included when compiling your code.

%return

Returned: an unsigned 32-bit integer.

the micro version number of the libsoup library

Procedure: get-minor-version ⇒ %return

Returns the minor version number of the libsoup library.

e.g. in libsoup version 2.42.0 this is 42.

This function is in the library, so it represents the libsoup library your code is running against. Contrast with the SOUP_MINOR_VERSION macro, which represents the minor version of the libsoup headers you have included when compiling your code.

%return

Returned: an unsigned 32-bit integer.

the minor version number of the libsoup library

Procedure: header-contains? header token ⇒ %return

Parses header to see if it contains the token token (matched case-insensitively).

Note that this can’t be used with lists that have qvalues.

header

Passed: a string.

An HTTP header suitable for parsing with header_parse_list

token

Passed: a string.

a token

%return

Returned: a boolean.

whether or not header contains token

Procedure: header-free-param-list param-list

Frees param-list.

param-list

Passed: a hash table, each key a string and each value a string.

a <GHashTable> returned from header_parse_param_list or header_parse_semi_param_list

Procedure: header-g-string-append-param string name [value]

Appends something like name=value to string, taking care to quote value if needed, and if so, to escape any quotes or backslashes in value.

Alternatively, if value is a non-ASCII UTF-8 string, it will be appended using RFC5987 syntax. Although in theory this is supposed to work anywhere in HTTP that uses this style of parameter, in reality, it can only be used portably with the Content-Disposition "filename" parameter.

If value is #f, this will just append name to string.

string

Passed: a <GString>.

a <GString> being used to construct an HTTP header value

name

Passed: a string.

a parameter name

value

Passed, or left out: a string, or #f.

a parameter value, or #f

Procedure: header-g-string-append-param-quoted string name value

Appends something like name="value" to string, taking care to escape any quotes or backslashes in value.

If value is (non-ASCII) UTF-8, this will instead use RFC 5987 encoding, just like header_g_string_append_param.

string

Passed: a <GString>.

a <GString> being used to construct an HTTP header value

name

Passed: a string.

a parameter name

value

Passed: a string.

a parameter value

Procedure: header-parse-list header ⇒ %return

Parses a header whose content is described by RFC2616 as #something.

"something" does not itself contain commas, except as part of quoted-strings.

header

Passed: a string.

a header value

%return

Returned: a list, each a string.

a GSList of list elements, as allocated strings

Procedure: header-parse-param-list header ⇒ %return

Parses a header which is a comma-delimited list of something like: token [ "=" ( token | quoted-string ) ].

Tokens that don’t have an associated value will still be added to the resulting hash table, but with a #f value.

This also handles RFC5987 encoding (which in HTTP is mostly used for giving UTF8-encoded filenames in the Content-Disposition header).

header

Passed: a string.

a header value

%return

Returned: a hash table, each key a string and each value a string.

a <GHashTable> of list elements, which can be freed with header_free_param_list.

Procedure: header-parse-param-list-strict header ⇒ %return

A strict version of header_parse_param_list that bails out if there are duplicate parameters.

Note that this function will treat RFC5987-encoded parameters as duplicated if an ASCII version is also present. For header fields that might contain RFC5987-encoded parameters, use header_parse_param_list instead.

header

Passed: a string.

a header value

%return

Returned: a hash table, each key a string and each value a string, or #f.

a <GHashTable> of list elements, which can be freed with header_free_param_list or #f if there are duplicate elements.

Procedure: header-parse-quality-list header ⇒ %return unacceptable

Parses a header whose content is a list of items with optional "qvalue"s (eg, Accept, Accept-Charset, Accept-Encoding, Accept-Language, TE).

If unacceptable is not #f, then on return, it will contain the items with qvalue 0. Either way, those items will be removed from the main list.

header

Passed: a string.

a header value

%return

Returned: a list, each a string.

a GSList of acceptable values (as allocated strings), highest-qvalue first.

unacceptable

Returned: a list, each a string.

on return, will contain a list of unacceptable values

Procedure: header-parse-semi-param-list header ⇒ %return

Parses a header which is a semicolon-delimited list of something like: token [ "=" ( token | quoted-string ) ].

Tokens that don’t have an associated value will still be added to the resulting hash table, but with a #f value.

This also handles RFC5987 encoding (which in HTTP is mostly used for giving UTF8-encoded filenames in the Content-Disposition header).

header

Passed: a string.

a header value

%return

Returned: a hash table, each key a string and each value a string.

a <GHashTable> of list elements, which can be freed with header_free_param_list.

Procedure: header-parse-semi-param-list-strict header ⇒ %return

A strict version of header_parse_semi_param_list that bails out if there are duplicate parameters.

Note that this function will treat RFC5987-encoded parameters as duplicated if an ASCII version is also present. For header fields that might contain RFC5987-encoded parameters, use header_parse_semi_param_list instead.

header

Passed: a string.

a header value

%return

Returned: a hash table, each key a string and each value a string, or #f.

a <GHashTable> of list elements, which can be freed with header_free_param_list or #f if there are duplicate elements.

Procedure: headers-parse-request str len req-headers ⇒ %return req-method req-path ver

Parses the headers of an HTTP request in str and stores the results in req-method, req-path, ver, and req-headers.

Beware that req-headers may be modified even on failure.

str

Passed: a string.

the headers (up to, but not including, the trailing blank line)

len

Passed: a 32-bit integer.

length of str

req-headers

Passed: a <SoupMessageHeaders>.

<SoupMessageHeaders> to store the header values in

%return

Returned: an unsigned 32-bit integer.

ok if the headers could be parsed, or an HTTP error to be returned to the client if they could not be.

req-method

Returned: a string.

if non-#f, will be filled in with the request method

req-path

Returned: a string.

if non-#f, will be filled in with the request path

ver

Returned: a <SoupHTTPVersion>.

if non-#f, will be filled in with the HTTP version

Procedure: headers-parse-response str len headers ⇒ %return ver status-code reason-phrase

Parses the headers of an HTTP response in str and stores the results in ver, status-code, reason-phrase, and headers.

Beware that headers may be modified even on failure.

str

Passed: a string.

the headers (up to, but not including, the trailing blank line)

len

Passed: a 32-bit integer.

length of str

headers

Passed: a <SoupMessageHeaders>.

<SoupMessageHeaders> to store the header values in

%return

Returned: a boolean.

success or failure.

ver

Returned: a <SoupHTTPVersion>.

if non-#f, will be filled in with the HTTP version

status-code

Returned: an unsigned 32-bit integer.

if non-#f, will be filled in with the status code

reason-phrase

Returned: a string.

if non-#f, will be filled in with the reason phrase

Procedure: headers-parse-status-line status-line ⇒ %return ver status-code reason-phrase

Parses the HTTP Status-Line string in status-line into ver, status-code, and reason-phrase.

status-line must be terminated by either "\0" or "\r\n".

status-line

Passed: a string.

an HTTP Status-Line

%return

Returned: a boolean.

#t if status-line was parsed successfully.

ver

Returned: a <SoupHTTPVersion>.

if non-#f, will be filled in with the HTTP version

status-code

Returned: an unsigned 32-bit integer.

if non-#f, will be filled in with the status code

reason-phrase

Returned: a string.

if non-#f, will be filled in with the reason phrase

Procedure: headers-parse? str len dest ⇒ %return

Parses the headers of an HTTP request or response in str and stores the results in dest.

Beware that dest may be modified even on failure.

This is a low-level method; normally you would use headers_parse_request or headers_parse_response.

str

Passed: a string.

the header string (including the Request-Line or Status-Line, but not the trailing blank line)

len

Passed: a 32-bit integer.

length of str

dest

Passed: a <SoupMessageHeaders>.

<SoupMessageHeaders> to store the header values in

%return

Returned: a boolean.

success or failure

Procedure: session-error-quark ⇒ %return

Registers error quark for SoupSession if needed.

%return

Returned: an unsigned 32-bit integer.

Error quark for SoupSession.

Procedure: status-get-phrase status-code ⇒ %return

Looks up the stock HTTP description of status-code.

There is no reason for you to ever use this function. If you wanted the textual description for the Message:status-code of a given Message, you should just look at the message’s Message:reason-phrase. However, you should only do that for use in debugging messages; HTTP reason phrases are not localized, and are not generally very descriptive anyway, and so they should never be presented to the user directly. Instead, you should create you own error messages based on the status code, and on what you were trying to do.

status-code

Passed: an unsigned 32-bit integer.

an HTTP status code

%return

Returned: a string.

the (terse, English) description of status-code

Procedure: tld-domain-is-public-suffix? domain ⇒ %return

Looks whether the domain passed as argument is a public domain suffix (.org, .com, .co.uk, etc) or not.

Prior to libsoup 2.46, this function required that domain be in UTF-8 if it was an IDN. From 2.46 on, the name can be in either UTF-8 or ASCII format.

domain

Passed: a string.

a domain name

%return

Returned: a boolean.

#t if it is a public domain, #f otherwise.

Procedure: tld-error-quark ⇒ %return

Registers error quark for tld-get-base-domain if needed.

%return

Returned: an unsigned 32-bit integer.

Error quark for Soup TLD functions.

Procedure: tld-get-base-domain hostname ⇒ %return

Finds the base domain for a given hostname

The base domain is composed by the top level domain (such as .org, .com, .co.uk, etc) plus the second level domain, for example for myhost.mydomain.com it will return mydomain.com.

Note that #f will be returned for private URLs (those not ending with any well known TLD) because choosing a base domain for them would be totally arbitrary.

Prior to libsoup 2.46, this function required that hostname be in UTF-8 if it was an IDN. From 2.46 on, the name can be in either UTF-8 or ASCII format (and the return value will be in the same format).

hostname

Passed: a string.

a hostname

%return

Returned: a string.

a pointer to the start of the base domain in hostname. If an error occurs, #f will be returned and error set.

Procedure: uri-decode-data-uri uri ⇒ %return content-type

Decodes the given data URI and returns its contents and content-type.

uri

Passed: a string.

a data URI, in string form

%return

Returned: a <GBytes>.

a <GBytes> with the contents of uri, or #f if uri is not a valid data URI

content-type

Returned: a string, or #f.

location to store content type

Procedure: uri-equal? uri1 uri2 ⇒ %return

Tests whether or not uri1 and uri2 are equal in all parts.

uri1

Passed: a <GUri>.

a <GUri>

uri2

Passed: a <GUri>.

another <GUri>

%return

Returned: a boolean.

#t if equal otherwise #f

Procedure: websocket-error-quark ⇒ %return

Registers error quark for SoupWebsocket if needed.

%return

Returned: an unsigned 32-bit integer.

Error quark for SoupWebsocket.