Welcome! Log In Create A New Profile

Advanced

Re: Several requests in one connection

November 02, 2011 09:06AM
Код взят отсюда практически без изменений
http://nutrun.com/weblog/2009/08/15/hello-world-nginx-module.html

static void
body_handler(ngx_http_request_t *r)
{
}

static ngx_int_t
ngx_handler(ngx_http_request_t *r)
{
ngx_int_t rc;
ngx_buf_t *b;
ngx_chain_t out;

if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD|NGX_HTTP_POST))) {
return NGX_HTTP_NOT_ALLOWED;
}

// rc = ngx_http_discard_request_body(r);
rc = ngx_http_read_client_request_body(r, body_handler);

if (rc != NGX_OK) {
return rc;
}

/* set the 'Content-type' header */
r->headers_out.content_type_len = sizeof("text/html") - 1;
r->headers_out.content_type.len = sizeof("text/html") - 1;
r->headers_out.content_type.data = (u_char *) "text/html";

/* send the header only, if the request type is http 'HEAD' */
if (r->method == NGX_HTTP_HEAD) {
r->headers_out.status = NGX_HTTP_OK;
r->headers_out.content_length_n = sizeof(ngx_hello_world) - 1;

return ngx_http_send_header(r);
}

/* allocate a buffer for your response body */
b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
if (b == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

/* attach this buffer to the buffer chain */
out.buf = b;
out.next = NULL;

b->pos = ngx_hello_world;
b->last = ngx_hello_world + sizeof(ngx_hello_world) - 1;
b->memory = 1; /* this buffer is in memory */
b->last_buf = 1; /* this is the last buffer in the buffer chain */

/* set the status line */
r->headers_out.status = NGX_HTTP_OK;
r->headers_out.content_length_n = sizeof(ngx_hello_world) - 1;

/* send the headers of your response */
rc = ngx_http_send_header(r);

if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
return rc;
}

/* send the buffer chain of your response */
return ngx_http_output_filter(r, &out);
}
Subject Author Posted

Several requests in one connection

amikish November 02, 2011 05:20AM

Re: Several requests in one connection

Rush November 02, 2011 08:34AM

Re: Several requests in one connection

amikish November 02, 2011 09:06AM

Re: Several requests in one connection

Maxim Dounin November 02, 2011 09:16AM

Re: Several requests in one connection

amikish November 08, 2011 02:33AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 204
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready