diff 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
line wrap: on
line diff
--- a/src/imap/ngx_imap_auth_http_module.c
+++ b/src/imap/ngx_imap_auth_http_module.c
@@ -23,6 +23,7 @@ typedef struct {
 
 typedef struct {
     ngx_buf_t              *request;
+    ngx_buf_t              *response;
     ngx_peer_connection_t   peer;
 } ngx_imap_auth_http_ctx_t;
 
@@ -91,7 +92,7 @@ ngx_imap_auth_http_init(ngx_imap_session
 
     ctx = ngx_pcalloc(s->connection->pool, sizeof(ngx_imap_auth_http_ctx_t));
     if (ctx == NULL) {
-        ngx_imap_close_connection(s->connection);
+        ngx_imap_session_internal_server_error(s);
         return;
     }
 
@@ -99,7 +100,7 @@ ngx_imap_auth_http_init(ngx_imap_session
 
     ctx->request = ngx_imap_auth_http_create_request(s, ahcf);
     if (ctx->request == NULL) {
-        ngx_imap_close_connection(s->connection);
+        ngx_imap_session_internal_server_error(s);
         return;
     }
 
@@ -112,7 +113,7 @@ ngx_imap_auth_http_init(ngx_imap_session
     rc = ngx_event_connect_peer(&ctx->peer);
 
     if (rc == NGX_ERROR) {
-        ngx_imap_close_connection(s->connection);
+        ngx_imap_session_internal_server_error(s);
         return;
     }
 
@@ -153,8 +154,8 @@ ngx_imap_auth_http_write_handler(ngx_eve
     if (wev->timedout) {  
         ngx_log_error(NGX_LOG_ERR, wev->log, NGX_ETIMEDOUT,
                       "auth http server timed out");
-        ngx_imap_close_connection(ctx->peer.connection);
-        ngx_imap_close_connection(s->connection);
+        ngx_close_connection(ctx->peer.connection);
+        ngx_imap_session_internal_server_error(s);
         return;
     }
 
@@ -163,8 +164,8 @@ ngx_imap_auth_http_write_handler(ngx_eve
     n = ngx_send(c, ctx->request->pos, size);
 
     if (n == NGX_ERROR) {
-        ngx_imap_close_connection(ctx->peer.connection);
-        ngx_imap_close_connection(s->connection);
+        ngx_close_connection(ctx->peer.connection);
+        ngx_imap_session_internal_server_error(s);
         return;
     }
 
@@ -192,23 +193,52 @@ ngx_imap_auth_http_write_handler(ngx_eve
 static void
 ngx_imap_auth_http_read_handler(ngx_event_t *rev)
 {
+    ssize_t                     n, size;
     ngx_peers_t                *peers;
     ngx_connection_t          *c;
     ngx_imap_session_t        *s;
-#if 0
     ngx_imap_auth_http_ctx_t  *ctx;
-#endif
 
     c = rev->data;
     s = c->data;
 
-#if 0
-    ctx = ngx_imap_get_module_ctx(s, ngx_imap_auth_http_module);
-#endif
-
     ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0,
                    "imap auth http read handler");
 
+    ctx = ngx_imap_get_module_ctx(s, ngx_imap_auth_http_module);
+
+    if (rev->timedout) {  
+        ngx_log_error(NGX_LOG_ERR, rev->log, NGX_ETIMEDOUT,
+                      "auth http server timed out");
+        ngx_close_connection(ctx->peer.connection);
+        ngx_imap_session_internal_server_error(s);
+        return;
+    }
+
+    if (ctx->response == NULL) {
+        ctx->response = ngx_create_temp_buf(s->connection->pool, 1024);
+        if (ctx->response == NULL) {
+            ngx_close_connection(ctx->peer.connection);
+            ngx_imap_session_internal_server_error(s);
+            return;
+        }
+    }
+
+    size = ctx->response->last - ctx->response->pos;
+
+    n = ngx_recv(c, ctx->response->pos, size);
+
+    if (n == NGX_ERROR || n == 0) {
+        ngx_close_connection(ctx->peer.connection);
+        ngx_imap_session_internal_server_error(s);
+        return;
+    }
+
+
+
+
+
+
     peers = NULL;
 
     ngx_imap_proxy_init(s, peers);
@@ -231,8 +261,8 @@ ngx_imap_auth_http_block_read(ngx_event_
 
         ctx = ngx_imap_get_module_ctx(s, ngx_imap_auth_http_module);
 
-        ngx_imap_close_connection(ctx->peer.connection);
-        ngx_imap_close_connection(s->connection);
+        ngx_close_connection(ctx->peer.connection);
+        ngx_imap_session_internal_server_error(s);
     }
 }