Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-08-14 10:00:28 +0400
committerIgor Sysoev <igor@sysoev.ru>2003-08-14 10:00:28 +0400
commitae5c59ca70bd1730e1b5d41dc8e725662dc03643 (patch)
treee5206f6bf5cdec6399a40e88b27ad4661c43d6c2 /src
parent8900adbddb48d52feb866b87132338aad0b9b273 (diff)
nginx-0.0.1-2003-08-14-10:00:28 import
Diffstat (limited to 'src')
-rw-r--r--src/event/ngx_event_connect.c10
-rw-r--r--src/http/modules/ngx_http_ssi_filter.c24
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.c156
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.h20
4 files changed, 147 insertions, 63 deletions
diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c
index c1b30cb99..17ef6a0be 100644
--- a/src/event/ngx_event_connect.c
+++ b/src/event/ngx_event_connect.c
@@ -1,6 +1,7 @@
#include <ngx_event_connect.h>
+
/* AF_INET only */
int ngx_event_connect_peer(ngx_peer_connection_t *pc)
@@ -10,7 +11,6 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc)
ngx_socket_t s;
struct sockaddr_in *addr;
-
now = ngx_time();
/* ngx_lock_mutex(pc->peers->mutex); */
@@ -19,7 +19,7 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc)
/* cached connection */
- pc->connection = pc->peers->cached[pc->peers->last_cached]
+ pc->connection = pc->peers->cached[pc->peers->last_cached];
pc->peers->last_cached--;
/* ngx_unlock_mutex(pc->peers->mutex); */
@@ -189,3 +189,9 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc)
}
+
+
+void ngx_event_connect_peer_failed(ngx_peer_connection_t *pc)
+{
+ return;
+}
diff --git a/src/http/modules/ngx_http_ssi_filter.c b/src/http/modules/ngx_http_ssi_filter.c
index f1cbbaaff..e00c35280 100644
--- a/src/http/modules/ngx_http_ssi_filter.c
+++ b/src/http/modules/ngx_http_ssi_filter.c
@@ -15,13 +15,14 @@
typedef struct {
+ ngx_hunk_t *hunk;
ngx_table_elt_t *param;
ngx_str_t command;
ngx_array_t params;
int state;
int looked;
char *pos;
- ngx_chain_t *out;
+ ngx_chain_t *incoming;
int new_hunk;
u_int value_len;
} ngx_http_ssi_ctx_t;
@@ -75,12 +76,13 @@ static int ngx_http_ssi_header_filter(ngx_http_request_t *r)
static int ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
+ int rc;
ngx_chain_t chain;
ngx_http_ssi_ctx_t *ctx;
ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module);
- if ((ctx == NULL) || (in == NULL && ctx->out == NULL)) {
+ if ((ctx == NULL) || (in == NULL && ctx->incoming == NULL)) {
return next_body_filter(r, NULL);
}
@@ -115,16 +117,16 @@ static int ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
#if 0
- add in to ctx->out chain
+ add in to ctx->incoming chain
- while (ctx->out) {
+ while (ctx->incoming) {
rc == ngx_http_ssi_exec(r, ctx);
if (rc != NGX_ERROR) {
return rc;
}
- ctx->out = ctx->out->next;
+ ctx->incoming = ctx->incoming->next;
}
#endif
@@ -136,8 +138,8 @@ static int ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
#if 0
- while (ctx->out) {
- rc = ngx_http_ssi_parse(r, ctx, ctx->out->hunk);
+ while (ctx->incoming) {
+ rc = ngx_http_ssi_parse(r, ctx, ctx->incoming->hunk);
if (rc == NGX_ERROR) {
return rc;
@@ -155,13 +157,13 @@ static int ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
- looked
- chain.hunk = ctx->out->hunk;
+ chain.hunk = ctx->incoming->hunk;
chain.next = NULL;
rc = next_body_filter(r, &chain);
if (rc != NGX_OK) {
- ctx->out = ctx->out->next;
+ ctx->incoming = ctx->incoming->next;
return rc;
}
@@ -171,7 +173,7 @@ static int ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
} else if (rc == NGX_HTTP_SSI_LONG_VALUE) {
}
- ctx->out = ctx->out->next;
+ ctx->incoming = ctx->incoming->next;
}
#endif
@@ -190,7 +192,7 @@ static int ngx_http_ssi_copy_opcode(ngx_http_request_t *r,
ngx_hunk_t *h;
ngx_chain_t chain;
- h = ctx->out->hunk;
+ h = ctx->incoming->hunk;
if (ctx->looked == 0 && ctx->pos == h->last) {
chain.hunk = h;
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index baecb2531..962dcbfbd 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -8,6 +8,10 @@
+static void ngx_http_proxy_send_request(ngx_event_t *wev);
+static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf);
+
+
static ngx_command_t ngx_http_proxy_commands[] = {
ngx_null_command
};
@@ -20,12 +24,11 @@ ngx_http_module_t ngx_http_proxy_module_ctx = {
NULL, /* create server configuration */
NULL, /* merge server configuration */
+ ngx_http_proxy_create_loc_conf, /* create location configration */
#if 0
- ngx_http_proxy_create_conf, /* create location configration */
ngx_http_proxy_merge_conf /* merge location configration */
#endif
- NULL,
NULL
};
@@ -46,24 +49,25 @@ static
int ngx_http_proxy_handler(ngx_http_request_t *r)
{
- int rc;
- ngx_http_proxy_ctx_t *p;
- ngx_peer_connection_t *pc;
-
+ int rc;
+ ngx_http_proxy_ctx_t *p;
+ ngx_http_proxy_loc_conf_t *lcf;
ngx_http_create_ctx(r, p, ngx_http_proxy_module,
sizeof(ngx_http_proxy_ctx_t),
NGX_HTTP_INTERNAL_SERVER_ERROR);
-
- p->action = "connecting to upstream";
- p->request = r;
-
+ p->lcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
#if 0
- pc->peers = lcf->peers;
+ create_request;
#endif
+ p->action = "connecting to upstream";
+ p->request = r;
+ p->upstream.peers = p->lcf->peers;
+
+ /* TODO: change log->data, how to restore log->data ? */
p->upstream.log = r->connection->log;
do {
@@ -74,56 +78,89 @@ int ngx_http_proxy_handler(ngx_http_request_t *r)
}
if (rc == NGX_OK) {
- send_proxy_request(p);
- return NGX_OK;
+ ngx_http_proxy_send_request(p->upstream.connection->write);
+ /* ??? */ return NGX_OK;
}
- if (rc == NGX_AGAIN && p->upstream.connection) {
- return NGX_OK;
+ if (rc == NGX_AGAIN) {
+ /* ??? */ return NGX_OK;
}
+ /* rc == NGX_CONNECT_FAILED */
+
+ ngx_event_connect_peer_failed(&p->upstream);
+
} while (p->upstream.tries);
return NGX_HTTP_BAD_GATEWAY;
}
-#if 0
-
-ngx_http_proxy_connect()
- do {
- ngx_event_connect_peer()
- if error
- return error
- if ok
- return ok
- if again
- return again
-
- /* next */
- while (tries)
-}
+static void ngx_http_proxy_send_request(ngx_event_t *wev)
+{
+ int rc;
+ ngx_chain_t *chain;
+ ngx_connection_t *c;
+ ngx_http_proxy_ctx_t *p;
+ c = wev->data;
+ p = c->data;
-ngx_http_proxy_send_request(ngx_event_t *wev)
for ( ;; ) {
- send
- if ok
- ???
- if again
- return
- if error
- close
- ngx_http_proxy_connect()
- if ok
- continue
- if error
- return
- if again
- return
- }
+ chain = ngx_write_chain(c, p->request_hunks);
+ if (chain == (ngx_chain_t *) -1) {
+ ngx_http_proxy_close_connection(c);
+
+ do {
+ rc = ngx_event_connect_peer(&p->upstream);
+
+ if (rc == NGX_OK) {
+#if 0
+ copy chain and hunks p->request_hunks from p->initial_request_hunks;
#endif
+ c = p->connection;
+ wev = c->write;
+
+ break;
+ }
+
+ if (rc == NGX_ERROR) {
+ ngx_http_finalize_request(p->request,
+ NGX_HTTP_INTERNAL_SERVER_ERROR);
+ return;
+ }
+
+ if (rc == NGX_AGAIN) {
+ return;
+ }
+
+ /* rc == NGX_CONNECT_FAILED */
+
+ ngx_event_connect_peer_failed(&p->upstream);
+
+ } while (p->upstream.tries);
+
+ return;
+
+ } else {
+ p->request_hunks = chain;
+
+ ngx_del_timer(wev);
+
+ if (chain) {
+ ngx_add_timer(wev, p->lcf->send_timeout);
+ wev->timer_set = 1;
+
+ } else {
+ wev->timer_set = 0;
+ /* TODO: del event */
+ }
+
+ return;
+ }
+ }
+}
static size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len)
@@ -137,3 +174,30 @@ static size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len)
p->request->connection->addr_text.data,
p->request->unparsed_uri.data);
}
+
+
+static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf)
+{
+ ngx_http_proxy_loc_conf_t *conf;
+
+ ngx_test_null(conf,
+ ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)),
+ NGX_CONF_ERROR);
+
+ /* STUB */
+ ngx_test_null(conf->peers, ngx_pcalloc(cf->pool, sizeof(ngx_peers_t)),
+ NGX_CONF_ERROR);
+
+ conf->peers->number = 1;
+ conf->peers->peers[0].addr = inet_addr("127.0.0.1");
+ conf->peers->peers[0].host.data = "localhost";
+ conf->peers->peers[0].host.len = sizeof("localhost") - 1;
+ conf->peers->peers[0].port = htons(9000);
+ conf->peers->peers[0].addr_port_text.data = "127.0.0.1:9000";
+ conf->peers->peers[0].addr_port_text.len = sizeof("127.0.0.1:9000") - 1;
+
+ conf->send_timeout = 30000;
+ /* */
+
+ return conf;
+}
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h
index 7f85417c4..ce264c9a2 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.h
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.h
@@ -8,15 +8,27 @@
#include <ngx_http.h>
+typedef struct {
+ ngx_msec_t send_timeout;
+ ngx_peers_t *peers;
+} ngx_http_proxy_loc_conf_t;
+
+
typedef struct ngx_http_proxy_ctx_s ngx_http_proxy_ctx_t;
struct ngx_http_proxy_ctx_s {
- ngx_peer_connection_t upstream;
- ngx_peer_t *peer;
+ ngx_peer_connection_t upstream;
+ ngx_peer_t *peer;
+
+ ngx_connection_t *connection;
+
+ ngx_http_request_t *request;
+
+ ngx_http_proxy_loc_conf_t *lcf;
- ngx_http_request_t *request;
+ ngx_chain_t *request_hunks;
- char *action;
+ char *action;
};