Usage
The HTTP Signature is implemented differently between the Guest and Host languages. The Host language has direct access to the HTTP Request and Response objects, while the Guest language has accessor methods to read and modify the request and response. This allows the Host language complete control over the HTTP request and response, while the Guest language has stricter restrictions on what can be modified and how it can be modified.Request
The HTTP Request object contains the following fields:
It can be accessed using the
Request(): Request method. The following are methods that can be used on the returned object.
URI
Theuri field is a string that contains the URI of the request. It can be accessed using the URI(): string method and
modified using the SetURI(uri: string) method.
Method
Themethod field is an enum that contains the HTTP method of the request. It can be accessed using the Method(): method
method and modified using the SetMethod(method: method) method.
Valid values for the method field are:
GETPOSTPUTPATCHDELETEHEADOPTIONS
Content Length
Thecontent_length field is a uint64 that contains the length of the request body. It can be accessed using the
ContentLength(): uint64 method and modified using the SetContentLength(length: uint64) method.
Protocol
Theprotocol field is an enum that contains the HTTP protocol of the request. It can be accessed using the
Protocol(): protocol method and modified using the SetProtocol(protocol: protocol) method.
Valid values for the protocol field are:
HTTP/1.1HTTP/2HTTP/3
IP
Theip field is a string that contains the IP address of the request. It can be accessed using the IP(): string method
and modified using the SetIP(ip: string) method.
Body
Thebody field is a bytes that contains the request body. It can be accessed using the Body(): []bytes method and modified
using the SetBody(body: []bytes) method.
If you’d like to set the body to a string, you can use the SetBodyString(body: string) method.
Headers
Theheaders field is a string_map that contains the request headers. It can be accessed using the Header() method.
Writing a key to the headers returned by the Header(): header method can be done using the Set(key: string, value: []string) method. Reading a key from
the headers returned by the Header(): header method can be done using the Get(key: string): []string method.
Response
The HTTP Response object contains the following fields:| Field | Type | Description |
|---|---|---|
| status_code | uint32 | The status code of the response. |
| body | bytes | The response body. |
| headers | string_map | The response headers. |
Response(): Response method. The following are methods that can be used on the returned object.
Status Code
Thestatus_code field is a uint32 that contains the status code of the response. It can be accessed using the
StatusCode(): uint32 method and modified using the SetStatusCode(status_code: uint32) method.
Body
Thebody field is a bytes that contains the response body. It can be accessed using the Body(): []bytes method and modified
using the SetBody(body: []bytes) method.
If you’d like to set the body to a string, you can use the SetBodyString(body: string) method.
Headers
Theheaders field is a string_map that contains the response headers. It can be accessed using the Header() method.
Writing a key to the headers returned by the Header(): header method can be done using the Set(key: string, value: []string) method. Reading a key from
the headers returned by the Header(): header method can be done using the Get(key: string): []string method.
Definition
The HTTP Signature is defined as follows using the Scale Signature syntax:http.signature