HEAD and OPTIONS are answered for every route by default (HEAD by the GET handler without the
body, OPTIONS with an Allow list); register them only to change that.
Adds a HEAD route. Register one only to change the default, which answers HEAD from the GET handler without sending the
body. The template, handler and max_body work as for get. A Content-Length header on the response is sent as is, with no
body, to tell the client how large a GET would be.
probe :: () -> Response {
return status_only(200);
}
main :: () {
app: App;
defer free_app(*app);
head(*app, "/file", probe);
api := test_client(*app);
response, _ := head(api, "/file");
defer close(*response);
assert(response.status == 200);
}Doesn't run in the browser (skipped on wasm).
head :: (
app: *App,
$template: string,
$handler: $H,
max_body := 0,
$loc := #caller_location
)
Parameters
- app: *App
- $template: string
- $handler: $H
- max_body := 0
- $loc := #caller_location
head :: (
group: *Group($P),
$template: string,
$handler: $H,
max_body := 0,
$loc := #caller_location
)
The head for a route under a group's prefix.
Parameters
- group: *Group($P)
- $template: string
- $handler: $H
- max_body := 0
- $loc := #caller_location
head :: (
client: *Client,
url: string,
headers: [] Header_Field = .[]
) -> (Client_Response, Client_Error)
HEAD: the headers a GET would get, and no body. The response is returned as get does.
Parameters
- client: *Client
- url: string
- headers: [] Header_Field = .[]
Returns
hello :: () -> string {
return "hello";
}
main :: () {
app: App;
defer free_app(*app);
get(*app, "/hello", hello);
api := test_client(*app);
response, _ := head(api, "/hello");
defer close(*response);
assert(response.status == 200);
}Doesn't run in the browser (skipped on wasm).