-
Notifications
You must be signed in to change notification settings - Fork 288
browser: update urls after redirection #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -351,23 +351,7 @@ pub const Page = struct { | |
| return; | ||
| } | ||
|
|
||
| // own the url | ||
| self.rawuri = try arena.dupe(u8, uri); | ||
| self.uri = std.Uri.parse(self.rawuri.?) catch try std.Uri.parseAfterScheme("", self.rawuri.?); | ||
|
|
||
| self.url = try URL.constructor(arena, self.rawuri.?, null); | ||
| self.location.url = &self.url.?; | ||
| try self.session.window.replaceLocation(&self.location); | ||
|
|
||
| // prepare origin value. | ||
| var buf: std.ArrayListUnmanaged(u8) = .{}; | ||
| try self.uri.writeToStream(.{ | ||
| .scheme = true, | ||
| .authority = true, | ||
| }, buf.writer(arena)); | ||
| self.origin = buf.items; | ||
|
|
||
| // TODO handle fragment in url. | ||
| self.uri = std.Uri.parse(uri) catch try std.Uri.parseAfterScheme("", uri); | ||
|
|
||
| self.session.app.telemetry.record(.{ .navigate = .{ | ||
| .proxy = false, | ||
|
|
@@ -380,7 +364,37 @@ pub const Page = struct { | |
|
|
||
| var response = try request.sendSync(.{}); | ||
| const header = response.header; | ||
| try self.session.cookie_jar.populateFromResponse(self.uri, &header); | ||
| try self.session.cookie_jar.populateFromResponse(request.uri, &header); | ||
|
|
||
| // update uri after eventual redirection | ||
| var buf: std.ArrayListUnmanaged(u8) = .{}; | ||
| defer buf.deinit(arena); | ||
|
|
||
| buf.clearRetainingCapacity(); | ||
|
||
| try request.uri.writeToStream(.{ | ||
| .scheme = true, | ||
| .authentication = true, | ||
| .authority = true, | ||
| .path = true, | ||
| .query = true, | ||
| .fragment = true, | ||
| }, buf.writer(arena)); | ||
| self.rawuri = try buf.toOwnedSlice(arena); | ||
|
||
|
|
||
| self.uri = try std.Uri.parse(self.rawuri.?); | ||
|
|
||
| // TODO handle fragment in url. | ||
| self.url = try URL.constructor(arena, self.rawuri.?, null); | ||
| self.location.url = &self.url.?; | ||
| try self.session.window.replaceLocation(&self.location); | ||
|
|
||
| // prepare origin value. | ||
| buf.clearRetainingCapacity(); | ||
|
||
| try request.uri.writeToStream(.{ | ||
| .scheme = true, | ||
| .authority = true, | ||
| }, buf.writer(arena)); | ||
| self.origin = try buf.toOwnedSlice(arena); | ||
|
||
|
|
||
| log.info("GET {any} {d}", .{ self.uri, header.status }); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can treat the allocator like an
ArenaAllocatoror like anstd.mem.Allocator.If we treat it like an
Arena, we can remove unnecessary frees, which has a super-tiny performance cost.If we treat it like an
Allocator, we gain some flexibility with respect to changing the implementation.It isn't a system-wide decisions, there are places where we'll have an arena and want to treat it like a generic allocator, and there are places where we'll definitely want to take advantage of the arena's behavior. The reason I like to call these ArenaAllocators
arenais that it's clear to the writer & reader what the behavior is.TL;DR - The
deinitis almost certainly a no-op and could be removed. It's up to you.