net::http::*_header: rename to header_*
This commit is contained in:
parent
b297d9d3a0
commit
0eef917610
|
@ -26,7 +26,7 @@ export fn client_finish(client: *client) void = {
|
||||||
// Adds a default header which is included on all HTTP requests using a given
|
// Adds a default header which is included on all HTTP requests using a given
|
||||||
// [[client]].
|
// [[client]].
|
||||||
export fn client_add_header(client: *client, name: str, val: str) void = {
|
export fn client_add_header(client: *client, name: str, val: str) void = {
|
||||||
add_header(&client.default_header, name, val);
|
header_add(&client.default_header, name, val);
|
||||||
};
|
};
|
||||||
|
|
||||||
fn new_request(client: *client, method: str, target: *uri::uri) request = {
|
fn new_request(client: *client, method: str, target: *uri::uri) request = {
|
||||||
|
@ -63,7 +63,7 @@ fn new_request(client: *client, method: str, target: *uri::uri) request = {
|
||||||
host = strings::dup(host);
|
host = strings::dup(host);
|
||||||
};
|
};
|
||||||
defer free(host);
|
defer free(host);
|
||||||
add_header(&req.header, "Host", host);
|
header_add(&req.header, "Host", host);
|
||||||
|
|
||||||
return req;
|
return req;
|
||||||
};
|
};
|
||||||
|
@ -89,7 +89,7 @@ fn request_set_content_length(req: *request, body: io::handle) void = {
|
||||||
};
|
};
|
||||||
const ln = io::seek(body, 0, io::whence::END)!;
|
const ln = io::seek(body, 0, io::whence::END)!;
|
||||||
io::seek(body, prev, io::whence::SET)!;
|
io::seek(body, prev, io::whence::SET)!;
|
||||||
add_header(&req.header, "Content-Length", strconv::ztos(ln: size));
|
header_add(&req.header, "Content-Length", strconv::ztos(ln: size));
|
||||||
};
|
};
|
||||||
|
|
||||||
fn uri_origin_form(target: *uri::uri) uri::uri = {
|
fn uri_origin_form(target: *uri::uri) uri::uri = {
|
||||||
|
|
|
@ -6,25 +6,24 @@ use strings;
|
||||||
|
|
||||||
// List of HTTP headers.
|
// List of HTTP headers.
|
||||||
// TODO: [](str, []str)
|
// TODO: [](str, []str)
|
||||||
// s/add_header/header_add/ et al
|
|
||||||
export type header = [](str, str);
|
export type header = [](str, str);
|
||||||
|
|
||||||
// Adds a given HTTP header, which may be added more than once. The name should
|
// Adds a given HTTP header, which may be added more than once. The name should
|
||||||
// be canonicalized by the caller.
|
// be canonicalized by the caller.
|
||||||
export fn add_header(head: *header, name: str, val: str) void = {
|
export fn header_add(head: *header, name: str, val: str) void = {
|
||||||
append(head, (strings::dup(name), strings::dup(val)));
|
append(head, (strings::dup(name), strings::dup(val)));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sets the value of a given HTTP header, removing any previous values. The name
|
// Sets the value of a given HTTP header, removing any previous values. The name
|
||||||
// should be canonicalized by the caller.
|
// should be canonicalized by the caller.
|
||||||
export fn set_header(head: *header, name: str, val: str) void = {
|
export fn set_header(head: *header, name: str, val: str) void = {
|
||||||
del_header(head, name);
|
header_del(head, name);
|
||||||
add_header(head, name, val);
|
header_add(head, name, val);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Removes an HTTP header from a list of [[header]]. If multiple headers match
|
// Removes an HTTP header from a list of [[header]]. If multiple headers match
|
||||||
// the given name, all matching headers are removed.
|
// the given name, all matching headers are removed.
|
||||||
export fn del_header(head: *header, name: str) void = {
|
export fn header_del(head: *header, name: str) void = {
|
||||||
for (let i = 0z; i < len(head); i += 1) {
|
for (let i = 0z; i < len(head); i += 1) {
|
||||||
if (head[i].0 == name) {
|
if (head[i].0 == name) {
|
||||||
free(head[i].0);
|
free(head[i].0);
|
||||||
|
@ -49,7 +48,7 @@ export fn header_dup(head: *header) header = {
|
||||||
let new: header = [];
|
let new: header = [];
|
||||||
for (let i = 0z; i < len(head); i += 1) {
|
for (let i = 0z; i < len(head); i += 1) {
|
||||||
const (key, val) = head[i];
|
const (key, val) = head[i];
|
||||||
add_header(&new, key, val);
|
header_add(&new, key, val);
|
||||||
};
|
};
|
||||||
return new;
|
return new;
|
||||||
};
|
};
|
||||||
|
@ -84,6 +83,6 @@ fn read_header(head: *header, scan: *bufio::scanner) (void | io::error) = {
|
||||||
// TODO: validate field-name
|
// TODO: validate field-name
|
||||||
let (name, val) = strings::cut(item, ":");
|
let (name, val) = strings::cut(item, ":");
|
||||||
val = strings::trim(val);
|
val = strings::trim(val);
|
||||||
add_header(head, name, val);
|
header_add(head, name, val);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue