diff options
author | 2021-10-14 05:22:47 -0700 | |
---|---|---|
committer | 2021-10-14 05:22:47 -0700 | |
commit | 4b618f9ad1a45f6819dcb65e9b6b5b859e0df9fd (patch) | |
tree | 9bc3aac20a9ab2863be3409c6cffb9983d165b84 /src/http_client.zig | |
parent | 0f7bc76f39b6792052be799779e8d10ee03c564c (diff) | |
download | bun-4b618f9ad1a45f6819dcb65e9b6b5b859e0df9fd.tar.gz bun-4b618f9ad1a45f6819dcb65e9b6b5b859e0df9fd.tar.zst bun-4b618f9ad1a45f6819dcb65e9b6b5b859e0df9fd.zip |
`bun create react app` is almost done
Diffstat (limited to 'src/http_client.zig')
-rw-r--r-- | src/http_client.zig | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/http_client.zig b/src/http_client.zig index 09614636d..3ac7a22cd 100644 --- a/src/http_client.zig +++ b/src/http_client.zig @@ -46,6 +46,7 @@ read_count: u32 = 0, remaining_redirect_count: i8 = 127, redirect_buf: [2048]u8 = undefined, disable_shutdown: bool = false, +timeout: u32 = 0, pub fn init(allocator: *std.mem.Allocator, method: Method, url: URL, header_entries: Headers.Entries, header_buf: string) HTTPClient { return HTTPClient{ @@ -225,6 +226,11 @@ pub fn connect( client.setReadBufferSize(http_req_buf.len) catch {}; client.setQuickACK(true) catch {}; + if (this.timeout > 0) { + client.setReadTimeout(this.timeout) catch {}; + client.setWriteTimeout(this.timeout) catch {}; + } + // if (this.url.isLocalhost()) { // try client.connect( // try std.x.os.Socket.Address.initIPv4(try std.net.Address.resolveIp("localhost", port), port), @@ -394,6 +400,7 @@ pub fn processResponse(this: *HTTPClient, comptime is_https: bool, comptime Clie content_length = std.fmt.parseInt(u32, header.value, 10) catch 0; try body_out_str.inflate(content_length); body_out_str.list.expandToCapacity(); + this.body_size = content_length; }, content_encoding_hash => { if (strings.eqlComptime(header.value, "gzip")) { @@ -486,6 +493,10 @@ pub fn processResponse(this: *HTTPClient, comptime is_https: bool, comptime Clie // set consume_trailer to 1 to discard the trailing header // using content-encoding per chunk is not supported decoder.consume_trailer = 1; + + // these variable names are terrible + // it's copypasta from https://github.com/h2o/picohttpparser#phr_decode_chunked + // (but ported from C -> zig) var rret: usize = 0; var rsize: usize = last_read; var pret: isize = picohttp.phr_decode_chunked(&decoder, buffer.list.items.ptr, &rsize); @@ -530,6 +541,7 @@ pub fn processResponse(this: *HTTPClient, comptime is_https: bool, comptime Clie else => {}, } + this.body_size = @intCast(u32, body_out_str.list.items.len); return response; } |