Adding 'connection' to request as an alias to 'socket'.

Adding actual 'remoteAddress' and 'localAddress' into socket object.

This closes #232 issue on GitHub.
This commit is contained in:
Max Romanov
2019-04-01 16:40:49 +03:00
parent 8557cb3660
commit 56101e47ee

View File

@@ -399,15 +399,20 @@ Unit::append_header(nxt_unit_field_t *f, napi_value headers,
napi_value napi_value
Unit::create_socket(napi_value server_obj, nxt_unit_request_info_t *req) Unit::create_socket(napi_value server_obj, nxt_unit_request_info_t *req)
{ {
napi_value constructor, return_val; napi_value constructor, res;
nxt_unit_request_t *r;
r = req->request;
constructor = get_named_property(server_obj, "socket"); constructor = get_named_property(server_obj, "socket");
return_val = new_instance(constructor); res = new_instance(constructor);
set_named_property(return_val, "req_pointer", (intptr_t) req); set_named_property(res, "req_pointer", (intptr_t) req);
set_named_property(res, "remoteAddress", r->remote, r->remote_length);
set_named_property(res, "localAddress", r->local, r->local_length);
return return_val; return res;
} }
@@ -421,6 +426,7 @@ Unit::create_request(napi_value server_obj, napi_value socket)
return_val = new_instance(constructor, server_obj); return_val = new_instance(constructor, server_obj);
set_named_property(return_val, "socket", socket); set_named_property(return_val, "socket", socket);
set_named_property(return_val, "connection", socket);
return return_val; return return_val;
} }
@@ -437,6 +443,7 @@ Unit::create_response(napi_value server_obj, napi_value socket,
return_val = new_instance(constructor, request); return_val = new_instance(constructor, request);
set_named_property(return_val, "socket", socket); set_named_property(return_val, "socket", socket);
set_named_property(return_val, "connection", socket);
set_named_property(return_val, "_req_point", (intptr_t) req); set_named_property(return_val, "_req_point", (intptr_t) req);
return return_val; return return_val;