mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
cleanup optional request headers
This commit is contained in:
@@ -472,6 +472,7 @@ pub const Page = struct {
|
||||
.url = owned_url,
|
||||
.method = opts.method,
|
||||
.body = opts.body,
|
||||
.header = opts.header,
|
||||
.cookie = self.requestCookie(.{ .is_navigation = true }),
|
||||
.header_done_callback = pageHeaderDoneCallback,
|
||||
.data_callback = pageDataCallback,
|
||||
@@ -931,6 +932,8 @@ pub const Page = struct {
|
||||
if (std.ascii.eqlIgnoreCase(method, "post")) {
|
||||
opts.method = .POST;
|
||||
opts.body = buf.items;
|
||||
// form_data.write currently only supports this encoding, so we know this has to be the content type
|
||||
opts.header = "Content-Type: application/x-www-form-urlencoded";
|
||||
} else {
|
||||
action = try URL.concatQueryString(transfer_arena, action, buf.items);
|
||||
}
|
||||
@@ -986,6 +989,7 @@ pub const NavigateOpts = struct {
|
||||
reason: NavigateReason = .address_bar,
|
||||
method: HttpClient.Method = .GET,
|
||||
body: ?[]const u8 = null,
|
||||
header: ?[:0]const u8 = null,
|
||||
};
|
||||
|
||||
fn timestamp() u32 {
|
||||
|
||||
@@ -12,6 +12,7 @@ pub const LookupOpts = struct {
|
||||
origin_uri: ?*const Uri = null,
|
||||
is_http: bool,
|
||||
is_navigation: bool = true,
|
||||
prefix: ?[]const u8 = null,
|
||||
};
|
||||
|
||||
pub const Jar = struct {
|
||||
@@ -91,10 +92,15 @@ pub const Jar = struct {
|
||||
|
||||
var first = true;
|
||||
for (self.cookies.items) |*cookie| {
|
||||
if (!cookie.appliesTo(&target, same_site, opts.is_navigation, opts.is_http)) continue;
|
||||
if (!cookie.appliesTo(&target, same_site, opts.is_navigation, opts.is_http)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// we have a match!
|
||||
if (first) {
|
||||
if (opts.prefix) |prefix| {
|
||||
try writer.writeAll(prefix);
|
||||
}
|
||||
first = false;
|
||||
} else {
|
||||
try writer.writeAll("; ");
|
||||
|
||||
@@ -375,7 +375,6 @@ pub const XMLHttpRequest = struct {
|
||||
.url = self.url.?,
|
||||
.method = self.method,
|
||||
.body = self.request_body,
|
||||
.content_type = "Content-Type: text/plain; charset=UTF-8", // @newhttp TODO
|
||||
.cookie = page.requestCookie(.{}),
|
||||
.start_callback = httpStartCallback,
|
||||
.header_callback = httpHeaderCallback,
|
||||
|
||||
@@ -263,24 +263,21 @@ fn makeRequest(self: *Client, handle: *Handle, req: Request) !void {
|
||||
var header_list = conn.commonHeaders();
|
||||
errdefer c.curl_slist_free_all(header_list);
|
||||
|
||||
if (req.content_type) |ct| {
|
||||
header_list = c.curl_slist_append(header_list, ct);
|
||||
if (req.header) |hdr| {
|
||||
header_list = c.curl_slist_append(header_list, hdr);
|
||||
}
|
||||
|
||||
{
|
||||
const COOKIE_HEADER = "Cookie: ";
|
||||
const aa = self.arena.allocator();
|
||||
defer _ = self.arena.reset(.{ .retain_with_limit = 2048 });
|
||||
|
||||
var arr: std.ArrayListUnmanaged(u8) = .{};
|
||||
try arr.appendSlice(aa, COOKIE_HEADER);
|
||||
try req.cookie.forRequest(&uri, arr.writer(aa));
|
||||
|
||||
if (arr.items.len > COOKIE_HEADER.len) {
|
||||
if (arr.items.len > 0) {
|
||||
try arr.append(aa, 0); //null terminate
|
||||
|
||||
// copies the value
|
||||
header_list = c.curl_slist_append(header_list, @ptrCast(arr.items.ptr));
|
||||
defer _ = self.arena.reset(.{ .retain_with_limit = 2048 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,6 +482,7 @@ pub const RequestCookie = struct {
|
||||
.is_http = self.is_http,
|
||||
.is_navigation = self.is_navigation,
|
||||
.origin_uri = self.origin,
|
||||
.prefix = "Cookie: ",
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -493,7 +491,7 @@ pub const Request = struct {
|
||||
method: Method,
|
||||
url: [:0]const u8,
|
||||
body: ?[]const u8 = null,
|
||||
content_type: ?[:0]const u8 = null,
|
||||
header: ?[:0]const u8 = null,
|
||||
cookie: RequestCookie,
|
||||
|
||||
// arbitrary data that can be associated with this request
|
||||
|
||||
Reference in New Issue
Block a user