xref: /unit/src/nodejs/unit-http/unit.h (revision 828:b9f7635e6be2)
1 
2 /*
3  * Copyright (C) NGINX, Inc.
4  */
5 
6 #ifndef _NXT_NODEJS_UNIT_H_INCLUDED_
7 #define _NXT_NODEJS_UNIT_H_INCLUDED_
8 
9 
10 #include <node_api.h>
11 
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #include <nxt_unit.h>
18 #include <nxt_unit_response.h>
19 #include <nxt_unit_request.h>
20 
21 #ifdef __cplusplus
22 } /* extern "C" */
23 #endif
24 
25 
26 class Unit {
27 public:
28     static napi_value init(napi_env env, napi_value exports);
29 
30 private:
31     Unit(napi_env env);
32     ~Unit();
33 
34     static napi_value create(napi_env env, napi_callback_info info);
35     static void destroy(napi_env env, void *nativeObject, void *finalize_hint);
36 
37     static napi_value create_server(napi_env env, napi_callback_info info);
38     static napi_value listen(napi_env env, napi_callback_info info);
39     static napi_value _read(napi_env env, napi_callback_info info);
40     static void request_handler(nxt_unit_request_info_t *req);
41     static int add_port(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port);
42     static void remove_port(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id);
43 
44     napi_value get_server_object();
45 
46     napi_value create_socket(napi_value server_obj,
47                              nxt_unit_request_info_t *req);
48 
49     napi_value create_request(napi_value server_obj, napi_value socket);
50 
51     napi_value create_response(napi_value server_obj, napi_value socket,
52                                napi_value request,
53                                nxt_unit_request_info_t *req, Unit *obj);
54 
55     static napi_value response_send_headers(napi_env env,
56                                             napi_callback_info info);
57 
58     static napi_value response_write(napi_env env, napi_callback_info info);
59     static napi_value response_end(napi_env env, napi_callback_info info);
60 
61     napi_status create_headers(nxt_unit_request_info_t *req,
62                                napi_value request);
63 
64     inline napi_status append_header(nxt_unit_field_t *f, napi_value headers,
65                                      napi_value raw_headers, uint32_t idx);
66 
67     static napi_ref constructor_;
68 
69     napi_env        env_;
70     napi_ref        wrapper_;
71     nxt_unit_ctx_t  *unit_ctx_;
72 };
73 
74 
75 #endif /* _NXT_NODEJS_H_INCLUDED_ */
76