3.4 <SoupMessageHeaders>

Structure: <SoupMessageHeaders>

The HTTP message headers associated with a request or response.

Procedures

Method: message-headers:append self name value
Method: append self name value

Appends a new header with name name and value value to self.

(If there is an existing header with name name, then this creates a second one, which is only allowed for list-valued headers; see also MessageHeaders.replace.)

The caller is expected to make sure that name and value are syntactically correct.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

name

Passed: a string.

the header name to add

value

Passed: a string.

the new value of name

Method: message-headers:clean-connection-headers self
Method: clean-connection-headers self

Removes all the headers listed in the Connection header.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

Method: message-headers:clear self
Method: clear self

Clears self.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

Method: message-headers:foreach self func
Method: foreach self func

Calls func once for each header value in self.

Beware that unlike MessageHeaders.get_list, this processes the headers in exactly the way they were added, rather than concatenating multiple same-named headers into a single value. (This is intentional; it ensures that if you call MessageHeaders.append multiple times with the same name, then the I/O code will output multiple copies of the header when sending the message to the remote implementation, which may be required for interoperability in some cases.)

You may not modify the headers from func.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

func

Passed: a procedure.

callback function to run for each header

See SoupMessageHeadersForeachFunc for how it is called.

user-data

Not passed: guile-gi supplies it.

data to pass to func

Method: message-headers:get-content-disposition self ⇒ %return disposition params
Method: get-content-disposition self ⇒ %return disposition params

Looks up the "Content-Disposition" header in self, parses it, and returns its value in *disposition and *params.

params can be #f if you are only interested in the disposition-type.

In HTTP, the most common use of this header is to set a disposition-type of "attachment", to suggest to the browser that a response should be saved to disk rather than displayed in the browser. If params contains a "filename" parameter, this is a suggestion of a filename to use. (If the parameter value in the header contains an absolute or relative path, libsoup will truncate it down to just the final path component, so you do not need to test this yourself.)

Content-Disposition is also used in "multipart/form-data", however this is handled automatically by Multipart and the associated form methods.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

%return

Returned: a boolean.

#t if self contains a "Content-Disposition" header, #f if not (in which case *disposition and *params will be unchanged).

disposition

Returned: a string.

return location for the disposition-type, or #f

params

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

return location for the Content-Disposition parameters, or #f

Method: message-headers:get-content-length self ⇒ %return
Method: get-content-length self ⇒ %return

Gets the message body length that self declare.

This will only be non-0 if MessageHeaders.get_encoding returns content-length.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

%return

Returned: a 64-bit integer.

the message body length declared by self.

Method: message-headers:get-content-range self ⇒ %return start end total-length
Method: get-content-range self ⇒ %return start end total-length

Parses self’s Content-Range header and returns it in start, end, and total-length. If the total length field in the header was specified as "*", then total-length will be set to -1.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

%return

Returned: a boolean.

#t if self contained a "Content-Range" header containing a byte range which could be parsed, #f otherwise.

start

Returned: a 64-bit integer.

return value for the start of the range

end

Returned: a 64-bit integer.

return value for the end of the range

total-length

Returned: a 64-bit integer.

return value for the total length of the resource, or #f if you don’t care.

Method: message-headers:get-content-type self ⇒ %return params
Method: get-content-type self ⇒ %return params

Looks up the "Content-Type" header in self, parses it, and returns its value in *content-type and *params.

params can be #f if you are only interested in the content type itself.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

%return

Returned: a string, or #f.

a string with the value of the "Content-Type" header or #f if self does not contain that header or it cannot be parsed (in which case *params will be unchanged).

params

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

return location for the Content-Type parameters (eg, "charset"), or #f

Method: message-headers:get-encoding self ⇒ %return
Method: get-encoding self ⇒ %return

Gets the message body encoding that self declare.

This may not always correspond to the encoding used on the wire; eg, a HEAD response may declare a Content-Length or Transfer-Encoding, but it will never actually include a body.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

%return

Returned: a <SoupEncoding>.

the encoding declared by self.

Method: message-headers:get-expectations self ⇒ %return
Method: get-expectations self ⇒ %return

Gets the expectations declared by self’s "Expect" header.

Currently this will either be continue or unrecognized.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

%return

Returned: a <SoupExpectation>.

the contents of self’s "Expect" header

Method: message-headers:get-headers-type self ⇒ %return
Method: get-headers-type self ⇒ %return

Gets the type of headers.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

%return

Returned: a <SoupMessageHeadersType>.

the header’s type.

Method: message-headers:get-list self name ⇒ %return
Method: get-list self name ⇒ %return

Gets the value of header name in self.

Use this for headers whose values are comma-delimited lists, and which are therefore allowed to appear multiple times in the headers. For non-list-valued headers, use MessageHeaders.get_one.

If name appears multiple times in self, MessageHeaders.get_list will concatenate all of the values together, separated by commas. This is sometimes awkward to parse (eg, WWW-Authenticate, Set-Cookie), but you have to be able to deal with it anyway, because the HTTP spec explicitly states that this transformation is allowed, and so an upstream proxy could do the same thing.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

name

Passed: a string.

header name

%return

Returned: a string, or #f.

the header’s value or #f if not found.

Method: message-headers:get-one self name ⇒ %return
Method: get-one self name ⇒ %return

Gets the value of header name in self.

