comparison src/http/ngx_http_header_filter.c @ 10:4f3879d9b6f6

nginx-0.0.1-2002-09-11-19:18:33 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 11 Sep 2002 15:18:33 +0000
parents src/http/modules/ngx_http_header_filter.c@708f8bb772ec
children 2aba961a1d34
comparison
equal deleted inserted replaced
9:6f58641241bb 10:4f3879d9b6f6
1
2 #include <nginx.h>
3
4 #include <ngx_config.h>
5 #include <ngx_core.h>
6 #include <ngx_string.h>
7 #include <ngx_hunk.h>
8 #include <ngx_http.h>
9
10
11 typedef struct {
12 int len;
13 char *line;
14 } line;
15
16
17 static line http_codes[] = {
18 { 6, "200 OK" }
19 };
20
21
22
23 int ngx_http_header_filter(ngx_http_request_t *r)
24 {
25 int status;
26 ngx_hunk_t *h;
27 ngx_chain_t *ch;
28
29 ngx_test_null(h, ngx_create_temp_hunk(r->pool, 1024, 0, 64),
30 NGX_ERROR);
31
32 status = r->headers_out->status - NGX_HTTP_OK;
33
34 ngx_memcpy(h->last.mem, "HTTP/1.0 ", 9);
35 h->last.mem += 9;
36 ngx_memcpy(h->last.mem, http_codes[status].line, http_codes[status].len);
37 h->last.mem += http_codes[status].len;
38 *(h->last.mem++) = CR; *(h->last.mem++) = LF;
39
40 /*
41 memcpy(h->last.mem, "Date: ", 6);
42 h->last.mem += 6;
43 h->last.mem += ngx_http_get_time(h->last.mem, time(NULL));
44 *(h->last.mem++) = CR; *(h->last.mem++) = LF;
45 */
46
47 /* 2^64 is 20 characters */
48 if (r->headers_out->content_length)
49 h->last.mem += ngx_snprintf(h->last.mem, 49, "Content-Length: %d" CRLF,
50 r->headers_out->content_length);
51
52 /* check */
53
54 memcpy(h->last.mem, "Server: ", 8);
55 h->last.mem += 8;
56 if (r->headers_out->server) {
57 h->last.mem = ngx_cpystrn(h->last.mem, r->headers_out->server,
58 h->end - h->last.mem);
59
60 /* check space */
61
62 } else {
63 ngx_memcpy(h->last.mem, NGINX_VER, sizeof(NGINX_VER));
64 h->last.mem += sizeof(NGINX_VER);
65 }
66 *(h->last.mem++) = CR; *(h->last.mem++) = LF;
67
68 /* end of HTTP header */
69 *(h->last.mem++) = CR; *(h->last.mem++) = LF;
70
71 ngx_test_null(ch, ngx_palloc(r->pool, sizeof(ngx_chain_t)),
72 /* STUB */
73 -1);
74 /*
75 NGX_HTTP_FILTER_ERROR);
76 */
77
78 ch->hunk = h;
79 ch->next = NULL;
80
81 return ngx_http_write_filter(r, ch);
82 }