Class Soup
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA constant corresponding to 1 day.static final intA constant corresponding to 1 hour.static final intA constant corresponding to 1 week.static final intA constant corresponding to 1 year.static final StringA macro containing the valuemultipart/form-data; the MIME type used for posting form data that contains files to be uploaded.static final StringA macro containing the valueapplication/x-www-form-urlencoded; the default MIME type for POSTing HTML form data.static final intAn expiration date that is always in the past.static final intThe set ofGUriFlagslibsoup expects allGUrito use.static final intLikegetMajorVersion(), but from the headers used at application compile time, rather than from the library linked against at application run time.static final intLikegetMicroVersion(), but from the headers used at application compile time, rather than from the library linked against at application run time.static final intLikegetMinorVersion(), but from the headers used at application compile time, rather than from the library linked against at application run time.static final intA macro that should be defined by the user prior to includinglibsoup.h. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckVersion(int major, int minor, int micro) Likeorg.gnome.soup.Soup#CHECKVERSION, but the check for soup_check_version is at runtime instead of compile time.static voidcookiesFree(SList<Cookie> cookies) Freescookies.Parsesmsg'sCookie request header and returns aGLib.SListofSoupCookies.Parsesmsg'sSet-Cookie response headers and returns aGLib.SListofSoupCookies.static StringcookiesToCookieHeader(SList<Cookie> cookies) Serializes aGLib.SListofSoupCookieinto a string suitable for setting as the value of the "Cookie" header.static voidcookiesToRequest(SList<Cookie> cookies, Message msg) Adds the name and value of each cookie incookiestomsg's"Cookie" request.static voidcookiesToResponse(SList<Cookie> cookies, Message msg) Appends a "Set-Cookie" response header tomsgfor each cookie incookies.static @Nullable DateTimedateTimeNewFromHttpString(String dateString) ParsesdateStringand tries to extract a date from it.static StringdateTimeToString(DateTime date, DateFormat format) Convertsdateto a string in the format described byformat.formDecode(String encodedForm) Decodesform.formDecodeMultipart(Multipart multipart, @Nullable String fileControlName, @Nullable Out<String> filename, @Nullable Out<String> contentType, @Nullable Out<byte[]> file) Decodes the "multipart/form-data" request inmultipart.static StringformEncode(String firstField, Object... varargs) Encodes the given field names and values into a value of type "application/x-www-form-urlencoded".static StringformEncodeDatalist(Data[] formDataSet) EncodesformDataSetinto a value of type "application/x-www-form-urlencoded".static StringformEncodeHash(HashTable<String, String> formDataSet) EncodesformDataSetinto a value of type "application/x-www-form-urlencoded".static intReturns the major version number of the libsoup library.static intReturns the micro version number of the libsoup library.static intReturns the minor version number of the libsoup library.static booleanheaderContains(String header, String token) Parsesheaderto see if it contains the tokentoken(matched case-insensitively).static voidheaderFreeList(SList<MemorySegment> list) Freeslist.static voidheaderFreeParamList(HashTable<String, String> paramList) FreesparamList.static voidheaderGStringAppendParam(String string, String name, @Nullable String value) Appends something likename=valuetostring,taking care to quotevalueif needed, and if so, to escape any quotes or backslashes invalue.static voidheaderGStringAppendParamQuoted(String string, String name, String value) Appends something likename="value"tostring,taking care to escape any quotes or backslashes invalue.headerParseList(String header) Parses a header whose content is described by RFC2616 as#something.headerParseParamList(String header) Parses a header which is a comma-delimited list of something like:token [ "=" ( token | quoted-string ) ].headerParseParamListStrict(String header) A strict version ofheaderParseParamList(java.lang.String)that bails out if there are duplicate parameters.headerParseQualityList(String header, @Nullable Out<SList<String>> unacceptable) Parses a header whose content is a list of items with optional "qvalue"s (eg, Accept, Accept-Charset, Accept-Encoding, Accept-Language, TE).headerParseSemiParamList(String header) Parses a header which is a semicolon-delimited list of something like:token [ "=" ( token | quoted-string ) ].headerParseSemiParamListStrict(String header) A strict version ofheaderParseSemiParamList(java.lang.String)that bails out if there are duplicate parameters.static booleanheadersParse(String str, int len, MessageHeaders dest) Parses the headers of an HTTP request or response instrand stores the results indest.static intheadersParseRequest(String str, int len, MessageHeaders reqHeaders, @Nullable Out<String> reqMethod, @Nullable Out<String> reqPath, @Nullable Out<HTTPVersion> ver) Parses the headers of an HTTP request instrand stores the results inreqMethod,reqPath,ver,andreqHeaders.static booleanheadersParseResponse(String str, int len, MessageHeaders headers, @Nullable Out<HTTPVersion> ver, @Nullable Out<Integer> statusCode, @Nullable Out<String> reasonPhrase) Parses the headers of an HTTP response instrand stores the results inver,statusCode,reasonPhrase,andheaders.static booleanheadersParseStatusLine(String statusLine, @Nullable Out<HTTPVersion> ver, @Nullable Out<Integer> statusCode, @Nullable Out<String> reasonPhrase) Parses the HTTP Status-Line string instatusLineintover,statusCode,andreasonPhrase.static voidstatic booleantldDomainIsPublicSuffix(String domain) Looks whether thedomainpassed as argument is a public domain suffix (.org, .com, .co.uk, etc) or not.static StringtldGetBaseDomain(String hostname) Finds the base domain for a givenhostnamestatic UriuriCopy(Uri uri, URIComponent firstComponent, Object... varargs) As of 3.4.0 this will detect the default ports of HTTP(s) and WS(S) URIs when copying and set it to the default port of the new scheme.static byte[]uriDecodeDataUri(String uri, @Nullable Out<String> contentType) Decodes the given data URI and returns its contents andcontentType.static booleanTests whether or noturi1anduri2are equal in all parts.static voidwebsocketClientPrepareHandshake(Message msg, @Nullable String origin, @Nullable String @Nullable [] protocols, @Nullable TypeClass @Nullable [] supportedExtensions) Adds the necessary headers tomsgto request a WebSocket handshake including supported WebSocket extensions.static booleanwebsocketClientVerifyHandshake(Message msg, @Nullable TypeClass @Nullable [] supportedExtensions, @Nullable Out<List<WebsocketExtension>> acceptedExtensions) Looks at the response status code and headers inmsgand determines if they contain a valid WebSocket handshake response (given the handshake request inmsg'srequest headers).static booleanwebsocketServerCheckHandshake(ServerMessage msg, @Nullable String origin, @Nullable String @Nullable [] protocols, @Nullable TypeClass @Nullable [] supportedExtensions) Examines the method and request headers inmsgand determines whethermsgcontains a valid handshake request.static booleanwebsocketServerProcessHandshake(ServerMessage msg, @Nullable String expectedOrigin, @Nullable String @Nullable [] protocols, @Nullable TypeClass @Nullable [] supportedExtensions, @Nullable Out<List<WebsocketExtension>> acceptedExtensions) Examines the method and request headers inmsgand (assumingmsgcontains a valid handshake request), fills in the handshake response.
-
Field Details
-
COOKIE_MAX_AGE_ONE_DAY
public static final int COOKIE_MAX_AGE_ONE_DAYA constant corresponding to 1 day.For use with
Cookie(java.lang.String, java.lang.String, java.lang.String, java.lang.String, int)andCookie.setMaxAge(int).- See Also:
-
COOKIE_MAX_AGE_ONE_HOUR
public static final int COOKIE_MAX_AGE_ONE_HOURA constant corresponding to 1 hour.For use with
Cookie(java.lang.String, java.lang.String, java.lang.String, java.lang.String, int)andCookie.setMaxAge(int).- See Also:
-
COOKIE_MAX_AGE_ONE_WEEK
public static final int COOKIE_MAX_AGE_ONE_WEEKA constant corresponding to 1 week.For use with
Cookie(java.lang.String, java.lang.String, java.lang.String, java.lang.String, int)andCookie.setMaxAge(int).- See Also:
-
COOKIE_MAX_AGE_ONE_YEAR
public static final int COOKIE_MAX_AGE_ONE_YEARA constant corresponding to 1 year.For use with
Cookie(java.lang.String, java.lang.String, java.lang.String, java.lang.String, int)andCookie.setMaxAge(int).- See Also:
-
FORM_MIME_TYPE_MULTIPART
A macro containing the valuemultipart/form-data; the MIME type used for posting form data that contains files to be uploaded.- See Also:
-
FORM_MIME_TYPE_URLENCODED
A macro containing the valueapplication/x-www-form-urlencoded; the default MIME type for POSTing HTML form data.- See Also:
-
HSTS_POLICY_MAX_AGE_PAST
public static final int HSTS_POLICY_MAX_AGE_PASTAn expiration date that is always in the past.- See Also:
-
HTTP_URI_FLAGS
public static final int HTTP_URI_FLAGSThe set ofGUriFlagslibsoup expects allGUrito use.- See Also:
-
MAJOR_VERSION
public static final int MAJOR_VERSIONLikegetMajorVersion(), but from the headers used at application compile time, rather than from the library linked against at application run time.- See Also:
-
MICRO_VERSION
public static final int MICRO_VERSIONLikegetMicroVersion(), but from the headers used at application compile time, rather than from the library linked against at application run time.- See Also:
-
MINOR_VERSION
public static final int MINOR_VERSIONLikegetMinorVersion(), but from the headers used at application compile time, rather than from the library linked against at application run time.- See Also:
-
VERSION_MIN_REQUIRED
public static final int VERSION_MIN_REQUIREDA macro that should be defined by the user prior to includinglibsoup.h.The definition should be one of the predefined libsoup version macros:
SOUP_VERSION_2_24,SOUP_VERSION_2_26, ...This macro defines the earliest version of libsoup that the package is required to be able to compile against.
If the compiler is configured to warn about the use of deprecated functions, then using functions that were deprecated in version
SOUP_VERSION_MIN_REQUIREDor earlier will cause warnings (but using functions deprecated in later releases will not).- See Also:
-
-
Constructor Details
-
Soup
public Soup()
-
-
Method Details
-
javagi$ensureInitialized
public static void javagi$ensureInitialized() -
checkVersion
public static boolean checkVersion(int major, int minor, int micro) Likeorg.gnome.soup.Soup#CHECKVERSION, 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.
- Parameters:
major- the major version to checkminor- the minor version to checkmicro- the micro version to check- Returns:
trueif the version of the libsoup currently loaded is the same as or newer than the passed-in version.
-
cookiesFree
-
cookiesFromRequest
Parsesmsg'sCookie request header and returns aGLib.SListofSoupCookies.As the "Cookie" header, unlike "Set-Cookie", only contains cookie names and values, none of the other
SoupCookiefields will be filled in. (Thus, you can't generally pass a cookie returned from this method directly tocookiesToResponse(org.gnome.glib.SList<org.gnome.soup.Cookie>, org.gnome.soup.Message).)- Parameters:
msg- aSoupMessagecontaining a "Cookie" request header- Returns:
- a
GSListofSoupCookies, which can be freed withCookie.free().
-
cookiesFromResponse
Parsesmsg'sSet-Cookie response headers and returns aGLib.SListofSoupCookies.Cookies that do not specify "path" or "domain" attributes will have their values defaulted from
msg.- Parameters:
msg- aSoupMessagecontaining a "Set-Cookie" response header- Returns:
- a
GSListofSoupCookies, which can be freed withCookie.free().
-
cookiesToCookieHeader
-
cookiesToRequest
Adds the name and value of each cookie incookiestomsg's"Cookie" request.If
msgalready 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.- Parameters:
cookies- aGSListofSoupCookiemsg- aSoupMessage
-
cookiesToResponse
-
dateTimeNewFromHttpString
ParsesdateStringand 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.)
- Parameters:
dateString- The date as a string- Returns:
- a new
GDateTime, ornullifdateStringcould not be parsed.
-
dateTimeToString
Convertsdateto a string in the format described byformat.- Parameters:
date- aGDateTimeformat- the format to generate the date in- Returns:
dateas a string ornull
-
formDecode
Decodesform.which is an urlencoded dataset as defined in the HTML 4.01 spec.
- Parameters:
encodedForm- data of type "application/x-www-form-urlencoded"- Returns:
- a hash
table containing the name/value pairs from
encodedForm,which you can free withHashTable.destroy().
-
formDecodeMultipart
public static @Nullable HashTable<String,String> formDecodeMultipart(Multipart multipart, @Nullable String fileControlName, @Nullable Out<String> filename, @Nullable Out<String> contentType, @Nullable Out<byte[]> file) Decodes the "multipart/form-data" request inmultipart.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
fileControlName,andformDecodeMultipart(org.gnome.soup.Multipart, java.lang.String, org.javagi.base.Out<java.lang.String>, org.javagi.base.Out<java.lang.String>, org.javagi.base.Out<byte[]>)will extract the uploaded file data intofilename,contentType,andfile.All of the other form control data will be returned (as strings, as withformDecode(java.lang.String)in the returnedGLib.HashTable.You may pass
nullforfilename,contentTypeand/orfileif you do not care about those fields.formDecodeMultipart(org.gnome.soup.Multipart, java.lang.String, org.javagi.base.Out<java.lang.String>, org.javagi.base.Out<java.lang.String>, org.javagi.base.Out<byte[]>)may also returnnullin those fields if the client did not provide that information. You must free the returned filename and content-type withGLib.free(java.lang.foreign.MemorySegment), and the returned file data withorg.gnome.glib.Bytes#unref.If you have a form with more than one file upload control, you will need to decode it manually, using
Multipart.fromMessage(org.gnome.soup.MessageHeaders, byte[])andMultipart.getPart(int, org.javagi.base.Out<org.gnome.soup.MessageHeaders>, org.javagi.base.Out<byte[]>).- Parameters:
multipart- aSoupMultipartfileControlName- the name of the HTML file upload controlfilename- return location for the name of the uploaded filecontentType- return location for the MIME type of the uploaded filefile- return location for the uploaded file data- Returns:
- a hash table containing the name/value pairs (other than
fileControlName)frommsg,which you can free withHashTable.destroy(). On error, it will returnnull.
-
formEncode
Encodes the given field names and values into a value of type "application/x-www-form-urlencoded".Encodes as defined in the HTML 4.01 spec.
This method requires you to know the names of the form fields (or at the very least, the total number of fields) at compile time; for working with dynamic forms, use
formEncodeHash(org.gnome.glib.HashTable<java.lang.String, java.lang.String>)orformEncodeDatalist(org.gnome.glib.Data[]).See also:
Message.fromEncodedForm(java.lang.String, java.lang.String, java.lang.String).- Parameters:
firstField- name of the first form fieldvarargs- value offirstField,followed by additional field names and values, terminated bynull.- Returns:
- the encoded form
-
formEncodeDatalist
EncodesformDataSetinto a value of type "application/x-www-form-urlencoded".Encodes as defined in the HTML 4.01 spec. Unlike
formEncodeHash(org.gnome.glib.HashTable<java.lang.String, java.lang.String>), this preserves the ordering of the form elements, which may be required in some situations.See also:
Message.fromEncodedForm(java.lang.String, java.lang.String, java.lang.String).- Parameters:
formDataSet- a datalist containing name/value pairs- Returns:
- the encoded form
-
formEncodeHash
EncodesformDataSetinto 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
formEncodeDatalist(org.gnome.glib.Data[]).See also:
Message.fromEncodedForm(java.lang.String, java.lang.String, java.lang.String).- Parameters:
formDataSet- a hash table containing name/value pairs (as strings)- Returns:
- the encoded form
-
getMajorVersion
public static int getMajorVersion()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_VERSIONmacro, which represents the major version of the libsoup headers you have included when compiling your code.- Returns:
- the major version number of the libsoup library
-
getMicroVersion
public static int getMicroVersion()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_VERSIONmacro, which represents the micro version of the libsoup headers you have included when compiling your code.- Returns:
- the micro version number of the libsoup library
-
getMinorVersion
public static int getMinorVersion()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_VERSIONmacro, which represents the minor version of the libsoup headers you have included when compiling your code.- Returns:
- the minor version number of the libsoup library
-
headerContains
Parsesheaderto see if it contains the tokentoken(matched case-insensitively).Note that this can't be used with lists that have qvalues.
- Parameters:
header- An HTTP header suitable for parsing withheaderParseList(java.lang.String)token- a token- Returns:
- whether or not
headercontainstoken
-
headerFreeList
Freeslist.- Parameters:
list- aGSListreturned fromheaderParseList(java.lang.String)orheaderParseQualityList(java.lang.String, org.javagi.base.Out<org.gnome.glib.SList<java.lang.String>>)
-
headerFreeParamList
FreesparamList.- Parameters:
paramList- aGHashTablereturned fromheaderParseParamList(java.lang.String)orheaderParseSemiParamList(java.lang.String)
-
headerGStringAppendParam
Appends something likename=valuetostring,taking care to quotevalueif needed, and if so, to escape any quotes or backslashes invalue.Alternatively, if
valueis 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
valueisnull, this will just appendnametostring.- Parameters:
string- aGStringbeing used to construct an HTTP header valuename- a parameter namevalue- a parameter value, ornull
-
headerGStringAppendParamQuoted
Appends something likename="value"tostring,taking care to escape any quotes or backslashes invalue.If
valueis (non-ASCII) UTF-8, this will instead use RFC 5987 encoding, just likeheaderGStringAppendParam(java.lang.String, java.lang.String, java.lang.String).- Parameters:
string- aGStringbeing used to construct an HTTP header valuename- a parameter namevalue- a parameter value
-
headerParseList
-
headerParseParamList
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
nullvalue.This also handles RFC5987 encoding (which in HTTP is mostly used for giving UTF8-encoded filenames in the Content-Disposition header).
- Parameters:
header- a header value- Returns:
- a
GHashTableof list elements, which can be freed withheaderFreeParamList(org.gnome.glib.HashTable<java.lang.String, java.lang.String>).
-
headerParseParamListStrict
A strict version ofheaderParseParamList(java.lang.String)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
headerParseParamList(java.lang.String)instead.- Parameters:
header- a header value- Returns:
- a
GHashTableof list elements, which can be freed withheaderFreeParamList(org.gnome.glib.HashTable<java.lang.String, java.lang.String>)ornullif there are duplicate elements.
-
headerParseQualityList
public static SList<String> headerParseQualityList(String header, @Nullable Out<SList<String>> 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
unacceptableis notnull, then on return, it will contain the items with qvalue 0. Either way, those items will be removed from the main list.- Parameters:
header- a header valueunacceptable- on return, will contain a list of unacceptable values- Returns:
- a
GSListof acceptable values (as allocated strings), highest-qvalue first.
-
headerParseSemiParamList
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
nullvalue.This also handles RFC5987 encoding (which in HTTP is mostly used for giving UTF8-encoded filenames in the Content-Disposition header).
- Parameters:
header- a header value- Returns:
- a
GHashTableof list elements, which can be freed withheaderFreeParamList(org.gnome.glib.HashTable<java.lang.String, java.lang.String>).
-
headerParseSemiParamListStrict
A strict version ofheaderParseSemiParamList(java.lang.String)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
headerParseSemiParamList(java.lang.String)instead.- Parameters:
header- a header value- Returns:
- a
GHashTableof list elements, which can be freed withheaderFreeParamList(org.gnome.glib.HashTable<java.lang.String, java.lang.String>)ornullif there are duplicate elements.
-
headersParse
Parses the headers of an HTTP request or response instrand stores the results indest.Beware that
destmay be modified even on failure.This is a low-level method; normally you would use
headersParseRequest(java.lang.String, int, org.gnome.soup.MessageHeaders, org.javagi.base.Out<java.lang.String>, org.javagi.base.Out<java.lang.String>, org.javagi.base.Out<org.gnome.soup.HTTPVersion>)orheadersParseResponse(java.lang.String, int, org.gnome.soup.MessageHeaders, org.javagi.base.Out<org.gnome.soup.HTTPVersion>, org.javagi.base.Out<java.lang.Integer>, org.javagi.base.Out<java.lang.String>).- Parameters:
str- the header string (including the Request-Line or Status-Line, but not the trailing blank line)len- length ofstrdest-SoupMessageHeadersto store the header values in- Returns:
- success or failure
-
headersParseRequest
public static int headersParseRequest(String str, int len, MessageHeaders reqHeaders, @Nullable Out<String> reqMethod, @Nullable Out<String> reqPath, @Nullable Out<HTTPVersion> ver) Parses the headers of an HTTP request instrand stores the results inreqMethod,reqPath,ver,andreqHeaders.Beware that
reqHeadersmay be modified even on failure.- Parameters:
str- the headers (up to, but not including, the trailing blank line)len- length ofstrreqHeaders-SoupMessageHeadersto store the header values inreqMethod- if non-null, will be filled in with the request methodreqPath- if non-null, will be filled in with the request pathver- if non-null, will be filled in with the HTTP version- Returns:
Status.OKif the headers could be parsed, or an HTTP error to be returned to the client if they could not be.
-
headersParseResponse
public static boolean headersParseResponse(String str, int len, MessageHeaders headers, @Nullable Out<HTTPVersion> ver, @Nullable Out<Integer> statusCode, @Nullable Out<String> reasonPhrase) Parses the headers of an HTTP response instrand stores the results inver,statusCode,reasonPhrase,andheaders.Beware that
headersmay be modified even on failure.- Parameters:
str- the headers (up to, but not including, the trailing blank line)len- length ofstrheaders-SoupMessageHeadersto store the header values inver- if non-null, will be filled in with the HTTP versionstatusCode- if non-null, will be filled in with the status codereasonPhrase- if non-null, will be filled in with the reason phrase- Returns:
- success or failure.
-
headersParseStatusLine
public static boolean headersParseStatusLine(String statusLine, @Nullable Out<HTTPVersion> ver, @Nullable Out<Integer> statusCode, @Nullable Out<String> reasonPhrase) Parses the HTTP Status-Line string instatusLineintover,statusCode,andreasonPhrase.statusLinemust be terminated by either "\\0" or "\\r\\n".- Parameters:
statusLine- an HTTP Status-Linever- if non-null, will be filled in with the HTTP versionstatusCode- if non-null, will be filled in with the status codereasonPhrase- if non-null, will be filled in with the reason phrase- Returns:
trueifstatusLinewas parsed successfully.
-
tldDomainIsPublicSuffix
Looks whether thedomainpassed as argument is a public domain suffix (.org, .com, .co.uk, etc) or not.Prior to libsoup 2.46, this function required that
domainbe in UTF-8 if it was an IDN. From 2.46 on, the name can be in either UTF-8 or ASCII format.- Parameters:
domain- a domain name- Returns:
trueif it is a public domain,falseotherwise.
-
tldGetBaseDomain
Finds the base domain for a givenhostnameThe 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
nullwill 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
hostnamebe 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).- Parameters:
hostname- a hostname- Returns:
- a pointer to the start of the base domain in
hostname.If an error occurs,nullwill be returned anderrorset. - Throws:
GErrorException- seeGError
-
uriCopy
As of 3.4.0 this will detect the default ports of HTTP(s) and WS(S) URIs when copying and set it to the default port of the new scheme. So for example copyinghttp://localhost:80while changing the scheme to https will result inhttps://localhost:443.Return a copy of
uriwith the given components updated.- Parameters:
uri- theGUrito copyfirstComponent- firstSoupURIComponentto updatevarargs- value offirstComponentfollowed by additional components and values, terminated byURIComponent.NONE- Returns:
- a new
GUri
-
uriDecodeDataUri
Decodes the given data URI and returns its contents andcontentType.- Parameters:
uri- a data URI, in string formcontentType- location to store content type- Returns:
- a
GByteswith the contents ofuri,ornullifuriis not a valid data URI
-
uriEqual
-
websocketClientPrepareHandshake
public static void websocketClientPrepareHandshake(Message msg, @Nullable String origin, @Nullable String @Nullable [] protocols, @Nullable TypeClass @Nullable [] supportedExtensions) Adds the necessary headers tomsgto request a WebSocket handshake including supported WebSocket extensions.The message body and non-WebSocket-related headers are not modified.
This is a low-level function; if you use
Session.websocketConnectAsync(org.gnome.soup.Message, java.lang.String, java.lang.String[], int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)to create a WebSocket connection, it will call this for you.- Parameters:
msg- aSoupMessageorigin- the "Origin" header to setprotocols- list of protocols to offersupportedExtensions- list of supported extension types
-
websocketClientVerifyHandshake
public static boolean websocketClientVerifyHandshake(Message msg, @Nullable TypeClass @Nullable [] supportedExtensions, @Nullable Out<List<WebsocketExtension>> acceptedExtensions) throws GErrorException Looks at the response status code and headers inmsgand determines if they contain a valid WebSocket handshake response (given the handshake request inmsg'srequest headers).If
supportedExtensionsis non-null, extensions included in the response "Sec-WebSocket-Extensions" are verified too. Accepted extensions are returned inacceptedExtensionsparameter if non-null.This is a low-level function; if you use
Session.websocketConnectAsync(org.gnome.soup.Message, java.lang.String, java.lang.String[], int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)to create a WebSocket connection, it will call this for you.- Parameters:
msg-SoupMessagecontaining both client and server sides of a WebSocket handshakesupportedExtensions- list of supported extension typesacceptedExtensions- aGListofSoupWebsocketExtensionobjects- Returns:
trueifmsgcontains a completed valid WebSocket handshake,falseand an error if not.- Throws:
GErrorException- seeGError
-
websocketServerCheckHandshake
public static boolean websocketServerCheckHandshake(ServerMessage msg, @Nullable String origin, @Nullable String @Nullable [] protocols, @Nullable TypeClass @Nullable [] supportedExtensions) throws GErrorException Examines the method and request headers inmsgand determines whethermsgcontains a valid handshake request.If
originis non-null, then only requests containing a matching "Origin" header will be accepted. Ifprotocolsis non-null, then only requests containing a compatible "Sec-WebSocket-Protocols" header will be accepted. IfsupportedExtensionsis non-null, then only requests containing valid supported extensions in "Sec-WebSocket-Extensions" header will be accepted.Normally
websocketServerProcessHandshake(org.gnome.soup.ServerMessage, java.lang.String, java.lang.String[], org.gnome.gobject.TypeClass[], org.javagi.base.Out<org.gnome.glib.List<org.gnome.soup.WebsocketExtension>>)will take care of this for you, and if you useServer.addWebsocketHandler(java.lang.String, java.lang.String, java.lang.String[], org.gnome.soup.ServerWebsocketCallback)to handle accepting WebSocket connections, it will call that for you. However, this function may be useful if you need to perform more complicated validation; eg, accepting multiple different Origins, or handling different protocols depending on the path.- Parameters:
msg-SoupServerMessagecontaining the client side of a WebSocket handshakeorigin- expected Origin headerprotocols- allowed WebSocket protocols.supportedExtensions- list of supported extension types- Returns:
trueifmsgcontained a valid WebSocket handshake,falseand an error if not.- Throws:
GErrorException- seeGError
-
websocketServerProcessHandshake
public static boolean websocketServerProcessHandshake(ServerMessage msg, @Nullable String expectedOrigin, @Nullable String @Nullable [] protocols, @Nullable TypeClass @Nullable [] supportedExtensions, @Nullable Out<List<WebsocketExtension>> acceptedExtensions) Examines the method and request headers inmsgand (assumingmsgcontains a valid handshake request), fills in the handshake response.If
expectedOriginis non-null, then only requests containing a matching "Origin" header will be accepted. Ifprotocolsis non-null, then only requests containing a compatible "Sec-WebSocket-Protocols" header will be accepted. IfsupportedExtensionsis non-null, then only requests containing valid supported extensions in "Sec-WebSocket-Extensions" header will be accepted. The accepted extensions will be returned inacceptedExtensionsparameter if non-null.This is a low-level function; if you use
Server.addWebsocketHandler(java.lang.String, java.lang.String, java.lang.String[], org.gnome.soup.ServerWebsocketCallback)to handle accepting WebSocket connections, it will call this for you.- Parameters:
msg-SoupServerMessagecontaining the client side of a WebSocket handshakeexpectedOrigin- expected Origin headerprotocols- allowed WebSocket protocols.supportedExtensions- list of supported extension typesacceptedExtensions- aGListofSoupWebsocketExtensionobjects- Returns:
trueifmsgcontained a valid WebSocket handshake request and was updated to contain a handshake response.falseif not.
-