aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-18 19:05:07 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-18 19:05:07 -0700
commit51ced7d3e3de965002d2818b9c18cb5e61283eb7 (patch)
tree5a551af8708f4909186c010096e47fd8dce45677
parent036e5800454c1d8a85bba5da29682fd53dcc3f17 (diff)
downloadbun-51ced7d3e3de965002d2818b9c18cb5e61283eb7.tar.gz
bun-51ced7d3e3de965002d2818b9c18cb5e61283eb7.tar.zst
bun-51ced7d3e3de965002d2818b9c18cb5e61283eb7.zip
Fix `bun:wrap` not loading
-rw-r--r--src/bun.js/api/server.zig2
-rw-r--r--src/http.zig48
-rw-r--r--src/http/method.zig12
3 files changed, 41 insertions, 21 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index aaa058330..4686c4a80 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -2163,7 +2163,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
if (wait_for_promise) {
// Even if the user hasn't requested it, we have to start downloading the body!!
// terrible for performance.
- if (request_object.body == .Locked and (request_object.body.Locked.promise == null and request_object.body.Locked.readable == null) and ((HTTP.Method.which(req.method()) orelse HTTP.Method.OPTIONS).hasBody())) {
+ if (request_object.body == .Locked and (request_object.body.Locked.promise == null and request_object.body.Locked.readable == null) and ((HTTP.Method.which(req.method()) orelse HTTP.Method.OPTIONS).hasRequestBody())) {
const req_len: usize = brk: {
if (req.header("content-length")) |content_length| {
break :brk std.fmt.parseInt(usize, content_length, 10) catch 0;
diff --git a/src/http.zig b/src/http.zig
index 00aa03124..49303d415 100644
--- a/src/http.zig
+++ b/src/http.zig
@@ -674,26 +674,33 @@ pub const RequestContext = struct {
}
const AsyncIO = @import("io");
- pub fn writeSocket(ctx: *RequestContext, buf: anytype, _: anytype) !usize {
- switch (Syscall.send(ctx.conn.client.socket.fd, buf, SOCKET_FLAGS)) {
- .err => |err| {
- const erro = AsyncIO.asError(err.getErrno());
- if (erro == error.EBADF or erro == error.ECONNABORTED or erro == error.ECONNREFUSED) {
- return error.SocketClosed;
- }
+ pub fn writeSocket(ctx: *RequestContext, buf_: anytype, _: anytype) !usize {
+ var total: usize = 0;
+ var buf: []const u8 = buf_;
+ while (buf.len > 0) {
+ switch (Syscall.send(ctx.conn.client.socket.fd, buf, SOCKET_FLAGS)) {
+ .err => |err| {
+ const erro = AsyncIO.asError(err.getErrno());
+ if (erro == error.EBADF or erro == error.ECONNABORTED or erro == error.ECONNREFUSED) {
+ return error.SocketClosed;
+ }
- Output.prettyErrorln("send() error: {s}", .{err.toSystemError().message.slice()});
+ Output.prettyErrorln("send() error: {s}", .{err.toSystemError().message.slice()});
- return erro;
- },
- .result => |written| {
- if (written == 0) {
- return error.SocketClosed;
- }
+ return erro;
+ },
+ .result => |written| {
+ if (written == 0) {
+ return error.SocketClosed;
+ }
- return written;
- },
+ buf = buf[written..];
+ total += written;
+ },
+ }
}
+
+ return total;
}
pub fn writeBodyBuf(ctx: *RequestContext, body: []const u8) !void {
@@ -3478,6 +3485,7 @@ pub const Server = struct {
},
}
};
+
break :restart;
}
@@ -3499,11 +3507,11 @@ pub const Server = struct {
try listener.listen(1280);
const addr = try listener.getLocalAddress();
- if (server.bundler.options.origin.getPort()) |_port| {
- if (_port != addr.ipv4.port) {
- server.bundler.options.origin.port = try std.fmt.allocPrint(server.allocator, "{d}", .{addr.ipv4.port});
- }
+
+ if (port != addr.ipv4.port) {
+ server.bundler.options.origin.port = try std.fmt.allocPrint(server.allocator, "{d}", .{addr.ipv4.port});
}
+
const start_time = Global.getStartTime();
const now = std.time.nanoTimestamp();
Output.printStartEnd(start_time, now);
diff --git a/src/http/method.zig b/src/http/method.zig
index 4f6c7827e..35017e6af 100644
--- a/src/http/method.zig
+++ b/src/http/method.zig
@@ -26,6 +26,14 @@ pub const Method = enum {
values.remove(.HEAD);
values.remove(.TRACE);
values.remove(.OPTIONS);
+ break :brk values;
+ };
+
+ const with_request_body: std.enums.EnumSet(Method) = brk: {
+ var values = std.enums.EnumSet(Method).initFull();
+ values.remove(.HEAD);
+ values.remove(.TRACE);
+ values.remove(.OPTIONS);
values.remove(.GET);
break :brk values;
};
@@ -34,6 +42,10 @@ pub const Method = enum {
return with_body.contains(this);
}
+ pub fn hasRequestBody(this: Method) bool {
+ return with_request_body.contains(this);
+ }
+
pub fn which(str: []const u8) ?Method {
if (str.len < 3) {
return null;