xref: /unit/src/nodejs/unit-http/unit.h (revision 842:8c77d7fdf952)
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     static void quit(nxt_unit_ctx_t *ctx);
44 
45     napi_value get_server_object();
46 
47     napi_value create_socket(napi_value server_obj,
48                              nxt_unit_request_info_t *req);
49 
50     napi_value create_request(napi_value server_obj, napi_value socket);
51 
52     napi_value create_response(napi_value server_obj, napi_value socket,
53                                napi_value request,
54                                nxt_unit_request_info_t *req, Unit *obj);
55 
56     static napi_value response_send_headers(napi_env env,
57                                             napi_callback_info info);
58 
59     static napi_value response_write(napi_env env, napi_callback_info info);
60     static napi_value response_end(napi_env env, napi_callback_info info);
61 
62     napi_status create_headers(nxt_unit_request_info_t *req,
63                                napi_value request);
64 
65     inline napi_status append_header(nxt_unit_field_t *f, napi_value headers,
66                                      napi_value raw_headers, uint32_t idx);
67 
68     static napi_ref constructor_;
69 
70     napi_env        env_;
71     napi_ref        wrapper_;
72     nxt_unit_ctx_t  *unit_ctx_;
73 };
74 
75 
76 #endif /* _NXT_NODEJS_H_INCLUDED_ */
77