aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/webcore/request.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/webcore/request.zig')
-rw-r--r--src/bun.js/webcore/request.zig60
1 files changed, 34 insertions, 26 deletions
diff --git a/src/bun.js/webcore/request.zig b/src/bun.js/webcore/request.zig
index 7457b941f..ff6816351 100644
--- a/src/bun.js/webcore/request.zig
+++ b/src/bun.js/webcore/request.zig
@@ -268,12 +268,17 @@ pub const Request = struct {
return this.url.len;
if (this.uws_request) |req| {
- const fmt = ZigURL.HostFormatter{
- .is_https = this.https,
- .host = req.header("host") orelse "",
- };
-
- return this.getProtocol().len + req.url().len + std.fmt.count("{any}", .{fmt});
+ const req_url = req.url();
+ if (req_url.len > 0 and req_url[0] == '/') {
+ if (req.header("host")) |host| {
+ const fmt = ZigURL.HostFormatter{
+ .is_https = this.https,
+ .host = host,
+ };
+ return this.getProtocol().len + req_url.len + std.fmt.count("{any}", .{fmt});
+ }
+ }
+ return req_url.len;
}
return 0;
@@ -291,28 +296,31 @@ pub const Request = struct {
if (this.uws_request) |req| {
const req_url = req.url();
- if (req.header("host")) |host| {
- const fmt = ZigURL.HostFormatter{
- .is_https = this.https,
- .host = host,
- };
- const url = try std.fmt.allocPrint(bun.default_allocator, "{s}{any}{s}", .{
- this.getProtocol(),
- fmt,
- req_url,
- });
- if (comptime Environment.allow_assert) {
- std.debug.assert(this.sizeOfURL() == url.len);
- }
- this.url = url;
- this.url_was_allocated = true;
- } else {
- if (comptime Environment.allow_assert) {
- std.debug.assert(this.sizeOfURL() == req_url.len);
+ if (req_url.len > 0 and req_url[0] == '/') {
+ if (req.header("host")) |host| {
+ const fmt = ZigURL.HostFormatter{
+ .is_https = this.https,
+ .host = host,
+ };
+ const url = try std.fmt.allocPrint(bun.default_allocator, "{s}{any}{s}", .{
+ this.getProtocol(),
+ fmt,
+ req_url,
+ });
+ if (comptime Environment.allow_assert) {
+ std.debug.assert(this.sizeOfURL() == url.len);
+ }
+ this.url = url;
+ this.url_was_allocated = true;
+ return;
}
- this.url = try bun.default_allocator.dupe(u8, req_url);
- this.url_was_allocated = true;
}
+
+ if (comptime Environment.allow_assert) {
+ std.debug.assert(this.sizeOfURL() == req_url.len);
+ }
+ this.url = try bun.default_allocator.dupe(u8, req_url);
+ this.url_was_allocated = true;
}
}