1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_event.h>
/* STUB */ #include <ngx_event_connect.h>
#include <ngx_http.h>
#include <ngx_http_proxy_handler.h>
static ngx_command_t ngx_http_proxy_commands[] = {
ngx_null_command
};
ngx_http_module_t ngx_http_proxy_module_ctx = {
NULL, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
NULL, /* merge server configuration */
#if 0
ngx_http_proxy_create_conf, /* create location configration */
ngx_http_proxy_merge_conf /* merge location configration */
#endif
NULL,
NULL
};
ngx_module_t ngx_http_proxy_module = {
NGX_MODULE,
&ngx_http_proxy_module_ctx, /* module context */
ngx_http_proxy_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init module */
NULL /* init child */
};
#if 0
static
#endif
int ngx_http_proxy_handler(ngx_http_request_t *r)
{
int rc;
ngx_http_proxy_ctx_t *p;
ngx_peer_connection_t *pc;
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;
#if 0
pc->peers = lcf->peers;
#endif
p->upstream.log = r->connection->log;
do {
rc = ngx_event_connect_peer(&p->upstream);
if (rc == NGX_ERROR) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
if (rc == NGX_OK) {
send_proxy_request(p);
return NGX_OK;
}
if (rc == NGX_AGAIN && p->upstream.connection) {
return NGX_OK;
}
} 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)
}
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
}
#endif
static size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len)
{
ngx_http_proxy_ctx_t *p = data;
return ngx_snprintf(buf, len,
" while %s, upstream: %s, client: %s, URL: %s",
p->action,
p->upstream.peers->peers[p->upstream.cur_peer].addr_port_text.data,
p->request->connection->addr_text.data,
p->request->unparsed_uri.data);
}
|