annotate src/http/modules/ngx_http_memcached_module.c @ 8031:d26db4f82d7d

All known output headers can be linked lists now. The h->next pointer properly provided as NULL in all cases where known output headers are added. Note that there are 3rd party modules which might not do this, and it might be risky to rely on this for arbitrary headers.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 30 May 2022 21:25:45 +0300
parents 7731c710796f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4121
diff changeset
4 * Copyright (C) Nginx, Inc.
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5 */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_config.h>
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_core.h>
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10 #include <ngx_http.h>
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 typedef struct {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14 ngx_http_upstream_conf_t upstream;
1076
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
15 ngx_int_t index;
4835
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
16 ngx_uint_t gzip_flag;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 } ngx_http_memcached_loc_conf_t;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20 typedef struct {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21 size_t rest;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 ngx_http_request_t *request;
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
23 ngx_str_t key;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 } ngx_http_memcached_ctx_t;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27 static ngx_int_t ngx_http_memcached_create_request(ngx_http_request_t *r);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28 static ngx_int_t ngx_http_memcached_reinit_request(ngx_http_request_t *r);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29 static ngx_int_t ngx_http_memcached_process_header(ngx_http_request_t *r);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30 static ngx_int_t ngx_http_memcached_filter_init(void *data);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 static ngx_int_t ngx_http_memcached_filter(void *data, ssize_t bytes);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 static void ngx_http_memcached_abort_request(ngx_http_request_t *r);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33 static void ngx_http_memcached_finalize_request(ngx_http_request_t *r,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 ngx_int_t rc);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36 static void *ngx_http_memcached_create_loc_conf(ngx_conf_t *cf);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37 static char *ngx_http_memcached_merge_loc_conf(ngx_conf_t *cf,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38 void *parent, void *child);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40 static char *ngx_http_memcached_pass(ngx_conf_t *cf, ngx_command_t *cmd,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 void *conf);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 static ngx_conf_bitmask_t ngx_http_memcached_next_upstream_masks[] = {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47 { ngx_string("invalid_response"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER },
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 { ngx_string("not_found"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
665
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
49 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50 { ngx_null_string, 0 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51 };
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
53
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
54 static ngx_command_t ngx_http_memcached_commands[] = {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56 { ngx_string("memcached_pass"),
1788
f10228d7ea06 allow memached_pass inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents: 1787
diff changeset
57 NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 ngx_http_memcached_pass,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 NGX_HTTP_LOC_CONF_OFFSET,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60 0,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61 NULL },
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62
3271
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3061
diff changeset
63 { ngx_string("memcached_bind"),
6530
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6480
diff changeset
64 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
3399
ac9c0380337d fix typo
Igor Sysoev <igor@sysoev.ru>
parents: 3271
diff changeset
65 ngx_http_upstream_bind_set_slot,
3271
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3061
diff changeset
66 NGX_HTTP_LOC_CONF_OFFSET,
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3061
diff changeset
67 offsetof(ngx_http_memcached_loc_conf_t, upstream.local),
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3061
diff changeset
68 NULL },
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3061
diff changeset
69
7371
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7321
diff changeset
70 { ngx_string("memcached_socket_keepalive"),
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7321
diff changeset
71 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7321
diff changeset
72 ngx_conf_set_flag_slot,
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7321
diff changeset
73 NGX_HTTP_LOC_CONF_OFFSET,
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7321
diff changeset
74 offsetof(ngx_http_memcached_loc_conf_t, upstream.socket_keepalive),
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7321
diff changeset
75 NULL },
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7321
diff changeset
76
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77 { ngx_string("memcached_connect_timeout"),
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 ngx_conf_set_msec_slot,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 NGX_HTTP_LOC_CONF_OFFSET,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81 offsetof(ngx_http_memcached_loc_conf_t, upstream.connect_timeout),
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 NULL },
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 { ngx_string("memcached_send_timeout"),
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 ngx_conf_set_msec_slot,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87 NGX_HTTP_LOC_CONF_OFFSET,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 offsetof(ngx_http_memcached_loc_conf_t, upstream.send_timeout),
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 NULL },
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 { ngx_string("memcached_buffer_size"),
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93 ngx_conf_set_size_slot,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 NGX_HTTP_LOC_CONF_OFFSET,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 offsetof(ngx_http_memcached_loc_conf_t, upstream.buffer_size),
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 NULL },
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 { ngx_string("memcached_read_timeout"),
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100 ngx_conf_set_msec_slot,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 NGX_HTTP_LOC_CONF_OFFSET,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102 offsetof(ngx_http_memcached_loc_conf_t, upstream.read_timeout),
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103 NULL },
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
104
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
105 { ngx_string("memcached_next_upstream"),
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107 ngx_conf_set_bitmask_slot,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108 NGX_HTTP_LOC_CONF_OFFSET,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
109 offsetof(ngx_http_memcached_loc_conf_t, upstream.next_upstream),
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110 &ngx_http_memcached_next_upstream_masks },
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111
5832
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
112 { ngx_string("memcached_next_upstream_tries"),
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
113 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
114 ngx_conf_set_num_slot,
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
115 NGX_HTTP_LOC_CONF_OFFSET,
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
116 offsetof(ngx_http_memcached_loc_conf_t, upstream.next_upstream_tries),
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
117 NULL },
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
118
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
119 { ngx_string("memcached_next_upstream_timeout"),
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
120 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
121 ngx_conf_set_msec_slot,
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
122 NGX_HTTP_LOC_CONF_OFFSET,
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
123 offsetof(ngx_http_memcached_loc_conf_t, upstream.next_upstream_timeout),
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
124 NULL },
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
125
4835
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
126 { ngx_string("memcached_gzip_flag"),
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
127 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
128 ngx_conf_set_num_slot,
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
129 NGX_HTTP_LOC_CONF_OFFSET,
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
130 offsetof(ngx_http_memcached_loc_conf_t, gzip_flag),
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
131 NULL },
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
132
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 ngx_null_command
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134 };
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 665
diff changeset
137 static ngx_http_module_t ngx_http_memcached_module_ctx = {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138 NULL, /* preconfiguration */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139 NULL, /* postconfiguration */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
141 NULL, /* create main configuration */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 NULL, /* init main configuration */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144 NULL, /* create server configuration */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 NULL, /* merge server configuration */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146
4499
778ef9c3fd2d Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
147 ngx_http_memcached_create_loc_conf, /* create location configuration */
778ef9c3fd2d Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
148 ngx_http_memcached_merge_loc_conf /* merge location configuration */
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149 };
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152 ngx_module_t ngx_http_memcached_module = {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153 NGX_MODULE_V1,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 &ngx_http_memcached_module_ctx, /* module context */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155 ngx_http_memcached_commands, /* module directives */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 NGX_HTTP_MODULE, /* module type */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157 NULL, /* init master */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158 NULL, /* init module */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159 NULL, /* init process */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160 NULL, /* init thread */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161 NULL, /* exit thread */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
162 NULL, /* exit process */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
163 NULL, /* exit master */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164 NGX_MODULE_V1_PADDING
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165 };
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167
1076
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
168 static ngx_str_t ngx_http_memcached_key = ngx_string("memcached_key");
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
169
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
170
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
171 #define NGX_HTTP_MEMCACHED_END (sizeof(ngx_http_memcached_end) - 1)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
172 static u_char ngx_http_memcached_end[] = CRLF "END" CRLF;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175 static ngx_int_t
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
176 ngx_http_memcached_handler(ngx_http_request_t *r)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178 ngx_int_t rc;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 ngx_http_upstream_t *u;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180 ngx_http_memcached_ctx_t *ctx;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 ngx_http_memcached_loc_conf_t *mlcf;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182
645
4946078f0a79 nginx-0.3.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
183 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184 return NGX_HTTP_NOT_ALLOWED;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186
1370
cc114c85be0f rename ngx_http_discard_body() to ngx_http_discard_request_body()
Igor Sysoev <igor@sysoev.ru>
parents: 1333
diff changeset
187 rc = ngx_http_discard_request_body(r);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188
1374
aabbf66b61ea omit unnecessary conditions
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
189 if (rc != NGX_OK) {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190 return rc;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193 if (ngx_http_set_content_type(r) != NGX_OK) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194 return NGX_HTTP_INTERNAL_SERVER_ERROR;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
195 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
196
3006
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
197 if (ngx_http_upstream_create(r) != NGX_OK) {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 return NGX_HTTP_INTERNAL_SERVER_ERROR;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200
3006
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
201 u = r->upstream;
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
202
3516
dd1570b6f237 ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents: 3487
diff changeset
203 ngx_str_set(&u->schema, "memcached://");
3006
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
204 u->output.tag = (ngx_buf_tag_t) &ngx_http_memcached_module;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205
3006
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
206 mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208 u->conf = &mlcf->upstream;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
209
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210 u->create_request = ngx_http_memcached_create_request;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211 u->reinit_request = ngx_http_memcached_reinit_request;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
212 u->process_header = ngx_http_memcached_process_header;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
213 u->abort_request = ngx_http_memcached_abort_request;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
214 u->finalize_request = ngx_http_memcached_finalize_request;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
216 ctx = ngx_palloc(r->pool, sizeof(ngx_http_memcached_ctx_t));
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
217 if (ctx == NULL) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218 return NGX_HTTP_INTERNAL_SERVER_ERROR;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
219 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221 ctx->request = r;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
222
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
223 ngx_http_set_ctx(r, ctx, ngx_http_memcached_module);
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
224
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
225 u->input_filter_init = ngx_http_memcached_filter_init;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
226 u->input_filter = ngx_http_memcached_filter;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
227 u->input_filter_ctx = ctx;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228
3061
f444f291ed38 fix request counter for memcached, introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3006
diff changeset
229 r->main->count++;
f444f291ed38 fix request counter for memcached, introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3006
diff changeset
230
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
231 ngx_http_upstream_init(r);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
232
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233 return NGX_DONE;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
235
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
236
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237 static ngx_int_t
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238 ngx_http_memcached_create_request(ngx_http_request_t *r)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239 {
1076
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
240 size_t len;
1333
07ebeeb55700 escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 1332
diff changeset
241 uintptr_t escape;
1076
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
242 ngx_buf_t *b;
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
243 ngx_chain_t *cl;
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
244 ngx_http_memcached_ctx_t *ctx;
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
245 ngx_http_variable_value_t *vv;
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
246 ngx_http_memcached_loc_conf_t *mlcf;
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
247
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
248 mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
249
1076
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
250 vv = ngx_http_get_indexed_variable(r, mlcf->index);
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
251
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
252 if (vv == NULL || vv->not_found || vv->len == 0) {
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
253 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
254 "the \"$memcached_key\" variable is not set");
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
255 return NGX_ERROR;
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
256 }
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
257
1333
07ebeeb55700 escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 1332
diff changeset
258 escape = 2 * ngx_escape_uri(NULL, vv->data, vv->len, NGX_ESCAPE_MEMCACHED);
07ebeeb55700 escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 1332
diff changeset
259
07ebeeb55700 escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 1332
diff changeset
260 len = sizeof("get ") - 1 + vv->len + escape + sizeof(CRLF) - 1;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
261
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
262 b = ngx_create_temp_buf(r->pool, len);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
263 if (b == NULL) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
264 return NGX_ERROR;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
265 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
266
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
267 cl = ngx_alloc_chain_link(r->pool);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
268 if (cl == NULL) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
269 return NGX_ERROR;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
270 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
271
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
272 cl->buf = b;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
273 cl->next = NULL;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
274
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
275 r->upstream->request_bufs = cl;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
276
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
277 *b->last++ = 'g'; *b->last++ = 'e'; *b->last++ = 't'; *b->last++ = ' ';
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
278
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
279 ctx = ngx_http_get_module_ctx(r, ngx_http_memcached_module);
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
280
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
281 ctx->key.data = b->last;
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
282
1333
07ebeeb55700 escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 1332
diff changeset
283 if (escape == 0) {
07ebeeb55700 escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 1332
diff changeset
284 b->last = ngx_copy(b->last, vv->data, vv->len);
07ebeeb55700 escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 1332
diff changeset
285
07ebeeb55700 escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 1332
diff changeset
286 } else {
07ebeeb55700 escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 1332
diff changeset
287 b->last = (u_char *) ngx_escape_uri(b->last, vv->data, vv->len,
07ebeeb55700 escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 1332
diff changeset
288 NGX_ESCAPE_MEMCACHED);
07ebeeb55700 escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 1332
diff changeset
289 }
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
290
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
291 ctx->key.len = b->last - ctx->key.data;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
292
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
293 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
294 "http memcached request: \"%V\"", &ctx->key);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
295
1088
2d8e72584534 eliminate the useless space symbol
Igor Sysoev <igor@sysoev.ru>
parents: 1076
diff changeset
296 *b->last++ = CR; *b->last++ = LF;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
297
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
298 return NGX_OK;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
299 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
300
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
301
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
302 static ngx_int_t
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
303 ngx_http_memcached_reinit_request(ngx_http_request_t *r)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
304 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
305 return NGX_OK;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
306 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
307
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
308
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
309 static ngx_int_t
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
310 ngx_http_memcached_process_header(ngx_http_request_t *r)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
311 {
4835
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
312 u_char *p, *start;
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
313 ngx_str_t line;
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
314 ngx_uint_t flags;
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
315 ngx_table_elt_t *h;
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
316 ngx_http_upstream_t *u;
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
317 ngx_http_memcached_ctx_t *ctx;
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
318 ngx_http_memcached_loc_conf_t *mlcf;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
319
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
320 u = r->upstream;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
321
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
322 for (p = u->buffer.pos; p < u->buffer.last; p++) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
323 if (*p == LF) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
324 goto found;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
325 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
326 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
327
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
328 return NGX_AGAIN;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
329
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
330 found:
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
331
5226
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
332 line.data = u->buffer.pos;
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
333 line.len = p - u->buffer.pos;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
334
5226
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
335 if (line.len == 0 || *(p - 1) != CR) {
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
336 goto no_valid;
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
337 }
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
338
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
339 *p = '\0';
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
340 line.len--;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
341
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
342 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
343 "memcached: \"%V\"", &line);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
344
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
345 p = u->buffer.pos;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
346
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
347 ctx = ngx_http_get_module_ctx(r, ngx_http_memcached_module);
4835
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
348 mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module);
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
349
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
350 if (ngx_strncmp(p, "VALUE ", sizeof("VALUE ") - 1) == 0) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
351
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
352 p += sizeof("VALUE ") - 1;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
353
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
354 if (ngx_strncmp(p, ctx->key.data, ctx->key.len) != 0) {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
355 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
356 "memcached sent invalid key in response \"%V\" "
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
357 "for key \"%V\"",
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
358 &line, &ctx->key);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
359
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
360 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
361 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
362
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
363 p += ctx->key.len;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
364
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
365 if (*p++ != ' ') {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
366 goto no_valid;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
367 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
368
4835
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
369 /* flags */
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
370
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
371 start = p;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
372
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
373 while (*p) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
374 if (*p++ == ' ') {
4835
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
375 if (mlcf->gzip_flag) {
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
376 goto flags;
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
377 } else {
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
378 goto length;
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
379 }
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
380 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
381 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
382
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
383 goto no_valid;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
384
4835
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
385 flags:
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
386
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
387 flags = ngx_atoi(start, p - start - 1);
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
388
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
389 if (flags == (ngx_uint_t) NGX_ERROR) {
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
390 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
391 "memcached sent invalid flags in response \"%V\" "
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
392 "for key \"%V\"",
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
393 &line, &ctx->key);
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
394 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
395 }
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
396
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
397 if (flags & mlcf->gzip_flag) {
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
398 h = ngx_list_push(&r->headers_out.headers);
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
399 if (h == NULL) {
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
400 return NGX_ERROR;
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
401 }
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
402
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
403 h->hash = 1;
8031
d26db4f82d7d All known output headers can be linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7674
diff changeset
404 h->next = NULL;
5765
d80543940f9a Style: use ngx_str_set().
Tatsuhiko Kubo <cubicdaiya@gmail.com>
parents: 5359
diff changeset
405 ngx_str_set(&h->key, "Content-Encoding");
d80543940f9a Style: use ngx_str_set().
Tatsuhiko Kubo <cubicdaiya@gmail.com>
parents: 5359
diff changeset
406 ngx_str_set(&h->value, "gzip");
4835
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
407 r->headers_out.content_encoding = h;
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
408 }
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
409
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
410 length:
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
411
4835
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
412 start = p;
5226
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
413 p = line.data + line.len;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
414
5226
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
415 u->headers_in.content_length_n = ngx_atoof(start, p - start);
5801
ab48149b77a6 Style: use specified macro instead of magic-number.
Tatsuhiko Kubo <cubicdaiya@gmail.com>
parents: 5765
diff changeset
416 if (u->headers_in.content_length_n == NGX_ERROR) {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
417 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
418 "memcached sent invalid length in response \"%V\" "
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
419 "for key \"%V\"",
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
420 &line, &ctx->key);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
421 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
422 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
423
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
424 u->headers_in.status_n = 200;
1567
31d4278d51c0 memcached did not set $upstream_response_time
Igor Sysoev <igor@sysoev.ru>
parents: 1554
diff changeset
425 u->state->status = 200;
5226
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
426 u->buffer.pos = p + sizeof(CRLF) - 1;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
427
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
428 return NGX_OK;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
429 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
430
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
431 if (ngx_strcmp(p, "END\x0d") == 0) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
432 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
433 "key: \"%V\" was not found by memcached", &ctx->key);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
434
5226
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
435 u->headers_in.content_length_n = 0;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
436 u->headers_in.status_n = 404;
1567
31d4278d51c0 memcached did not set $upstream_response_time
Igor Sysoev <igor@sysoev.ru>
parents: 1554
diff changeset
437 u->state->status = 404;
5226
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
438 u->buffer.pos = p + sizeof("END" CRLF) - 1;
4121
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
439 u->keepalive = 1;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
440
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
441 return NGX_OK;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
442 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
443
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
444 no_valid:
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
445
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
446 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
447 "memcached sent invalid response: \"%V\"", &line);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
448
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
449 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
450 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
451
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
452
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
453 static ngx_int_t
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
454 ngx_http_memcached_filter_init(void *data)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
455 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
456 ngx_http_memcached_ctx_t *ctx = data;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
457
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
458 ngx_http_upstream_t *u;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
459
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
460 u = ctx->request->upstream;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
461
5226
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
462 if (u->headers_in.status_n != 404) {
5300
f538a67c9f77 Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5226
diff changeset
463 u->length = u->headers_in.content_length_n + NGX_HTTP_MEMCACHED_END;
5226
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
464 ctx->rest = NGX_HTTP_MEMCACHED_END;
5300
f538a67c9f77 Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5226
diff changeset
465
f538a67c9f77 Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5226
diff changeset
466 } else {
f538a67c9f77 Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5226
diff changeset
467 u->length = 0;
5226
a30ea5c6451d Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents: 5008
diff changeset
468 }
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
469
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
470 return NGX_OK;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
471 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
472
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
473
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
474 static ngx_int_t
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
475 ngx_http_memcached_filter(void *data, ssize_t bytes)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
476 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
477 ngx_http_memcached_ctx_t *ctx = data;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
478
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
479 u_char *last;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
480 ngx_buf_t *b;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
481 ngx_chain_t *cl, **ll;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
482 ngx_http_upstream_t *u;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
483
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
484 u = ctx->request->upstream;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
485 b = &u->buffer;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
486
4118
dbddec65fdab Upstream: r->upstream->length type change to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4117
diff changeset
487 if (u->length == (ssize_t) ctx->rest) {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
488
7674
7731c710796f Memcached: protect from too long responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7371
diff changeset
489 if (bytes > u->length
7731c710796f Memcached: protect from too long responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7371
diff changeset
490 || ngx_strncmp(b->last,
1548
a83aa8c53552 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 1374
diff changeset
491 ngx_http_memcached_end + NGX_HTTP_MEMCACHED_END - ctx->rest,
3487
5d2acf153153 revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents: 3399
diff changeset
492 bytes)
7674
7731c710796f Memcached: protect from too long responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7371
diff changeset
493 != 0)
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
494 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
495 ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
496 "memcached sent invalid trailer");
3487
5d2acf153153 revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents: 3399
diff changeset
497
5d2acf153153 revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents: 3399
diff changeset
498 u->length = 0;
5d2acf153153 revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents: 3399
diff changeset
499 ctx->rest = 0;
5d2acf153153 revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents: 3399
diff changeset
500
5d2acf153153 revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents: 3399
diff changeset
501 return NGX_OK;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
502 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
503
3487
5d2acf153153 revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents: 3399
diff changeset
504 u->length -= bytes;
5d2acf153153 revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents: 3399
diff changeset
505 ctx->rest -= bytes;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
506
4121
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
507 if (u->length == 0) {
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
508 u->keepalive = 1;
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
509 }
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
510
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
511 return NGX_OK;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
512 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
513
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
514 for (cl = u->out_bufs, ll = &u->out_bufs; cl; cl = cl->next) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
515 ll = &cl->next;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
516 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
517
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
518 cl = ngx_chain_get_free_buf(ctx->request->pool, &u->free_bufs);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
519 if (cl == NULL) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
520 return NGX_ERROR;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
521 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
522
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
523 cl->buf->flush = 1;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
524 cl->buf->memory = 1;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
525
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
526 *ll = cl;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
527
1554
30fcc8478d85 two commits those go together by mistake
Igor Sysoev <igor@sysoev.ru>
parents: 1548
diff changeset
528 last = b->last;
30fcc8478d85 two commits those go together by mistake
Igor Sysoev <igor@sysoev.ru>
parents: 1548
diff changeset
529 cl->buf->pos = last;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
530 b->last += bytes;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
531 cl->buf->last = b->last;
1908
f2953601ed3c fix memory leak in long-lived non buffered connections
Igor Sysoev <igor@sysoev.ru>
parents: 1788
diff changeset
532 cl->buf->tag = u->output.tag;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
533
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
534 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
6480
f01ab2dbcfdc Fixed logging.
Sergey Kandaurov <pluknet@nginx.com>
parents: 6122
diff changeset
535 "memcached filter bytes:%z size:%z length:%O rest:%z",
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
536 bytes, b->last - b->pos, u->length, ctx->rest);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
537
1554
30fcc8478d85 two commits those go together by mistake
Igor Sysoev <igor@sysoev.ru>
parents: 1548
diff changeset
538 if (bytes <= (ssize_t) (u->length - NGX_HTTP_MEMCACHED_END)) {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
539 u->length -= bytes;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
540 return NGX_OK;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
541 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
542
5359
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
543 last += (size_t) (u->length - NGX_HTTP_MEMCACHED_END);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
544
7674
7731c710796f Memcached: protect from too long responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7371
diff changeset
545 if (bytes > u->length
7731c710796f Memcached: protect from too long responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7371
diff changeset
546 || ngx_strncmp(last, ngx_http_memcached_end, b->last - last) != 0)
7731c710796f Memcached: protect from too long responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7371
diff changeset
547 {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
548 ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
549 "memcached sent invalid trailer");
4121
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
550
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
551 b->last = last;
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
552 cl->buf->last = last;
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
553 u->length = 0;
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
554 ctx->rest = 0;
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
555
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
556 return NGX_OK;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
557 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
558
1554
30fcc8478d85 two commits those go together by mistake
Igor Sysoev <igor@sysoev.ru>
parents: 1548
diff changeset
559 ctx->rest -= b->last - last;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
560 b->last = last;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
561 cl->buf->last = last;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
562 u->length = ctx->rest;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
563
4121
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
564 if (u->length == 0) {
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
565 u->keepalive = 1;
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
566 }
16c60162c35b Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
567
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
568 return NGX_OK;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
569 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
570
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
571
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
572 static void
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
573 ngx_http_memcached_abort_request(ngx_http_request_t *r)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
574 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
575 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
576 "abort http memcached request");
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
577 return;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
578 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
579
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
580
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
581 static void
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
582 ngx_http_memcached_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
583 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
584 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
585 "finalize http memcached request");
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
586 return;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
587 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
588
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
589
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
590 static void *
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
591 ngx_http_memcached_create_loc_conf(ngx_conf_t *cf)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
592 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
593 ngx_http_memcached_loc_conf_t *conf;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
594
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
595 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_memcached_loc_conf_t));
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
596 if (conf == NULL) {
2912
c7d57b539248 return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents: 2392
diff changeset
597 return NULL;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
598 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
599
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
600 /*
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
601 * set by ngx_pcalloc():
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
602 *
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
603 * conf->upstream.bufs.num = 0;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
604 * conf->upstream.next_upstream = 0;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
605 * conf->upstream.temp_path = NULL;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
606 */
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
607
5008
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 4835
diff changeset
608 conf->upstream.local = NGX_CONF_UNSET_PTR;
7371
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7321
diff changeset
609 conf->upstream.socket_keepalive = NGX_CONF_UNSET;
5832
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
610 conf->upstream.next_upstream_tries = NGX_CONF_UNSET_UINT;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
611 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
612 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
613 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC;
5832
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
614 conf->upstream.next_upstream_timeout = NGX_CONF_UNSET_MSEC;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
615
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
616 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
617
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 815
diff changeset
618 /* the hardcoded values */
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
619 conf->upstream.cyclic_temp_file = 0;
629
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 597
diff changeset
620 conf->upstream.buffering = 0;
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 597
diff changeset
621 conf->upstream.ignore_client_abort = 0;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
622 conf->upstream.send_lowat = 0;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
623 conf->upstream.bufs.num = 0;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
624 conf->upstream.busy_buffers_size = 0;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
625 conf->upstream.max_temp_file_size = 0;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
626 conf->upstream.temp_file_write_size = 0;
657
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
627 conf->upstream.intercept_errors = 1;
675
e924670896ab nginx-0.3.59-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 667
diff changeset
628 conf->upstream.intercept_404 = 1;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
629 conf->upstream.pass_request_headers = 0;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
630 conf->upstream.pass_request_body = 0;
6122
85f00678e54a Memcached: enabled ranges.
Martin Mlynář <nexus@smoula.net>
parents: 5832
diff changeset
631 conf->upstream.force_ranges = 1;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
632
1787
a37fe5ceacc4 inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents: 1658
diff changeset
633 conf->index = NGX_CONF_UNSET;
4835
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
634 conf->gzip_flag = NGX_CONF_UNSET_UINT;
1787
a37fe5ceacc4 inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents: 1658
diff changeset
635
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
636 return conf;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
637 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
638
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
639
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
640 static char *
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
641 ngx_http_memcached_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
642 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
643 ngx_http_memcached_loc_conf_t *prev = parent;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
644 ngx_http_memcached_loc_conf_t *conf = child;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
645
5008
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 4835
diff changeset
646 ngx_conf_merge_ptr_value(conf->upstream.local,
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 4835
diff changeset
647 prev->upstream.local, NULL);
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 4835
diff changeset
648
7371
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7321
diff changeset
649 ngx_conf_merge_value(conf->upstream.socket_keepalive,
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7321
diff changeset
650 prev->upstream.socket_keepalive, 0);
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7321
diff changeset
651
5832
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
652 ngx_conf_merge_uint_value(conf->upstream.next_upstream_tries,
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
653 prev->upstream.next_upstream_tries, 0);
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
654
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
655 ngx_conf_merge_msec_value(conf->upstream.connect_timeout,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
656 prev->upstream.connect_timeout, 60000);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
657
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
658 ngx_conf_merge_msec_value(conf->upstream.send_timeout,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
659 prev->upstream.send_timeout, 60000);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
660
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
661 ngx_conf_merge_msec_value(conf->upstream.read_timeout,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
662 prev->upstream.read_timeout, 60000);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
663
5832
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
664 ngx_conf_merge_msec_value(conf->upstream.next_upstream_timeout,
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
665 prev->upstream.next_upstream_timeout, 0);
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5801
diff changeset
666
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
667 ngx_conf_merge_size_value(conf->upstream.buffer_size,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
668 prev->upstream.buffer_size,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
669 (size_t) ngx_pagesize);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
670
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
671 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
672 prev->upstream.next_upstream,
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
673 (NGX_CONF_BITMASK_SET
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
674 |NGX_HTTP_UPSTREAM_FT_ERROR
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
675 |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
676
665
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
677 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) {
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
678 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
679 |NGX_HTTP_UPSTREAM_FT_OFF;
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
680 }
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
681
1787
a37fe5ceacc4 inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents: 1658
diff changeset
682 if (conf->upstream.upstream == NULL) {
a37fe5ceacc4 inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents: 1658
diff changeset
683 conf->upstream.upstream = prev->upstream.upstream;
a37fe5ceacc4 inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents: 1658
diff changeset
684 }
a37fe5ceacc4 inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents: 1658
diff changeset
685
a37fe5ceacc4 inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents: 1658
diff changeset
686 if (conf->index == NGX_CONF_UNSET) {
a37fe5ceacc4 inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents: 1658
diff changeset
687 conf->index = prev->index;
a37fe5ceacc4 inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents: 1658
diff changeset
688 }
a37fe5ceacc4 inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents: 1658
diff changeset
689
4835
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
690 ngx_conf_merge_uint_value(conf->gzip_flag, prev->gzip_flag, 0);
a4512d7737f6 Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4499
diff changeset
691
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
692 return NGX_CONF_OK;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
693 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
694
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
695
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
696 static char *
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
697 ngx_http_memcached_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
698 {
2392
3530e5bd4826 change variable name
Igor Sysoev <igor@sysoev.ru>
parents: 2391
diff changeset
699 ngx_http_memcached_loc_conf_t *mlcf = conf;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
700
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
701 ngx_str_t *value;
807
3095bf59059b now the "memcached_pass" directive uses ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents: 675
diff changeset
702 ngx_url_t u;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
703 ngx_http_core_loc_conf_t *clcf;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
704
2392
3530e5bd4826 change variable name
Igor Sysoev <igor@sysoev.ru>
parents: 2391
diff changeset
705 if (mlcf->upstream.upstream) {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
706 return "is duplicate";
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
707 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
708
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
709 value = cf->args->elts;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
710
807
3095bf59059b now the "memcached_pass" directive uses ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents: 675
diff changeset
711 ngx_memzero(&u, sizeof(ngx_url_t));
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
712
807
3095bf59059b now the "memcached_pass" directive uses ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents: 675
diff changeset
713 u.url = value[1];
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 815
diff changeset
714 u.no_resolve = 1;
815
b630109560b7 style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents: 807
diff changeset
715
2392
3530e5bd4826 change variable name
Igor Sysoev <igor@sysoev.ru>
parents: 2391
diff changeset
716 mlcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
3530e5bd4826 change variable name
Igor Sysoev <igor@sysoev.ru>
parents: 2391
diff changeset
717 if (mlcf->upstream.upstream == NULL) {
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 815
diff changeset
718 return NGX_CONF_ERROR;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
719 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
720
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
721 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
722
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
723 clcf->handler = ngx_http_memcached_handler;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
724
7321
45e513c3540d Fixed invalid access to location defined as an empty string.
Ruslan Ermilov <ru@nginx.com>
parents: 7238
diff changeset
725 if (clcf->name.len && clcf->name.data[clcf->name.len - 1] == '/') {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
726 clcf->auto_redirect = 1;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
727 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
728
2392
3530e5bd4826 change variable name
Igor Sysoev <igor@sysoev.ru>
parents: 2391
diff changeset
729 mlcf->index = ngx_http_get_variable_index(cf, &ngx_http_memcached_key);
1076
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
730
2392
3530e5bd4826 change variable name
Igor Sysoev <igor@sysoev.ru>
parents: 2391
diff changeset
731 if (mlcf->index == NGX_ERROR) {
1076
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
732 return NGX_CONF_ERROR;
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
733 }
2deb6d858c53 $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
734
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
735 return NGX_CONF_OK;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
736 }