aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/webcore/request.zig
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-09-29 03:39:26 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-29 03:39:26 -0700
commit6afa78120ac0512bc55d00a8a1562d8f0eafa2c2 (patch)
tree6a413589452d966f42c1e97e39fd11a82308e565 /src/bun.js/webcore/request.zig
parent6514dcf4cbc63cff89f3cac59598872caf776f0b (diff)
downloadbun-6afa78120ac0512bc55d00a8a1562d8f0eafa2c2.tar.gz
bun-6afa78120ac0512bc55d00a8a1562d8f0eafa2c2.tar.zst
bun-6afa78120ac0512bc55d00a8a1562d8f0eafa2c2.zip
feat(runtime): implement `server.requestIp` + node:http `socket.address()` (#6165)
* [server] requestIp and AnyRequestContext Changed Request.uws_request to the new AnyRequestContext. This allows grabbing the IP from a Request. Unfinished. * [server] basic `requestIp` implementation Currently using uws's requestIpAsText, which always returns a ipv6 string. We should return a `SocketAddress` object to the user instead, which will contain the formatted address string and what type it is. We'll have to use requestIpAsBinary and parse that ourselves. * TypeScript docs, use `bun.String`, return `undefined` instead of `null` if we can't get the ip. * binary address formatting * uws getRemoteAddress binding * remove dead code * working * final touches:sparkles: * I will abide by the results of this poll. --------- Co-authored-by: Parzival-3141 <29632054+Parzival-3141@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/webcore/request.zig')
-rw-r--r--src/bun.js/webcore/request.zig12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/bun.js/webcore/request.zig b/src/bun.js/webcore/request.zig
index db073fccc..381ae2750 100644
--- a/src/bun.js/webcore/request.zig
+++ b/src/bun.js/webcore/request.zig
@@ -68,7 +68,7 @@ pub const Request = struct {
signal: ?*AbortSignal = null,
body: *BodyValueRef,
method: Method = Method.GET,
- uws_request: ?*uws.Request = null,
+ request_context: JSC.API.AnyRequestContext = JSC.API.AnyRequestContext.Null,
https: bool = false,
upgrader: ?*anyopaque = null,
@@ -89,7 +89,7 @@ pub const Request = struct {
pub fn getContentType(
this: *Request,
) ?ZigString.Slice {
- if (this.uws_request) |req| {
+ if (this.request_context.getRequest()) |req| {
if (req.header("content-type")) |value| {
return ZigString.Slice.fromUTF8NeverFree(value);
}
@@ -324,7 +324,7 @@ pub const Request = struct {
if (this.url.length() > 0)
return this.url.byteSlice().len;
- if (this.uws_request) |req| {
+ if (this.request_context.getRequest()) |req| {
const req_url = req.url();
if (req_url.len > 0 and req_url[0] == '/') {
if (req.header("host")) |host| {
@@ -351,7 +351,7 @@ pub const Request = struct {
pub fn ensureURL(this: *Request) !void {
if (!this.url.isEmpty()) return;
- if (this.uws_request) |req| {
+ if (this.request_context.getRequest()) |req| {
const req_url = req.url();
if (req_url.len > 0 and req_url[0] == '/') {
if (req.header("host")) |host| {
@@ -723,7 +723,7 @@ pub const Request = struct {
globalThis: *JSC.JSGlobalObject,
) callconv(.C) JSC.JSValue {
if (this.headers == null) {
- if (this.uws_request) |req| {
+ if (this.request_context.getRequest()) |req| {
this.headers = FetchHeaders.createFromUWS(globalThis, req);
} else {
this.headers = FetchHeaders.createEmpty();
@@ -742,7 +742,7 @@ pub const Request = struct {
pub fn cloneHeaders(this: *Request, globalThis: *JSGlobalObject) ?*FetchHeaders {
if (this.headers == null) {
- if (this.uws_request) |uws_req| {
+ if (this.request_context.getRequest()) |uws_req| {
this.headers = FetchHeaders.createFromUWS(globalThis, uws_req);
}
}