Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/bun.js/bindings/ErrorCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,17 @@ JSC_DEFINE_HOST_FUNCTION(Bun::jsFunctionMakeErrorWithCode, (JSC::JSGlobalObject
return JSC::JSValue::encode(err);
}

case Bun::ErrorCode::ERR_HTTP_CONTENT_LENGTH_MISMATCH: {
auto arg0 = callFrame->argument(1);
auto str0 = arg0.toWTFString(globalObject);
RETURN_IF_EXCEPTION(scope, {});
auto arg1 = callFrame->argument(2);
auto str1 = arg1.toWTFString(globalObject);
RETURN_IF_EXCEPTION(scope, {});
auto message = makeString("Response body's content-length of "_s, str0, " byte(s) does not match the content-length of "_s, str1, " byte(s) set in header"_s);
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_HTTP_CONTENT_LENGTH_MISMATCH, message));
}

case ErrorCode::ERR_IPC_DISCONNECTED:
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_IPC_DISCONNECTED, "IPC channel is already disconnected"_s));
case ErrorCode::ERR_SERVER_NOT_RUNNING:
Expand Down Expand Up @@ -2518,6 +2529,8 @@ JSC_DEFINE_HOST_FUNCTION(Bun::jsFunctionMakeErrorWithCode, (JSC::JSGlobalObject
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_HTTP2_TOO_MANY_INVALID_FRAMES, "Too many invalid HTTP/2 frames"_s));
case ErrorCode::ERR_HTTP2_PING_CANCEL:
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_HTTP2_PING_CANCEL, "HTTP2 ping cancelled"_s));
case ErrorCode::ERR_HTTP_TRAILER_INVALID:
return JSC::JSValue::encode(createError(globalObject, ErrorCode::ERR_HTTP_TRAILER_INVALID, "Trailers are invalid with this transfer encoding"_s));

