summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_parse.h
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2017-06-13 20:11:29 +0300
committerValentin Bartenev <vbart@nginx.com>2017-06-13 20:11:29 +0300
commitdb6642f374add9d645270e2eec3b803f8ab65321 (patch)
tree54f6650e4e2ecb57a7bd3e503d6a09498596228f /src/nxt_http_parse.h
parentf6e7c2b6a6b36fb54cc771e27dff61b8f079e688 (diff)
downloadunit-db6642f374add9d645270e2eec3b803f8ab65321.tar.gz
unit-db6642f374add9d645270e2eec3b803f8ab65321.tar.bz2
HTTP parser: decoupled header fields processing.
Diffstat (limited to 'src/nxt_http_parse.h')
-rw-r--r--src/nxt_http_parse.h83
1 files changed, 53 insertions, 30 deletions
diff --git a/src/nxt_http_parse.h b/src/nxt_http_parse.h
index 2376855e..4cf3dc3c 100644
--- a/src/nxt_http_parse.h
+++ b/src/nxt_http_parse.h
@@ -11,64 +11,87 @@
typedef struct nxt_http_request_parse_s nxt_http_request_parse_t;
typedef struct nxt_http_fields_hash_s nxt_http_fields_hash_t;
-typedef nxt_int_t (*nxt_http_field_handler_t)(void *ctx, nxt_str_t *name,
- nxt_str_t *value, uintptr_t data);
-
typedef union {
- u_char str[8];
- uint64_t ui64;
+ u_char str[8];
+ uint64_t ui64;
} nxt_http_ver_t;
-struct nxt_http_request_parse_s {
- nxt_int_t (*handler)(nxt_http_request_parse_t *rp,
- u_char **pos, u_char *end);
+typedef struct {
+ union {
+ uint8_t str[32];
+ uint64_t ui64[4];
+ } key;
- size_t offset;
+ nxt_str_t name;
+ nxt_str_t value;
+} nxt_http_field_t;
- nxt_str_t method;
- u_char *target_start;
- u_char *target_end;
- u_char *exten_start;
- u_char *args_start;
+struct nxt_http_request_parse_s {
+ nxt_int_t (*handler)(nxt_http_request_parse_t *rp,
+ u_char **pos, u_char *end);
- nxt_http_ver_t version;
+ size_t offset;
- union {
- uint8_t str[32];
- uint64_t ui64[4];
- } field_name_key;
+ nxt_str_t method;
+
+ u_char *target_start;
+ u_char *target_end;
+ u_char *exten_start;
+ u_char *args_start;
- nxt_str_t field_name;
- nxt_str_t field_value;
+ nxt_http_ver_t version;
- nxt_http_fields_hash_t *hash;
- void *ctx;
+ nxt_http_field_t field;
+ nxt_list_t *fields;
/* target with "/." */
- unsigned complex_target:1;
+ unsigned complex_target:1;
/* target with "%" */
- unsigned quoted_target:1;
+ unsigned quoted_target:1;
/* target with " " */
- unsigned space_in_target:1;
+ unsigned space_in_target:1;
/* target with "+" */
- unsigned plus_in_target:1;
+ unsigned plus_in_target:1;
};
+typedef nxt_int_t (*nxt_http_field_handler_t)(void *ctx,
+ nxt_http_field_t *field,
+ uintptr_t data, nxt_log_t *log);
+
+
typedef struct {
nxt_str_t name;
nxt_http_field_handler_t handler;
uintptr_t data;
-} nxt_http_fields_t;
+} nxt_http_fields_hash_entry_t;
+
+
+nxt_inline nxt_int_t
+nxt_http_parse_request_init(nxt_http_request_parse_t *rp, nxt_mem_pool_t *mp)
+{
+ rp->fields = nxt_list_create(mp, 8, sizeof(nxt_http_field_t));
+ if (nxt_slow_path(rp->fields == NULL)){
+ return NXT_ERROR;
+ }
+
+ return NXT_OK;
+}
nxt_int_t nxt_http_parse_request(nxt_http_request_parse_t *rp,
nxt_buf_mem_t *b);
-nxt_http_fields_hash_t *nxt_http_fields_hash(nxt_http_fields_t *fields,
- nxt_mem_pool_t *mp);
+
+nxt_http_fields_hash_t *nxt_http_fields_hash_create(
+ nxt_http_fields_hash_entry_t *entries, nxt_mem_pool_t *mp);
+nxt_http_fields_hash_entry_t *nxt_http_fields_hash_lookup(
+ nxt_http_fields_hash_t *hash, nxt_http_field_t *field);
+
+nxt_int_t nxt_http_fields_process(nxt_list_t *fields,
+ nxt_http_fields_hash_t *hash, void *ctx, nxt_log_t *log);
#endif /* _NXT_HTTP_PARSER_H_INCLUDED_ */