uWS 18.1, WITH_PROXY, wrap new functions

This commit is contained in:
Alex Hultman 2020-06-08 14:03:09 +02:00
parent de719f9ec1
commit d6f2c1c50b
4 changed files with 59 additions and 3 deletions

View file

@ -94,6 +94,45 @@ struct HttpResponseWrapper {
}
}
/* Takes nothing, returns arraybuffer */
template <bool SSL>
static void res_getRemoteAddressAsText(const FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
auto *res = getHttpResponse<SSL>(args);
if (res) {
std::string_view ip = res->getRemoteAddressAsText();
/* Todo: we need to pass a copy here */
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
}
}
/* Takes nothing, returns arraybuffer */
template <bool SSL>
static void res_getProxiedRemoteAddress(const FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
auto *res = getHttpResponse<SSL>(args);
if (res) {
std::string_view ip = res->getProxiedRemoteAddress();
/* Todo: we need to pass a copy here */
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
}
}
/* Takes nothing, returns arraybuffer */
template <bool SSL>
static void res_getProxiedRemoteAddressAsText(const FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
auto *res = getHttpResponse<SSL>(args);
if (res) {
std::string_view ip = res->getProxiedRemoteAddressAsText();
/* Todo: we need to pass a copy here */
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
}
}
/* Returns the current write offset */
template <bool SSL>
static void res_getWriteOffset(const FunctionCallbackInfo<Value> &args) {
@ -316,6 +355,9 @@ struct HttpResponseWrapper {
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddress", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getRemoteAddress<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "cork", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_cork<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "upgrade", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_upgrade<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddressAsText", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getRemoteAddressAsText<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getProxiedRemoteAddress", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getProxiedRemoteAddress<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getProxiedRemoteAddressAsText", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getProxiedRemoteAddressAsText<SSL>));
/* Create our template */
Local<Object> resObjectLocal = resTemplateLocal->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();

View file

@ -110,6 +110,19 @@ struct WebSocketWrapper {
}
}
/* Takes nothing returns arraybuffer */
template <bool SSL>
static void uWS_WebSocket_getRemoteAddressAsText(const FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
auto *ws = getWebSocket<SSL>(args);
if (ws) {
std::string_view ip = ws->getRemoteAddressAsText();
/* Todo: we need to pass a copy here */
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
}
}
/* Takes nothing, returns integer */
template <bool SSL>
static void uWS_WebSocket_getBufferedAmount(const FunctionCallbackInfo<Value> &args) {
@ -205,10 +218,11 @@ struct WebSocketWrapper {
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "unsubscribeAll", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_unsubscribeAll<SSL>));
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "cork", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_cork<SSL>));
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "ping", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_ping<SSL>));
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddressAsText", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_getRemoteAddressAsText<SSL>));
/* Create the template */
Local<Object> wsObjectLocal = wsTemplateLocal->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
return wsObjectLocal;
}
};