4
#include "ngx_http_echo_request_info.h"
5
#include "ngx_http_echo_util.h"
6
#include "ngx_http_echo_handler.h"
11
static void ngx_http_echo_post_read_request_body(ngx_http_request_t *r);
14
ngx_http_echo_exec_echo_read_request_body(
15
ngx_http_request_t* r, ngx_http_echo_ctx_t *ctx)
17
return ngx_http_read_client_request_body(r,
18
ngx_http_echo_post_read_request_body);
23
ngx_http_echo_post_read_request_body(ngx_http_request_t *r)
25
ngx_http_echo_ctx_t *ctx;
27
ctx = ngx_http_get_module_ctx(r, ngx_http_echo_module);
29
dd("wait read request body %d", (int) ctx->wait_read_request_body);
31
if (ctx->wait_read_request_body) {
35
r->write_event_handler = ngx_http_echo_wev_handler;
37
ngx_http_echo_wev_handler(r);
42
/* this function's implementation is borrowed from nginx 0.8.20
43
* and modified a bit to work with subrequests.
44
* Copyrighted (C) by Igor Sysoev */
46
ngx_http_echo_request_method_variable(ngx_http_request_t *r,
47
ngx_http_variable_value_t *v, uintptr_t data)
49
if (r->method_name.data) {
50
v->len = r->method_name.len;
54
v->data = r->method_name.data;
63
/* this function's implementation is borrowed from nginx 0.8.20
64
* and modified a bit to work with subrequests.
65
* Copyrighted (C) by Igor Sysoev */
67
ngx_http_echo_client_request_method_variable(ngx_http_request_t *r,
68
ngx_http_variable_value_t *v, uintptr_t data)
70
if (r->main->method_name.data) {
71
v->len = r->main->method_name.len;
75
v->data = r->main->method_name.data;
84
/* this function's implementation is borrowed from nginx 0.8.20
85
* and modified a bit to work with subrequests.
86
* Copyrighted (C) by Igor Sysoev */
88
ngx_http_echo_request_body_variable(ngx_http_request_t *r,
89
ngx_http_variable_value_t *v, uintptr_t data)
93
ngx_buf_t *buf, *next;
96
if (r->request_body == NULL
97
|| r->request_body->bufs == NULL
98
|| r->request_body->temp_file)
105
cl = r->request_body->bufs;
108
if (cl->next == NULL) {
109
v->len = buf->last - buf->pos;
118
next = cl->next->buf;
119
len = (buf->last - buf->pos) + (next->last - next->pos);
121
p = ngx_pnalloc(r->pool, len);
128
p = ngx_cpymem(p, buf->pos, buf->last - buf->pos);
129
ngx_memcpy(p, next->pos, next->last - next->pos);
141
ngx_http_echo_client_request_headers_variable(ngx_http_request_t *r,
142
ngx_http_variable_value_t *v, uintptr_t data)
146
ngx_buf_t *header_in;
147
ngx_flag_t just_seen_crlf;
150
header_in = r->main->header_in;
152
header_in = r->header_in;
155
if (header_in == NULL) {
160
size = header_in->pos - header_in->start;
162
v->data = ngx_palloc(r->pool, size);
163
last = ngx_cpymem(v->data, header_in->start, size);
165
/* fix \0 introduced by the nginx header parser and
166
* locate the end of the header */
168
for (p = (u_char*)v->data; p != last; p++) {
170
if (p + 1 != last && *(p + 1) == LF) {
177
} else if (*p == CR) {
178
if (just_seen_crlf) {
183
} else if (*p != LF) {
188
v->len = last - v->data;
198
ngx_http_echo_cacheable_request_uri_variable(ngx_http_request_t *r,
199
ngx_http_variable_value_t *v, uintptr_t data)
206
v->data = r->uri.data;
216
ngx_http_echo_request_uri_variable(ngx_http_request_t *r,
217
ngx_http_variable_value_t *v, uintptr_t data)
224
v->data = r->uri.data;
234
ngx_http_echo_response_status_variable(ngx_http_request_t *r,
235
ngx_http_variable_value_t *v, uintptr_t data)
239
if (r->headers_out.status) {
240
dd("headers out status: %d", (int) r->headers_out.status);
242
p = ngx_palloc(r->pool, NGX_INT_T_LEN);
247
v->len = ngx_sprintf(p, "%ui", r->headers_out.status) - p;