Class MessageHeaders
-
Constructor Summary
ConstructorsConstructorDescriptionMessageHeaders(MemorySegment address) Create a MessageHeaders proxy instance for the provided memory address.Creates aSoupMessageHeaders. -
Method Summary
Modifier and TypeMethodDescriptionvoidAppends a new header with namenameand valuevaluetohdrs.voidRemoves all the headers listed in the Connection header.voidclear()Clearshdrs.voidforeach(@Nullable MessageHeadersForeachFunc func) Callsfunconce for each header value inhdrs.voidfreeRanges(Range ranges) Frees the array of ranges returned fromgetRanges(long, org.javagi.base.Out<org.gnome.soup.Range[]>).booleanLooks up the "Content-Disposition" header inhdrs,parses it, and returns its value in *dispositionand *params.longGets the message body length that this MessageHeaders declare.booleanParseshdrs'sContent-Range header and returns it instart,end,andtotalLength.If the total length field in the header was specified as "*", thentotalLengthwill be set to -1.@Nullable StringgetContentType(@Nullable Out<HashTable<String, String>> params) Looks up the "Content-Type" header inhdrs,parses it, and returns its value in *contentTypeand *params.Gets the message body encoding that this MessageHeaders declare.Gets the expectations declared byhdrs's"Expect" header.Gets the type of headers.@Nullable StringGets the value of headernameinhdrs.@Nullable StringGets the value of headernameinhdrs.booleanParseshdrs'sRange header and returns an array of the requested byte ranges.static @Nullable TypegetType()Get the GType of the MessageHeaders classbooleanheaderContains(String name, String token) Checks whether the list-valued headernameis present inhdrs,and contains a case-insensitive match fortoken.booleanheaderEquals(String name, String value) Checks whether the headernameis present in this MessageHeaders and is (case-insensitively) equal tovalue.ref()Atomically increments the reference count of this MessageHeaders by one.voidRemovesnamefromhdrs.voidReplaces the value of the headernamein this MessageHeaders withvalue.voidsetContentDisposition(String disposition, @Nullable HashTable<String, String> params) Sets the "Content-Disposition" header in this MessageHeaders todisposition,optionally with additional parameters specified inparams.voidsetContentLength(long contentLength) Sets the message body length that this MessageHeaders will declare, and setshdrs'sencoding toEncoding.CONTENT_LENGTH.voidsetContentRange(long start, long end, long totalLength) Setshdrs'sContent-Range header according to the given values.voidsetContentType(String contentType, @Nullable HashTable<String, String> params) Sets the "Content-Type" header in this MessageHeaders tocontentType.voidsetEncoding(Encoding encoding) Sets the message body encoding that this MessageHeaders will declare.voidsetExpectations(Set<Expectation> expectations) Setshdrs's"Expect" header according toexpectations.voidsetExpectations(Expectation... expectations) Setshdrs's"Expect" header according toexpectations.voidsetRange(long start, long end) Setshdrs'sRange header to request the indicated range.voidSetshdrs'sRange header to request the indicated ranges.voidunref()Atomically decrements the reference count of this MessageHeaders by one.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
MessageHeaders
Create a MessageHeaders proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
MessageHeaders
Creates aSoupMessageHeaders.(
Messagedoes this automatically for its own headers. You would only need to use this method if you are manually parsing or generating message headers.)- Parameters:
type- the type of headers
-
-
Method Details
-
getType
-
append
Appends a new header with namenameand valuevaluetohdrs.(If there is an existing header with name
name,then this creates a second one, which is only allowed for list-valued headers; see alsoreplace(java.lang.String, java.lang.String).)The caller is expected to make sure that
nameandvalueare syntactically correct.- Parameters:
name- the header name to addvalue- the new value ofname
-
cleanConnectionHeaders
public void cleanConnectionHeaders()Removes all the headers listed in the Connection header. -
clear
public void clear()Clearshdrs. -
foreach
Callsfunconce for each header value inhdrs.Beware that unlike
getList(java.lang.String), 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 callappend(java.lang.String, java.lang.String)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.- Parameters:
func- callback function to run for each header
-
freeRanges
Frees the array of ranges returned fromgetRanges(long, org.javagi.base.Out<org.gnome.soup.Range[]>).- Parameters:
ranges- an array ofSoupRange
-
getContentDisposition
Looks up the "Content-Disposition" header inhdrs,parses it, and returns its value in *dispositionand *params.paramscan benullif 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
paramscontains 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
Multipartand the associated form methods.- Parameters:
disposition- return location for the disposition-type, ornullparams- return location for the Content-Disposition parameters, ornull- Returns:
trueif this MessageHeaders contains a "Content-Disposition" header,falseif not (in which case *dispositionand *paramswill be unchanged).
-
getContentLength
public long getContentLength()Gets the message body length that this MessageHeaders declare.This will only be non-0 if
getEncoding()returnsEncoding.CONTENT_LENGTH.- Returns:
- the message body length declared by
hdrs.
-
getContentRange
Parseshdrs'sContent-Range header and returns it instart,end,andtotalLength.If the total length field in the header was specified as "*", thentotalLengthwill be set to -1.- Parameters:
start- return value for the start of the rangeend- return value for the end of the rangetotalLength- return value for the total length of the resource, ornullif you don't care.- Returns:
trueif this MessageHeaders contained a "Content-Range" header containing a byte range which could be parsed,falseotherwise.
-
getContentType
Looks up the "Content-Type" header inhdrs,parses it, and returns its value in *contentTypeand *params.paramscan benullif you are only interested in the content type itself.- Parameters:
params- return location for the Content-Type parameters (eg, "charset"), ornull- Returns:
- a string with the value of the
"Content-Type" header or
nullif this MessageHeaders does not contain that header or it cannot be parsed (in which case *paramswill be unchanged).
-
getEncoding
Gets the message body encoding that this MessageHeaders 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.
- Returns:
- the encoding declared by
hdrs.
-
getExpectations
Gets the expectations declared byhdrs's"Expect" header.Currently this will either be
Expectation.CONTINUEorExpectation.UNRECOGNIZED.- Returns:
- the contents of
hdrs's"Expect" header
-
getHeadersType
-
getList
Gets the value of headernameinhdrs.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
getOne(java.lang.String).If
nameappears multiple times inhdrs,getList(java.lang.String)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.- Parameters:
name- header name- Returns:
- the header's value or
nullif not found.
-
getOne
Gets the value of headernameinhdrs.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
getList(java.lang.String).If this MessageHeaders 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.)
- Parameters:
name- header name- Returns:
- the header's value or
nullif not found.
-
getRanges
Parseshdrs'sRange header and returns an array of the requested byte ranges.The returned array must be freed with
freeRanges(org.gnome.soup.Range).If
totalLengthis non-0, its value will be used to adjust the returned ranges to have explicit start and end values, and the returned ranges will be sorted and non-overlapping. IftotalLengthis 0, then some ranges may have an end value of -1, as described underRange, and some of the ranges may be redundant.Beware that even if given a
totalLength,this function does not check that the ranges are satisfiable.SoupServerhas built-in handling for range requests. If your server handler returns aStatus.OKresponse containing the complete response body (rather than pausing the message and returning some of the response body later), and there is a Range header in the request, then libsoup will automatically convert the response to aStatus.PARTIAL_CONTENTresponse containing only the range(s) requested by the client.The only time you need to process the Range header yourself is if either you need to stream the response body rather than returning it all at once, or you do not already have the complete response body available, and only want to generate the parts that were actually requested by the client.
- Parameters:
totalLength- the total_length of the response bodyranges- return location for an array ofSoupRange- Returns:
trueif this MessageHeaders contained a syntactically-valid "Range" header,falseotherwise (in which caserangeandlengthwill not be set).
-
headerContains
Checks whether the list-valued headernameis present inhdrs,and contains a case-insensitive match fortoken.(If
nameis present inhdrs,then this is equivalent to callingSoup.headerContains(java.lang.String, java.lang.String)on its value.)- Parameters:
name- header nametoken- token to look for- Returns:
trueif the header is present and containstoken,falseotherwise.
-
headerEquals
-
ref
Atomically increments the reference count of this MessageHeaders by one.- Returns:
- the passed in
SoupMessageHeaders
-
remove
Removesnamefromhdrs.If there are multiple values for
name,they are all removed.- Parameters:
name- the header name to remove
-
replace
Replaces the value of the headernamein this MessageHeaders withvalue.See also
append(java.lang.String, java.lang.String).The caller is expected to make sure that
nameandvalueare syntactically correct.- Parameters:
name- the header name to replacevalue- the new value ofname
-
setContentDisposition
Sets the "Content-Disposition" header in this MessageHeaders todisposition,optionally with additional parameters specified inparams.See
getContentDisposition(org.javagi.base.Out<java.lang.String>, org.javagi.base.Out<org.gnome.glib.HashTable<java.lang.String, java.lang.String>>)for a discussion of how Content-Disposition is used in HTTP.- Parameters:
disposition- the disposition-typeparams- additional parameters
-
setContentLength
public void setContentLength(long contentLength) Sets the message body length that this MessageHeaders will declare, and setshdrs'sencoding toEncoding.CONTENT_LENGTH.You do not normally need to call this; if this MessageHeaders 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
setContentLength(long)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.- Parameters:
contentLength- the message body length
-
setContentRange
public void setContentRange(long start, long end, long totalLength) Setshdrs'sContent-Range header according to the given values.(Note that
totalLengthis the total length of the entire resource that this is a range of, not simplyend-start+ 1.)Serverhas built-in handling for range requests, and you do not normally need to call this function youself. SeegetRanges(long, org.javagi.base.Out<org.gnome.soup.Range[]>)for more details.- Parameters:
start- the start of the rangeend- the end of the rangetotalLength- the total length of the resource, or -1 if unknown
-
setContentType
-
setEncoding
Sets the message body encoding that this MessageHeaders will declare.In particular, you should use this if you are going to send a request or response in chunked encoding.
- Parameters:
encoding- aSoupEncoding
-
setExpectations
Setshdrs's"Expect" header according toexpectations.Currently
Expectation.CONTINUEis 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.- Parameters:
expectations- the expectations to set
-
setExpectations
Setshdrs's"Expect" header according toexpectations.Currently
Expectation.CONTINUEis 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.- Parameters:
expectations- the expectations to set
-
setRange
public void setRange(long start, long end) Setshdrs'sRange header to request the indicated range.startandendare interpreted as in aRange.If you need to request multiple ranges, use
setRanges(org.gnome.soup.Range, int).- Parameters:
start- the start of the range to requestend- the end of the range to request
-
setRanges
Setshdrs'sRange header to request the indicated ranges.If you only want to request a single range, you can use
setRange(long, long).- Parameters:
ranges- an array ofSoupRangelength- the length ofrange
-
unref
public void unref()Atomically decrements the reference count of this MessageHeaders by one.When the reference count reaches zero, the resources allocated by this MessageHeaders are freed
-