Lines 1-145
Link Here
|
1 |
--- lib/core/request.c.orig 2016-09-13 06:57:03 UTC |
|
|
2 |
+++ lib/core/request.c |
3 |
@@ -31,21 +31,24 @@ |
4 |
|
5 |
#define INITIAL_INBUFSZ 8192 |
6 |
|
7 |
-struct st_delegate_request_deferred_t { |
8 |
+struct st_deferred_request_action_t { |
9 |
+ h2o_timeout_entry_t timeout; |
10 |
h2o_req_t *req; |
11 |
+}; |
12 |
+ |
13 |
+struct st_delegate_request_deferred_t { |
14 |
+ struct st_deferred_request_action_t super; |
15 |
h2o_handler_t *current_handler; |
16 |
- h2o_timeout_entry_t _timeout; |
17 |
}; |
18 |
|
19 |
struct st_reprocess_request_deferred_t { |
20 |
- h2o_req_t *req; |
21 |
+ struct st_deferred_request_action_t super; |
22 |
h2o_iovec_t method; |
23 |
const h2o_url_scheme_t *scheme; |
24 |
h2o_iovec_t authority; |
25 |
h2o_iovec_t path; |
26 |
h2o_req_overrides_t *overrides; |
27 |
int is_delegated; |
28 |
- h2o_timeout_entry_t _timeout; |
29 |
}; |
30 |
|
31 |
struct st_send_error_deferred_t { |
32 |
@@ -57,6 +60,21 @@ struct st_send_error_deferred_t { |
33 |
h2o_timeout_entry_t _timeout; |
34 |
}; |
35 |
|
36 |
+static void on_deferred_action_dispose(void *_action) |
37 |
+{ |
38 |
+ struct st_deferred_request_action_t *action = _action; |
39 |
+ if (h2o_timeout_is_linked(&action->timeout)) |
40 |
+ h2o_timeout_unlink(&action->timeout); |
41 |
+} |
42 |
+ |
43 |
+static struct st_deferred_request_action_t *create_deferred_action(h2o_req_t *req, size_t sz, h2o_timeout_cb cb) |
44 |
+{ |
45 |
+ struct st_deferred_request_action_t *action = h2o_mem_alloc_shared(&req->pool, sz, on_deferred_action_dispose); |
46 |
+ *action = (struct st_deferred_request_action_t){{0, cb}, req}; |
47 |
+ h2o_timeout_link(req->conn->ctx->loop, &req->conn->ctx->zero_timeout, &action->timeout); |
48 |
+ return action; |
49 |
+} |
50 |
+ |
51 |
static h2o_hostconf_t *find_hostconf(h2o_hostconf_t **hostconfs, h2o_iovec_t authority, uint16_t default_port) |
52 |
{ |
53 |
h2o_iovec_t hostname; |
54 |
@@ -205,6 +223,7 @@ void h2o_init_request(h2o_req_t *req, h2 |
55 |
req->preferred_chunk_size = SIZE_MAX; |
56 |
|
57 |
if (src != NULL) { |
58 |
+ size_t i; |
59 |
#define COPY(buf) \ |
60 |
do { \ |
61 |
req->buf.base = h2o_mem_alloc_pool(&req->pool, src->buf.len); \ |
62 |
@@ -216,9 +235,6 @@ void h2o_init_request(h2o_req_t *req, h2 |
63 |
COPY(input.path); |
64 |
req->input.scheme = src->input.scheme; |
65 |
req->version = src->version; |
66 |
- h2o_vector_reserve(&req->pool, &req->headers, src->headers.size); |
67 |
- memcpy(req->headers.entries, src->headers.entries, sizeof(req->headers.entries[0]) * src->headers.size); |
68 |
- req->headers.size = src->headers.size; |
69 |
req->entity = src->entity; |
70 |
req->http1_is_persistent = src->http1_is_persistent; |
71 |
req->timestamps = src->timestamps; |
72 |
@@ -229,8 +245,19 @@ void h2o_init_request(h2o_req_t *req, h2 |
73 |
req->upgrade.len = 0; |
74 |
} |
75 |
#undef COPY |
76 |
+ h2o_vector_reserve(&req->pool, &req->headers, src->headers.size); |
77 |
+ req->headers.size = src->headers.size; |
78 |
+ for (i = 0; i != src->headers.size; ++i) { |
79 |
+ h2o_header_t *dst_header = req->headers.entries + i, *src_header = src->headers.entries + i; |
80 |
+ if (h2o_iovec_is_token(src_header->name)) { |
81 |
+ dst_header->name = src_header->name; |
82 |
+ } else { |
83 |
+ dst_header->name = h2o_mem_alloc_pool(&req->pool, sizeof(*dst_header->name)); |
84 |
+ *dst_header->name = h2o_strdup(&req->pool, src_header->name->base, src_header->name->len); |
85 |
+ } |
86 |
+ dst_header->value = h2o_strdup(&req->pool, src_header->value.base, src_header->value.len); |
87 |
+ } |
88 |
if (src->env.size != 0) { |
89 |
- size_t i; |
90 |
h2o_vector_reserve(&req->pool, &req->env, src->env.size); |
91 |
req->env.size = src->env.size; |
92 |
for (i = 0; i != req->env.size; ++i) |
93 |
@@ -276,16 +303,16 @@ void h2o_delegate_request(h2o_req_t *req |
94 |
|
95 |
static void on_delegate_request_cb(h2o_timeout_entry_t *entry) |
96 |
{ |
97 |
- struct st_delegate_request_deferred_t *args = H2O_STRUCT_FROM_MEMBER(struct st_delegate_request_deferred_t, _timeout, entry); |
98 |
- h2o_delegate_request(args->req, args->current_handler); |
99 |
+ struct st_delegate_request_deferred_t *args = |
100 |
+ H2O_STRUCT_FROM_MEMBER(struct st_delegate_request_deferred_t, super.timeout, entry); |
101 |
+ h2o_delegate_request(args->super.req, args->current_handler); |
102 |
} |
103 |
|
104 |
void h2o_delegate_request_deferred(h2o_req_t *req, h2o_handler_t *current_handler) |
105 |
{ |
106 |
- struct st_delegate_request_deferred_t *args = h2o_mem_alloc_pool(&req->pool, sizeof(*args)); |
107 |
- *args = (struct st_delegate_request_deferred_t){req, current_handler}; |
108 |
- args->_timeout.cb = on_delegate_request_cb; |
109 |
- h2o_timeout_link(req->conn->ctx->loop, &req->conn->ctx->zero_timeout, &args->_timeout); |
110 |
+ struct st_delegate_request_deferred_t *args = |
111 |
+ (struct st_delegate_request_deferred_t *)create_deferred_action(req, sizeof(*args), on_delegate_request_cb); |
112 |
+ args->current_handler = current_handler; |
113 |
} |
114 |
|
115 |
void h2o_reprocess_request(h2o_req_t *req, h2o_iovec_t method, const h2o_url_scheme_t *scheme, h2o_iovec_t authority, |
116 |
@@ -335,17 +362,23 @@ void h2o_reprocess_request(h2o_req_t *re |
117 |
|
118 |
static void on_reprocess_request_cb(h2o_timeout_entry_t *entry) |
119 |
{ |
120 |
- struct st_reprocess_request_deferred_t *args = H2O_STRUCT_FROM_MEMBER(struct st_reprocess_request_deferred_t, _timeout, entry); |
121 |
- h2o_reprocess_request(args->req, args->method, args->scheme, args->authority, args->path, args->overrides, args->is_delegated); |
122 |
+ struct st_reprocess_request_deferred_t *args = |
123 |
+ H2O_STRUCT_FROM_MEMBER(struct st_reprocess_request_deferred_t, super.timeout, entry); |
124 |
+ h2o_reprocess_request(args->super.req, args->method, args->scheme, args->authority, args->path, args->overrides, |
125 |
+ args->is_delegated); |
126 |
} |
127 |
|
128 |
void h2o_reprocess_request_deferred(h2o_req_t *req, h2o_iovec_t method, const h2o_url_scheme_t *scheme, h2o_iovec_t authority, |
129 |
h2o_iovec_t path, h2o_req_overrides_t *overrides, int is_delegated) |
130 |
{ |
131 |
- struct st_reprocess_request_deferred_t *args = h2o_mem_alloc_pool(&req->pool, sizeof(*args)); |
132 |
- *args = (struct st_reprocess_request_deferred_t){req, method, scheme, authority, path, overrides, is_delegated}; |
133 |
- args->_timeout.cb = on_reprocess_request_cb; |
134 |
- h2o_timeout_link(req->conn->ctx->loop, &req->conn->ctx->zero_timeout, &args->_timeout); |
135 |
+ struct st_reprocess_request_deferred_t *args = |
136 |
+ (struct st_reprocess_request_deferred_t *)create_deferred_action(req, sizeof(*args), on_reprocess_request_cb); |
137 |
+ args->method = method; |
138 |
+ args->scheme = scheme; |
139 |
+ args->authority = authority; |
140 |
+ args->path = path; |
141 |
+ args->overrides = overrides; |
142 |
+ args->is_delegated = is_delegated; |
143 |
} |
144 |
|
145 |
void h2o_start_response(h2o_req_t *req, h2o_generator_t *generator) |