diff options
author | 2022-11-20 07:03:50 -0800 | |
---|---|---|
committer | 2022-11-20 07:03:50 -0800 | |
commit | a4b67ccbff11967cf4756520eb5912f767a2bbab (patch) | |
tree | 9ffd6d7ea6ed620a2fbd23fa73f9426b23fb8799 /src/http_client_async.zig | |
parent | 1fca6becd3233d234d192e4528be4c14e5a5083c (diff) | |
download | bun-a4b67ccbff11967cf4756520eb5912f767a2bbab.tar.gz bun-a4b67ccbff11967cf4756520eb5912f767a2bbab.tar.zst bun-a4b67ccbff11967cf4756520eb5912f767a2bbab.zip |
fix protocol relative urls again
Diffstat (limited to 'src/http_client_async.zig')
-rw-r--r-- | src/http_client_async.zig | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/http_client_async.zig b/src/http_client_async.zig index 743be4558..3c18b9552 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -1998,6 +1998,30 @@ pub fn handleResponseMetadata( this.url = URL.parse(url_buf.data[0..url_buf_len]); this.redirect = url_buf; + } else if (strings.hasPrefixComptime(location, "//")) { + var url_buf = URLBufferPool.get(default_allocator); + + const protocol_name = this.url.displayProtocol(); + + if (protocol_name.len + 1 + location.len > url_buf.data.len) { + return error.RedirectURLTooLong; + } + + deferred_redirect.* = this.redirect; + var url_buf_len = location.len; + + if (strings.eqlComptime(protocol_name, "http")) { + url_buf.data[0.."http:".len].* = "http:".*; + std.mem.copy(u8, url_buf.data["http:".len..], location); + url_buf_len += "http:".len; + } else { + url_buf.data[0.."https:".len].* = "https:".*; + std.mem.copy(u8, url_buf.data["https:".len..], location); + url_buf_len += "https:".len; + } + + this.url = URL.parse(url_buf.data[0..url_buf_len]); + this.redirect = url_buf; } else { var url_buf = URLBufferPool.get(default_allocator); const original_url = this.url; |