Gjsify LogoGjsify Logo

A #SoupURI represents a (parsed) URI. #SoupURI supports RFC 3986 (URI Generic Syntax), and can parse any valid URI. However, libsoup only uses "http" and "https" URIs internally; You can use SOUP_URI_VALID_FOR_HTTP() to test if a #SoupURI is a valid HTTP URI.

scheme will always be set in any URI. It is an interned string and is always all lowercase. (If you parse a URI with a non-lowercase scheme, it will be converted to lowercase.) The macros %SOUP_URI_SCHEME_HTTP and %SOUP_URI_SCHEME_HTTPS provide the interned values for "http" and "https" and can be compared against URI scheme values.

user and password are parsed as defined in the older URI specs (ie, separated by a colon; RFC 3986 only talks about a single "userinfo" field). Note that password is not included in the output of soup_uri_to_string(). libsoup does not normally use these fields; authentication is handled via #SoupSession signals.

host contains the hostname, and port the port specified in the URI. If the URI doesn't contain a hostname, host will be %NULL, and if it doesn't specify a port, port may be 0. However, for "http" and "https" URIs, host is guaranteed to be non-%NULL (trying to parse an http URI with no host will return %NULL), and port will always be non-0 (because libsoup knows the default value to use when it is not specified in the URI).

path is always non-%NULL. For http/https URIs, path will never be an empty string either; if the input URI has no path, the parsed #SoupURI will have a path of "/".

query and fragment are optional for all URI types. soup_form_decode() may be useful for parsing query.

Note that path, query, and fragment may contain %-encoded characters. soup_uri_new() calls soup_uri_normalize() on them, but not soup_uri_decode(). This is necessary to ensure that soup_uri_to_string() will generate a URI that has exactly the same meaning as the original. (In theory, #SoupURI should leave user, password, and host partially-encoded as well, but this would be more annoying than useful.)

record

Hierarchy

  • URI

Index

Constructors

  • new URI(uri_string: string): Soup.URI
  • Parses an absolute URI.

    You can also pass %NULL for uri_string if you want to get back an "empty" #SoupURI that you can fill in by hand. (You will need to call at least soup_uri_set_scheme() and soup_uri_set_path(), since those fields are required.)

    Parameters

    • uri_string: string

      a URI

    Returns Soup.URI

Properties

fragment: string

a fragment identifier within path, or %NULL

field
host: string

the hostname or IP address, or %NULL

field
password: string

a password, or %NULL

field
path: string

the path on host

field
port: number

the port number on host

field
query: string

a query for path, or %NULL

field
scheme: string

the URI scheme (eg, "http")

field
user: string

a username, or %NULL

field
name: string

Methods

  • free(): void
  • get_fragment(): string
  • get_host(): string
  • get_password(): string
  • get_path(): string
  • get_port(): number
  • get_query(): string
  • get_scheme(): string
  • get_user(): string
  • Compares v1 and v2, considering only the scheme, host, and port.

    Parameters

    • v2: Soup.URI

      a #SoupURI with a non-%NULL host member

    Returns boolean

  • host_hash(): number
  • set_fragment(fragment: string): void
  • set_host(host: string): void
  • Sets uri's host to host.

    If host is an IPv6 IP address, it should not include the brackets required by the URI syntax; they will be added automatically when converting uri to a string.

    http and https URIs should not have a %NULL host.

    Parameters

    • host: string

      the hostname or IP address, or %NULL

    Returns void

  • set_password(password: string): void
  • set_path(path: string): void
  • set_port(port: number): void
  • Sets uri's port to port. If port is 0, uri will not have an explicitly-specified port.

    Parameters

    • port: number

      the port, or 0

    Returns void

  • set_query(query: string): void
  • set_query_from_form(form: HashTable<string | number | symbol, string | number | boolean>): void
  • Sets uri's query to the result of encoding form according to the HTML form rules. See soup_form_encode_hash() for more information.

    Parameters

    • form: HashTable<string | number | symbol, string | number | boolean>

      a #GHashTable containing HTML form information

    Returns void

  • set_scheme(scheme: string): void
  • Sets uri's scheme to scheme. This will also set uri's port to the default port for scheme, if known.

    Parameters

    • scheme: string

      the URI scheme

    Returns void

  • set_user(user: string): void
  • to_string(just_path_and_query: boolean): string
  • Returns a string representing uri.

    If just_path_and_query is %TRUE, this concatenates the path and query together. That is, it constructs the string that would be needed in the Request-Line of an HTTP request for uri.

    Note that the output will never contain a password, even if uri does.

    Parameters

    • just_path_and_query: boolean

      if %TRUE, output just the path and query portions

    Returns string

  • uses_default_port(): boolean
  • Tests if uri uses the default port for its scheme. (Eg, 80 for http.) (This only works for http, https and ftp; libsoup does not know the default ports of other protocols.)

    Returns boolean

  • decode(part: string): string
  • Fully %-decodes part.

    In the past, this would return %NULL if part contained invalid percent-encoding, but now it just ignores the problem (as soup_uri_new() already did).

    Parameters

    • part: string

      a URI part

    Returns string

  • encode(part: string, escape_extra: string): string
  • This %-encodes the given URI part and returns the escaped version in allocated memory, which the caller must free when it is done.

    Parameters

    • part: string

      a URI part

    • escape_extra: string

      additional reserved characters to escape (or %NULL)

    Returns string

  • Parses an absolute URI.

    You can also pass %NULL for uri_string if you want to get back an "empty" #SoupURI that you can fill in by hand. (You will need to call at least soup_uri_set_scheme() and soup_uri_set_path(), since those fields are required.)

    Parameters

    • uri_string: string

      a URI

    Returns Soup.URI

  • normalize(part: string, unescape_extra: string): string
  • %-decodes any "unreserved" characters (or characters in unescape_extra) in part, and %-encodes any non-ASCII characters, spaces, and non-printing characters in part.

    "Unreserved" characters are those that are not allowed to be used for punctuation according to the URI spec. For example, letters are unreserved, so soup_uri_normalize() will turn http://example.com/foo/b%61r into http://example.com/foo/bar, which is guaranteed to mean the same thing. However, "/" is "reserved", so http://example.com/foo%2Fbar would not be changed, because it might mean something different to the server.

    In the past, this would return %NULL if part contained invalid percent-encoding, but now it just ignores the problem (as soup_uri_new() already did).

    Parameters

    • part: string

      a URI part

    • unescape_extra: string

      reserved characters to unescape (or %NULL)

    Returns string

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method