Files
bun.sh/src/bun.js/bindings/JSSocketAddress.h
dave caruso 6afa78120a 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

* I will abide by the results of this poll.

---------

Co-authored-by: Parzival-3141 <29632054+Parzival-3141@users.noreply.github.com>
2023-09-29 03:39:26 -07:00

20 lines
581 B
C++

// The object returned by Bun.serve's .requestIP()
#pragma once
#include "root.h"
#include "JavaScriptCore/JSObjectInlines.h"
using namespace JSC;
namespace Bun {
namespace JSSocketAddress {
static const NeverDestroyed<String> IPv4 = MAKE_STATIC_STRING_IMPL("IPv4");
static const NeverDestroyed<String> IPv6 = MAKE_STATIC_STRING_IMPL("IPv6");
Structure* createStructure(VM& vm, JSGlobalObject* globalObject);
} // namespace JSSocketAddress
} // namespace Bun
extern "C" JSObject* JSSocketAddress__create(JSGlobalObject* globalObject, JSString* value, int port, bool isIPv6);