Mercurial > hg > nginx
comparison src/imap/ngx_imap_auth_http_module.c @ 525:09b42134ac0c release-0.1.37
nginx-0.1.37-RELEASE import
*) Change: now the "\n" is added to the end of the "nginx.pid" file.
*) Bugfix: the responses may be transferred not completely, if many
parts or the big parts were included by SSI.
*) Bugfix: if all backends had returned the 404 reponse and the
"http_404" parameter of the "proxy_next_upstream" or
"fastcgi_next_upstream" directives was used, then nginx started to
request all backends again.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 23 Jun 2005 13:41:06 +0000 |
parents | 6f00349b98e5 |
children | 7fa11e5c6e96 |
comparison
equal
deleted
inserted
replaced
524:a55bc21dee27 | 525:09b42134ac0c |
---|---|
21 } ngx_imap_auth_http_conf_t; | 21 } ngx_imap_auth_http_conf_t; |
22 | 22 |
23 | 23 |
24 typedef struct { | 24 typedef struct { |
25 ngx_buf_t *request; | 25 ngx_buf_t *request; |
26 ngx_buf_t *response; | |
26 ngx_peer_connection_t peer; | 27 ngx_peer_connection_t peer; |
27 } ngx_imap_auth_http_ctx_t; | 28 } ngx_imap_auth_http_ctx_t; |
28 | 29 |
29 | 30 |
30 static void ngx_imap_auth_http_write_handler(ngx_event_t *wev); | 31 static void ngx_imap_auth_http_write_handler(ngx_event_t *wev); |
89 ngx_imap_auth_http_ctx_t *ctx; | 90 ngx_imap_auth_http_ctx_t *ctx; |
90 ngx_imap_auth_http_conf_t *ahcf; | 91 ngx_imap_auth_http_conf_t *ahcf; |
91 | 92 |
92 ctx = ngx_pcalloc(s->connection->pool, sizeof(ngx_imap_auth_http_ctx_t)); | 93 ctx = ngx_pcalloc(s->connection->pool, sizeof(ngx_imap_auth_http_ctx_t)); |
93 if (ctx == NULL) { | 94 if (ctx == NULL) { |
94 ngx_imap_close_connection(s->connection); | 95 ngx_imap_session_internal_server_error(s); |
95 return; | 96 return; |
96 } | 97 } |
97 | 98 |
98 ahcf = ngx_imap_get_module_srv_conf(s, ngx_imap_auth_http_module); | 99 ahcf = ngx_imap_get_module_srv_conf(s, ngx_imap_auth_http_module); |
99 | 100 |
100 ctx->request = ngx_imap_auth_http_create_request(s, ahcf); | 101 ctx->request = ngx_imap_auth_http_create_request(s, ahcf); |
101 if (ctx->request == NULL) { | 102 if (ctx->request == NULL) { |
102 ngx_imap_close_connection(s->connection); | 103 ngx_imap_session_internal_server_error(s); |
103 return; | 104 return; |
104 } | 105 } |
105 | 106 |
106 ngx_imap_set_ctx(s, ctx, ngx_imap_auth_http_module); | 107 ngx_imap_set_ctx(s, ctx, ngx_imap_auth_http_module); |
107 | 108 |
110 ctx->peer.log_error = NGX_ERROR_ERR; | 111 ctx->peer.log_error = NGX_ERROR_ERR; |
111 | 112 |
112 rc = ngx_event_connect_peer(&ctx->peer); | 113 rc = ngx_event_connect_peer(&ctx->peer); |
113 | 114 |
114 if (rc == NGX_ERROR) { | 115 if (rc == NGX_ERROR) { |
115 ngx_imap_close_connection(s->connection); | 116 ngx_imap_session_internal_server_error(s); |
116 return; | 117 return; |
117 } | 118 } |
118 | 119 |
119 ctx->peer.connection->data = s; | 120 ctx->peer.connection->data = s; |
120 ctx->peer.connection->pool = s->connection->pool; | 121 ctx->peer.connection->pool = s->connection->pool; |
151 "imap auth http write handler"); | 152 "imap auth http write handler"); |
152 | 153 |
153 if (wev->timedout) { | 154 if (wev->timedout) { |
154 ngx_log_error(NGX_LOG_ERR, wev->log, NGX_ETIMEDOUT, | 155 ngx_log_error(NGX_LOG_ERR, wev->log, NGX_ETIMEDOUT, |
155 "auth http server timed out"); | 156 "auth http server timed out"); |
156 ngx_imap_close_connection(ctx->peer.connection); | 157 ngx_close_connection(ctx->peer.connection); |
157 ngx_imap_close_connection(s->connection); | 158 ngx_imap_session_internal_server_error(s); |
158 return; | 159 return; |
159 } | 160 } |
160 | 161 |
161 size = ctx->request->last - ctx->request->pos; | 162 size = ctx->request->last - ctx->request->pos; |
162 | 163 |
163 n = ngx_send(c, ctx->request->pos, size); | 164 n = ngx_send(c, ctx->request->pos, size); |
164 | 165 |
165 if (n == NGX_ERROR) { | 166 if (n == NGX_ERROR) { |
166 ngx_imap_close_connection(ctx->peer.connection); | 167 ngx_close_connection(ctx->peer.connection); |
167 ngx_imap_close_connection(s->connection); | 168 ngx_imap_session_internal_server_error(s); |
168 return; | 169 return; |
169 } | 170 } |
170 | 171 |
171 if (n > 0) { | 172 if (n > 0) { |
172 ctx->request->pos += n; | 173 ctx->request->pos += n; |
190 | 191 |
191 | 192 |
192 static void | 193 static void |
193 ngx_imap_auth_http_read_handler(ngx_event_t *rev) | 194 ngx_imap_auth_http_read_handler(ngx_event_t *rev) |
194 { | 195 { |
196 ssize_t n, size; | |
195 ngx_peers_t *peers; | 197 ngx_peers_t *peers; |
196 ngx_connection_t *c; | 198 ngx_connection_t *c; |
197 ngx_imap_session_t *s; | 199 ngx_imap_session_t *s; |
198 #if 0 | |
199 ngx_imap_auth_http_ctx_t *ctx; | 200 ngx_imap_auth_http_ctx_t *ctx; |
200 #endif | |
201 | 201 |
202 c = rev->data; | 202 c = rev->data; |
203 s = c->data; | 203 s = c->data; |
204 | 204 |
205 #if 0 | |
206 ctx = ngx_imap_get_module_ctx(s, ngx_imap_auth_http_module); | |
207 #endif | |
208 | |
209 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, | 205 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, |
210 "imap auth http read handler"); | 206 "imap auth http read handler"); |
207 | |
208 ctx = ngx_imap_get_module_ctx(s, ngx_imap_auth_http_module); | |
209 | |
210 if (rev->timedout) { | |
211 ngx_log_error(NGX_LOG_ERR, rev->log, NGX_ETIMEDOUT, | |
212 "auth http server timed out"); | |
213 ngx_close_connection(ctx->peer.connection); | |
214 ngx_imap_session_internal_server_error(s); | |
215 return; | |
216 } | |
217 | |
218 if (ctx->response == NULL) { | |
219 ctx->response = ngx_create_temp_buf(s->connection->pool, 1024); | |
220 if (ctx->response == NULL) { | |
221 ngx_close_connection(ctx->peer.connection); | |
222 ngx_imap_session_internal_server_error(s); | |
223 return; | |
224 } | |
225 } | |
226 | |
227 size = ctx->response->last - ctx->response->pos; | |
228 | |
229 n = ngx_recv(c, ctx->response->pos, size); | |
230 | |
231 if (n == NGX_ERROR || n == 0) { | |
232 ngx_close_connection(ctx->peer.connection); | |
233 ngx_imap_session_internal_server_error(s); | |
234 return; | |
235 } | |
236 | |
237 | |
238 | |
239 | |
240 | |
211 | 241 |
212 peers = NULL; | 242 peers = NULL; |
213 | 243 |
214 ngx_imap_proxy_init(s, peers); | 244 ngx_imap_proxy_init(s, peers); |
215 } | 245 } |
229 c = rev->data; | 259 c = rev->data; |
230 s = c->data; | 260 s = c->data; |
231 | 261 |
232 ctx = ngx_imap_get_module_ctx(s, ngx_imap_auth_http_module); | 262 ctx = ngx_imap_get_module_ctx(s, ngx_imap_auth_http_module); |
233 | 263 |
234 ngx_imap_close_connection(ctx->peer.connection); | 264 ngx_close_connection(ctx->peer.connection); |
235 ngx_imap_close_connection(s->connection); | 265 ngx_imap_session_internal_server_error(s); |
236 } | 266 } |
237 } | 267 } |
238 | 268 |
239 | 269 |
240 static void | 270 static void |