Skip to content

Commit

Permalink
[fetch] Add support for gzip & deflate to the http client
Browse files Browse the repository at this point in the history
Powered by Cloudflare's zlib fork
  • Loading branch information
Jarred-Sumner committed Oct 11, 2021
1 parent 5e3d1dd commit 0db7af6
Show file tree
Hide file tree
Showing 18 changed files with 1,461 additions and 1,095 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ packages/debug-*
packages/bun-cli/postinstall.js
packages/bun-*/bin/*

packages/bun-cli/bin/*
packages/bun-cli/bin/*
bun-test-scratch
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
path = src/deps/mimalloc
url = https://github.com/microsoft/mimalloc.git
ignore = dirty
[submodule "src/deps/zlib"]
path = src/deps/zlib
url = https://github.com/cloudflare/zlib
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ endif
bun: vendor build-obj bun-link-lld-release


vendor-without-check: api analytics node-fallbacks runtime_js fallback_decoder bun_error mimalloc picohttp
vendor-without-check: api analytics node-fallbacks runtime_js fallback_decoder bun_error mimalloc picohttp zlib

vendor: require init-submodules vendor-without-check

zlib:
cd src/deps/zlib; cmake .; make;

require:
@echo "Checking if the required utilities are available..."
@realpath --version >/dev/null 2>&1 || (echo "ERROR: realpath is required."; exit 1)
Expand Down Expand Up @@ -317,6 +320,7 @@ BUN_LLD_FLAGS := $(OBJ_FILES) \
${JSC_FILES} \
src/deps/picohttpparser.o \
src/deps/mimalloc/libmimalloc.a \
src/deps/zlib/libz.a \
$(CLANG_FLAGS) \


Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ Bun also statically links these libraries:
- `libicu`, which can be found here: https://github.com/unicode-org/icu/blob/main/icu4c/LICENSE
- [`picohttp`](https://github.com/h2o/picohttpparser), which is dual-licensed under the Perl License or the MIT License
- [`mimalloc`](https://github.com/microsoft/mimalloc), which is MIT licensed
- [`zlib-cloudflare`](https://github.com/cloudflare/zlib), which is zlib licensed
For compatibiltiy reasons, these NPM packages are embedded into Bun's binary and injected if imported.
Expand Down
Binary file added fixtures_example.com.html.gz
Binary file not shown.
332 changes: 0 additions & 332 deletions src/Wyhash.zig

This file was deleted.

1 change: 1 addition & 0 deletions src/deps/zlib
Submodule zlib added at 959b4e
5 changes: 5 additions & 0 deletions src/global.zig
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ pub const Output = struct {
return enable_ansi_colors and !isWindows;
}

pub fn initTest() void {
var in = std.io.getStdErr();
var src = Output.Source.init(in, in);
Output.Source.set(&src);
}
pub fn enableBuffering() void {
enable_buffering = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hash_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const mem = std.mem;
const meta = std.meta;
const trait = meta.trait;
const Allocator = mem.Allocator;
const Wyhash = @import("./Wyhash.zig").Wyhash;
const Wyhash = std.hash.Wyhash;

pub fn getAutoHashFn(comptime K: type) (fn (K) u64) {
comptime {
Expand Down
6 changes: 3 additions & 3 deletions src/http.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const IPv6 = std.x.os.IPv6;
const Socket = std.x.os.Socket;
const os = std.os;

const picohttp = @import("picohttp");
const picohttp = @import("./deps/picohttp.zig");
const Header = picohttp.Header;
const Request = picohttp.Request;
const Response = picohttp.Response;
Expand Down Expand Up @@ -592,8 +592,8 @@ pub const RequestContext = struct {
}

pub fn appendHeader(ctx: *RequestContext, comptime key: string, value: string) void {
if (isDebug or isTest) std.debug.assert(!ctx.has_written_last_header);
if (isDebug or isTest) std.debug.assert(ctx.res_headers_count < res_headers_buf.len);
if (comptime isDebug or isTest) std.debug.assert(!ctx.has_written_last_header);
if (comptime isDebug or isTest) std.debug.assert(ctx.res_headers_count < res_headers_buf.len);
res_headers_buf[ctx.res_headers_count] = Header{ .name = key, .value = value };
ctx.res_headers_count += 1;
}
Expand Down
Loading

0 comments on commit 0db7af6

Please sign in to comment.