default: {
break;
Expand Down
1 change: 1 addition & 0 deletions src/bun.js/bindings/ErrorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ const errors: ErrorCodeMapping = [
["ERR_POSTGRES_UNSUPPORTED_INTEGER_SIZE", TypeError, "PostgresError"],
["ERR_POSTGRES_UNSUPPORTED_NUMERIC_FORMAT", TypeError, "PostgresError"],
["ERR_PROXY_INVALID_CONFIG", Error],
["ERR_PROXY_TUNNEL", Error],
["ERR_MYSQL_CONNECTION_CLOSED", Error, "MySQLError"],
["ERR_MYSQL_CONNECTION_TIMEOUT", Error, "MySQLError"],
["ERR_MYSQL_IDLE_TIMEOUT", Error, "MySQLError"],
Expand Down
1 change: 1 addition & 0 deletions src/codegen/bundle-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ declare module "module" {
dts += ` (id: "bun"): typeof import("bun");\n`;
dts += ` (id: "bun:test"): typeof import("bun:test");\n`;
dts += ` (id: "bun:jsc"): typeof import("bun:jsc");\n`;
dts += ` (id: "node:util/types"): typeof import("node:util/types");\n`;

for (let i = 0; i < nativeStartIndex; i++) {
const id = moduleList[i];
Expand Down
3 changes: 3 additions & 0 deletions src/js/builtins.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,8 @@ declare function $ERR_ASYNC_CALLBACK(name): TypeError;
declare function $ERR_AMBIGUOUS_ARGUMENT(arg, message): TypeError;
declare function $ERR_INVALID_FD_TYPE(type): TypeError;
declare function $ERR_IP_BLOCKED(ip): Error;
declare function $ERR_HTTP_CONTENT_LENGTH_MISMATCH(bodylen: number, headerlen: number): Error;
declare function $ERR_PROXY_TUNNEL(msg: string): Error;

declare function $ERR_IPC_DISCONNECTED(): Error;
declare function $ERR_SERVER_NOT_RUNNING(): Error;
Expand Down Expand Up @@ -837,6 +839,7 @@ declare function $ERR_HTTP2_CONNECT_SCHEME(): Error;
declare function $ERR_HTTP2_CONNECT_PATH(): Error;
declare function $ERR_HTTP2_TOO_MANY_INVALID_FRAMES(): Error;
declare function $ERR_HTTP2_PING_CANCEL(): Error;
declare function $ERR_HTTP_TRAILER_INVALID(): Error;

/**
* Convert a function to a class-like object.
Expand Down
5 changes: 5 additions & 0 deletions src/js/internal/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ function urlToHttpOptions(url) {
return options;
}

function isURL(self) {
return Boolean(self?.href && self.protocol && self.auth === undefined && self.path === undefined);
}

export default {
urlToHttpOptions,
isURL,
};
8 changes: 5 additions & 3 deletions src/js/node/_http_agent.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Hardcoded module "node:_http_agent"

const EventEmitter = require("node:events");
const { parseProxyConfigFromEnv, kProxyConfig, checkShouldUseProxy, kWaitForProxyTunnel } = require("internal/http");
const { getLazy, kEmptyObject, once } = require("internal/shared");
Expand Down Expand Up @@ -146,7 +148,7 @@ Agent.prototype.createConnection = function createConnection(...args) {
const shouldUseProxy = checkShouldUseProxy(this[kProxyConfig], options);
$debug(`http createConnection should use proxy for ${options.host}:${options.port}:`, shouldUseProxy);
if (!shouldUseProxy) {
// @ts-ignore
// @ts-expect-error
return net().createConnection(...args);
}

Expand All @@ -155,10 +157,10 @@ Agent.prototype.createConnection = function createConnection(...args) {
};
const proxyProtocol = this[kProxyConfig].protocol;
if (proxyProtocol === "http:") {
// @ts-ignore
// @ts-expect-error
return net().connect(connectOptions, cb);
} else if (proxyProtocol === "https:") {
// @ts-ignore
// @ts-expect-error
return tls().connect(connectOptions, cb);
}
// This should be unreachable because proxy config should be null for other protocols.
Expand Down
8 changes: 5 additions & 3 deletions src/js/node/_http_client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Hardcoded module "node:_http_client"

const { isIP, isIPv6 } = require("internal/net/isIP");

const { checkIsHttpToken, validateFunction, validateInteger, validateBoolean } = require("internal/validators");
Expand Down Expand Up @@ -67,7 +69,7 @@ function emitErrorEventNT(self, err) {
}
}

function ClientRequest(input, options, cb) {
function ClientRequest(input, options, cb): void {
if (!(this instanceof ClientRequest)) {
return new (ClientRequest as any)(input, options, cb);
}
Expand Down Expand Up @@ -910,11 +912,11 @@ function ClientRequest(input, options, cb) {
this[kEmitState] = 0;

this.setSocketKeepAlive = (_enable = true, _initialDelay = 0) => {
$debug(`${NODE_HTTP_WARNING}\n`, "WARN: ClientRequest.setSocketKeepAlive is a no-op");
$debug("WARN: ClientRequest.setSocketKeepAlive is a no-op");
};

this.setNoDelay = (_noDelay = true) => {
$debug(`${NODE_HTTP_WARNING}\n`, "WARN: ClientRequest.setNoDelay is a no-op");
$debug("WARN: ClientRequest.setNoDelay is a no-op");
};

this[kClearTimeout] = () => {
Expand Down
2 changes: 2 additions & 0 deletions src/js/node/_http_incoming.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Hardcoded module "node:_http_incoming"

const Readable = require("internal/streams/readable");

const {
Expand Down
2 changes: 2 additions & 0 deletions src/js/node/_http_outgoing.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Hardcoded module "node:_http_outgoing"

const { Stream } = require("internal/stream");
const { isUint8Array, validateString } = require("internal/validators");
const { deprecate } = require("internal/util/deprecate");
Expand Down
Loading