Use this for headers whose values are not comma-delimited lists, and which therefore can only appear at most once in the headers. For list-valued headers, use MessageHeaders.get_list.

If self does erroneously contain multiple copies of the header, it is not defined which one will be returned. (Ideally, it will return whichever one makes libsoup most compatible with other HTTP implementations.)

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

name

Passed: a string.

header name

%return

Returned: a string, or #f.

the header’s value or #f if not found.

Method: message-headers:header-contains? self name token ⇒ %return
Method: header-contains? self name token ⇒ %return

Checks whether the list-valued header name is present in self, and contains a case-insensitive match for token.

(If name is present in self, then this is equivalent to calling header_contains on its value.)

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

name

Passed: a string.

header name

token

Passed: a string.

token to look for

%return

Returned: a boolean.

#t if the header is present and contains token, #f otherwise.

Method: message-headers:header-equals? self name value ⇒ %return
Method: header-equals? self name value ⇒ %return

Checks whether the header name is present in self and is (case-insensitively) equal to value.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

name

Passed: a string.

header name

value

Passed: a string.

expected value

%return

Returned: a boolean.

#t if the header is present and its value is value, #f otherwise.

Procedure: message-headers:new type ⇒ %return

Creates a MessageHeaders.

(Message does this automatically for its own headers. You would only need to use this method if you are manually parsing or generating message headers.)

type

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

the type of headers

%return

Returned: a <SoupMessageHeaders>.

a new <SoupMessageHeaders>

Method: message-headers:ref self ⇒ %return
Method: ref self ⇒ %return

Atomically increments the reference count of self by one.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

%return

Returned: a <SoupMessageHeaders>.

the passed in <SoupMessageHeaders>

Method: message-headers:remove self name
Method: remove self name

Removes name from self.

If there are multiple values for name, they are all removed.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

name

Passed: a string.

the header name to remove

Method: message-headers:replace self name value
Method: replace self name value

Replaces the value of the header name in self with value.

See also MessageHeaders.append.

The caller is expected to make sure that name and value are syntactically correct.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

name

Passed: a string.

the header name to replace

value

Passed: a string.

the new value of name

Method: message-headers:set-content-disposition self disposition [params]
Method: set-content-disposition self disposition [params]

Sets the "Content-Disposition" header in self to disposition, optionally with additional parameters specified in params.

See MessageHeaders.get_content_disposition for a discussion of how Content-Disposition is used in HTTP.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

disposition

Passed: a string.

the disposition-type

params

Passed, or left out: a hash table, each key a string and each value a string, or #f.

additional parameters

Method: message-headers:set-content-length self content-length
Method: set-content-length self content-length

Sets the message body length that self will declare, and sets self’s encoding to content-length.

You do not normally need to call this; if self is set to use Content-Length encoding, libsoup will automatically set its Content-Length header for you immediately before sending the headers. One situation in which this method is useful is when generating the response to a HEAD request; Calling MessageHeaders.set_content_length allows you to put the correct content length into the response without needing to waste memory by filling in a response body which won’t actually be sent.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

content-length

Passed: a 64-bit integer.

the message body length

Method: message-headers:set-content-range self start end total-length
Method: set-content-range self start end total-length

Sets self’s Content-Range header according to the given values.

(Note that total-length is the total length of the entire resource that this is a range of, not simply end - start + 1.)

Server has built-in handling for range requests, and you do not normally need to call this function youself. See MessageHeaders.get_ranges for more details.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

start

Passed: a 64-bit integer.

the start of the range

end

Passed: a 64-bit integer.

the end of the range

total-length

Passed: a 64-bit integer.

the total length of the resource, or -1 if unknown

Method: message-headers:set-content-type self content-type [params]
Method: set-content-type self content-type [params]

Sets the "Content-Type" header in self to content-type.

Accepts additional parameters specified in params.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

content-type

Passed: a string.

the MIME type

params

Passed, or left out: a hash table, each key a string and each value a string, or #f.

additional parameters

Method: message-headers:set-encoding self encoding
Method: set-encoding self encoding

Sets the message body encoding that self will declare.

In particular, you should use this if you are going to send a request or response in chunked encoding.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

encoding

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

a <SoupEncoding>

Method: message-headers:set-expectations self expectations
Method: set-expectations self expectations

Sets self’s "Expect" header according to expectations.

Currently continue is the only known expectation value. You should set this value on a request if you are sending a large message body (eg, via POST or PUT), and want to give the server a chance to reject the request after seeing just the headers (eg, because it will require authentication before allowing you to post, or because you’re POSTing to a URL that doesn’t exist). This saves you from having to transmit the large request body when the server is just going to ignore it anyway.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

expectations

Passed: a <SoupExpectation>, or a list of its symbols, or one of them.

the expectations to set

Method: message-headers:set-range self start end
Method: set-range self start end

Sets self’s Range header to request the indicated range.

start and end are interpreted as in a Range.

If you need to request multiple ranges, use MessageHeaders.set_ranges.

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>

start

Passed: a 64-bit integer.

the start of the range to request

end

Passed: a 64-bit integer.

the end of the range to request

Method: message-headers:unref self
Method: unref self

Atomically decrements the reference count of self by one.

When the reference count reaches zero, the resources allocated by self are freed

self

Passed: a <SoupMessageHeaders>.

a <SoupMessageHeaders>