Shared networking types used across all HTTP libraries: Url (parsing and construction), Response (status code, headers, body), Cookie, and WebDownloader for streaming downloads. Compile with -lib net.
Url
URL parser, encoder and decoder
Operations
- New
- Compare
- Decode
- DecodePath
- Encode
- EncodePath
- GetFragment
- GetHost
- GetPath
- GetPort
- GetQuery
- GetQueryParameters
- GetScheme
- GetUrl
- HashID
- Parsed
- ToString
Compare #
Compares two objects
method : public : Compare(rhs:System.Compare) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| rhs | Compare | compare object |
Return
| Type | Description |
|---|---|
| Int | 0 if equal, -1 if right-hand side i greater, 1 if left-hand side is greater |
Decode # native
Decodes a percent-encoded URL component or form value. Each run of consecutive %XX escapes is collected as bytes and decoded as UTF-8, and '+' is read as a space (application/x-www-form-urlencoded). Characters that are not escapes, non-ASCII included, are kept as they are. Malformed input is not an error: a '%' not followed by two hex digits is kept literally, and bytes that are not valid UTF-8 (a stray continuation byte, an overlong form, a surrogate, a truncated sequence) each become U+FFFD, one per maximal invalid subsequence as in the WHATWG Encoding standard. Use DecodePath where '+' is a literal plus sign.
function : native : Decode(str:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| str | String | encoded string |
Return
| Type | Description |
|---|---|
| String | decoded string, or Nil if str is Nil |
Example
Web.HTTP.Url->Decode("hello%20world+%26%20foo%3Dbar")->PrintLine(); # hello world & foo=bar
Web.HTTP.Url->Decode("caf%C3%A9")->PrintLine(); # caféDecodePath # native
Decodes a percent-encoded URL path or URI: as Decode, except that '+' is kept as a plus sign rather than read as a space
function : native : DecodePath(str:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| str | String | encoded path |
Return
| Type | Description |
|---|---|
| String | decoded path, or Nil if str is Nil |
Example
Web.HTTP.Url->DecodePath("/c++/my%20file.txt")->PrintLine(); # /c++/my file.txtEncode # native
Percent-encodes a URL component, such as a query parameter name or value or a single path segment (RFC 3986). Every character outside the unreserved set (A-Z a-z 0-9 - . _ ~) is written as the %XX escapes of its UTF-8 bytes, with upper-case hex digits; that includes space (%20), '+' (%2B), '/' (%2F), '%' (%25), control characters and all non-ASCII text. An unpaired surrogate is encoded as U+FFFD. Use EncodePath to keep '/' separators in a path.
function : native : Encode(str:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| str | String | string to encode |
Return
| Type | Description |
|---|---|
| String | encoded string, or Nil if str is Nil |
Example
Web.HTTP.Url->Encode("hello world & foo=bar")->PrintLine(); # hello%20world%20%26%20foo%3Dbar
Web.HTTP.Url->Encode("café")->PrintLine(); # caf%C3%A9EncodePath # native
Percent-encodes a URL path: as Encode, except that '/' is kept so the path's segments stay separate
function : native : EncodePath(str:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| str | String | path to encode |
Return
| Type | Description |
|---|---|
| String | encoded path, or Nil if str is Nil |
Example
Web.HTTP.Url->EncodePath("/docs/my file.txt")->PrintLine(); # /docs/my%20file.txtGetFragment #
Gets fragment
method : public : GetFragment() ~ StringReturn
| Type | Description |
|---|---|
| String | fragment, Nil if not present |
GetHost #
Gets host
method : public : GetHost() ~ StringReturn
| Type | Description |
|---|---|
| String | host, Nil if not present |
GetPath #
Gets path
method : public : GetPath() ~ StringReturn
| Type | Description |
|---|---|
| String | path, Nil if not present |
GetQuery #
Gets scheme
method : public : GetQuery() ~ StringReturn
| Type | Description |
|---|---|
| String | scheme, Nil if not present |
GetQueryParameters #
Gets the name/value query parameters
method : public : GetQueryParameters() ~ Map<String,String>Return
| Type | Description |
|---|---|
| Map<String,String> | query parameters, Nil if URL cannot be parsed |
Example
url := Web.HTTP.Url->New("https://api.example.com/search?name=foo&lang=objeck");
params := url->GetQueryParameters();
params->Find("name")->PrintLine(); # foo
params->Find("lang")->PrintLine(); # objeckGetScheme #
Gets scheme
method : public : GetScheme() ~ StringReturn
| Type | Description |
|---|---|
| String | scheme, Nil if not present |
HashID #
Returns a hash ID for the given class
method : public : HashID() ~ IntReturn
| Type | Description |
|---|---|
| Int | hash ID |
New # constructor
Parsed URL into components
New(url:String)Parameters
| Name | Type | Description |
|---|---|---|
| url | String | raw URL |
Example
url := Web.HTTP.Url->New("https://example.com:8080/path?q=hello#section");
url->GetScheme()->PrintLine(); # https
url->GetHost()->PrintLine(); # example.com
url->GetPort()->PrintLine(); # 8080
url->GetPath()->PrintLine(); # /path
url->GetQuery()->PrintLine(); # q=hello
url->GetFragment()->PrintLine(); # sectionParsed #
Determines if given URL has been parsed correctly
method : public : Parsed() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if parsed, false otherwise |
ToString #
String representation of URL
method : public : ToString() ~ StringReturn
| Type | Description |
|---|---|
| String | string representation of URL |
Example
url := Web.HTTP.Url->New("https://example.com/path?q=hello");
url->ToString()->PrintLine();
# 'https://example.com/path?q=hello
# scheme='https'
# host='example.com'
# path='/path'
# query='q=hello'