static ngx_int_t ngx_http_ajp_create_request(ngx_http_request_t *r) { ajp_msg_t *msg; ngx_chain_t *cl; ngx_http_ajp_ctx_t *a; ngx_http_ajp_loc_conf_t *alcf; a = ngx_http_get_module_ctx(r, ngx_http_ajp_module); alcf = ngx_http_get_module_loc_conf(r, ngx_http_ajp_module); if (a == NULL || alcf == NULL) { return NGX_ERROR; } msg = ajp_msg_reuse(&a->msg); if (NGX_OK != ajp_msg_create_buffer(r->pool, alcf->ajp_header_packet_buffer_size_conf, msg)) { return NGX_ERROR; } if (NGX_OK != ajp_marshal_into_msgb(msg, r, alcf)) { return NGX_ERROR; } ajp_msg_end(msg); cl = ngx_alloc_chain_link(r->pool); if (cl == NULL) { return NGX_ERROR; } cl->buf = msg->buf; cl->buf->flush = 1; a->state = ngx_http_ajp_st_forward_request_sent; if (alcf->upstream.pass_request_body) { a->body = r->upstream->request_bufs; r->upstream->request_bufs = cl; cl->next = ajp_data_msg_send_body(r, alcf->max_ajp_data_packet_size_conf, &a->body); if (a->body) { a->state = ngx_http_ajp_st_request_body_data_sending; } else { a->state = ngx_http_ajp_st_request_send_all_done; } } else { a->state = ngx_http_ajp_st_request_send_all_done; r->upstream->request_bufs = cl; cl->next = NULL; } return NGX_OK; }
ngx_int_t ajp_data_msg_end(ajp_msg_t *msg, size_t len) { ngx_buf_t *buf; buf = msg->buf; buf->last = buf->start + AJP_HEADER_SZ; ajp_msg_end(msg); buf->start[AJP_HEADER_SZ - 2] = (u_char)((len >> 8) & 0xFF); buf->start[AJP_HEADER_SZ - 1] = (u_char)(len & 0xFF); /* len include AJP_HEADER_SIZE_LEN */ len += AJP_HEADER_SZ_LEN; buf->start[AJP_HEADER_LEN - 2] = (u_char)((len >> 8) & 0xFF); buf->start[AJP_HEADER_LEN - 1] = (u_char)(len & 0xFF); return NGX_OK; }