diff options
Diffstat (limited to 'src/nxt_http.h')
-rw-r--r-- | src/nxt_http.h | 87 |
1 files changed, 46 insertions, 41 deletions
diff --git a/src/nxt_http.h b/src/nxt_http.h index 835cf66d..ac1eedcf 100644 --- a/src/nxt_http.h +++ b/src/nxt_http.h @@ -11,6 +11,9 @@ typedef enum { NXT_HTTP_INVALID = 0, + NXT_HTTP_CONTINUE = 100, + NXT_HTTP_SWITCHING_PROTOCOLS = 101, + NXT_HTTP_OK = 200, NXT_HTTP_NO_CONTENT = 204, @@ -26,6 +29,7 @@ typedef enum { NXT_HTTP_LENGTH_REQUIRED = 411, NXT_HTTP_PAYLOAD_TOO_LARGE = 413, NXT_HTTP_URI_TOO_LONG = 414, + NXT_HTTP_UPGRADE_REQUIRED = 426, NXT_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431, NXT_HTTP_TO_HTTPS = 497, @@ -46,30 +50,26 @@ typedef enum { } nxt_http_te_t; +typedef enum { + NXT_HTTP_PROTO_H1 = 0, + NXT_HTTP_PROTO_H2, + NXT_HTTP_PROTO_DEVNULL, +} nxt_http_protocol_t; + + typedef struct { nxt_work_handler_t ready_handler; nxt_work_handler_t error_handler; } nxt_http_request_state_t; -typedef struct { - nxt_http_request_parse_t parser; - - uint8_t nbuffers; - uint8_t keepalive; /* 1 bit */ - uint8_t chunked; /* 1 bit */ - nxt_http_te_t transfer_encoding:8; /* 2 bits */ - - uint32_t header_size; +typedef struct nxt_h1proto_s nxt_h1proto_t; - nxt_http_request_t *request; - nxt_buf_t *buffers; - /* - * All fields before the conn field will - * be zeroed in a keep-alive connection. - */ - nxt_conn_t *conn; -} nxt_h1proto_t; +struct nxt_h1p_websocket_timer_s { + nxt_timer_t timer; + nxt_h1proto_t *h1p; + nxt_msec_t keepalive_interval; +}; typedef union { @@ -110,6 +110,7 @@ struct nxt_http_request_s { nxt_mp_t *mem_pool; nxt_buf_t *body; + nxt_buf_t *ws_frame; nxt_buf_t *out; const nxt_http_request_state_t *state; @@ -138,6 +139,8 @@ struct nxt_http_request_s { nxt_timer_t timer; void *timer_data; + void *req_rpc_data; + nxt_buf_t *last; nxt_http_response_t resp; @@ -145,10 +148,11 @@ struct nxt_http_request_s { nxt_http_status_t status:16; uint8_t pass_count; /* 8 bits */ - uint8_t protocol; /* 2 bits */ + nxt_http_protocol_t protocol:8; /* 2 bits */ uint8_t logged; /* 1 bit */ uint8_t header_sent; /* 1 bit */ uint8_t error; /* 1 bit */ + uint8_t websocket_handshake; /* 1 bit */ }; @@ -168,21 +172,18 @@ struct nxt_http_pass_s { }; -typedef void (*nxt_http_proto_body_read_t)(nxt_task_t *task, - nxt_http_request_t *r); -typedef void (*nxt_http_proto_local_addr_t)(nxt_task_t *task, - nxt_http_request_t *r); -typedef void (*nxt_http_proto_tls_t)(nxt_task_t *task, nxt_http_request_t *r); -typedef void (*nxt_http_proto_header_send_t)(nxt_task_t *task, - nxt_http_request_t *r); -typedef void (*nxt_http_proto_send_t)(nxt_task_t *task, nxt_http_request_t *r, - nxt_buf_t *out); -typedef nxt_off_t (*nxt_http_proto_body_bytes_sent_t)(nxt_task_t *task, - nxt_http_proto_t proto); -typedef void (*nxt_http_proto_discard_t)(nxt_task_t *task, - nxt_http_request_t *r, nxt_buf_t *last); -typedef void (*nxt_http_proto_close_t)(nxt_task_t *task, - nxt_http_proto_t proto, nxt_socket_conf_joint_t *joint); +typedef struct { + void (*body_read)(nxt_task_t *task, nxt_http_request_t *r); + void (*local_addr)(nxt_task_t *task, nxt_http_request_t *r); + void (*header_send)(nxt_task_t *task, nxt_http_request_t *r); + void (*send)(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *out); + nxt_off_t (*body_bytes_sent)(nxt_task_t *task, nxt_http_proto_t proto); + void (*discard)(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *last); + void (*close)(nxt_task_t *task, nxt_http_proto_t proto, + nxt_socket_conf_joint_t *joint); + void (*ws_frame_start)(nxt_task_t *task, nxt_http_request_t *r, + nxt_buf_t *ws_frame); +} nxt_http_proto_table_t; nxt_int_t nxt_http_init(nxt_task_t *task, nxt_runtime_t *rt); @@ -195,12 +196,15 @@ void nxt_http_request_error(nxt_task_t *task, nxt_http_request_t *r, nxt_http_status_t status); void nxt_http_request_read_body(nxt_task_t *task, nxt_http_request_t *r); void nxt_http_request_header_send(nxt_task_t *task, nxt_http_request_t *r); +void nxt_http_request_ws_frame_start(nxt_task_t *task, nxt_http_request_t *r, + nxt_buf_t *ws_frame); void nxt_http_request_send(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *out); nxt_buf_t *nxt_http_buf_mem(nxt_task_t *task, nxt_http_request_t *r, size_t size); nxt_buf_t *nxt_http_buf_last(nxt_http_request_t *r); void nxt_http_request_error_handler(nxt_task_t *task, void *obj, void *data); +void nxt_http_request_close_handler(nxt_task_t *task, void *obj, void *data); nxt_int_t nxt_http_request_host(void *ctx, nxt_http_field_t *field, uintptr_t data); @@ -226,14 +230,15 @@ extern nxt_time_string_t nxt_http_date_cache; extern nxt_lvlhsh_t nxt_response_fields_hash; -extern const nxt_http_proto_body_read_t nxt_http_proto_body_read[]; -extern const nxt_http_proto_local_addr_t nxt_http_proto_local_addr[]; -extern const nxt_http_proto_tls_t nxt_http_proto_tls[]; -extern const nxt_http_proto_header_send_t nxt_http_proto_header_send[]; -extern const nxt_http_proto_send_t nxt_http_proto_send[]; -extern const nxt_http_proto_body_bytes_sent_t nxt_http_proto_body_bytes_sent[]; -extern const nxt_http_proto_discard_t nxt_http_proto_discard[]; -extern const nxt_http_proto_close_t nxt_http_proto_close[]; +extern const nxt_http_proto_table_t nxt_http_proto[]; + +void nxt_h1p_websocket_first_frame_start(nxt_task_t *task, + nxt_http_request_t *r, nxt_buf_t *ws_frame); +void nxt_h1p_websocket_frame_start(nxt_task_t *task, nxt_http_request_t *r, + nxt_buf_t *ws_frame); +void nxt_h1p_complete_buffers(nxt_task_t *task, nxt_h1proto_t *h1p); +nxt_msec_t nxt_h1p_conn_request_timer_value(nxt_conn_t *c, uintptr_t data); +extern const nxt_conn_state_t nxt_h1p_idle_close_state; #endif /* _NXT_HTTP_H_INCLUDED_ */ |