68 |
|
apr_status_t status; |
69 |
|
serf_status_line sl; |
70 |
|
req_ctx_t *ctx = handler_baton; |
71 |
+ |
serf_connection_t *conn = request->conn; |
72 |
|
|
73 |
< |
if (! response) { |
74 |
< |
serf_connection_request_create(request->conn, |
75 |
< |
setup_request, |
76 |
< |
ctx); |
73 |
> |
/* CONNECT request was cancelled. Assuming that this is during connection |
74 |
> |
reset, we can safely discard the request as a new one will be created |
75 |
> |
when setting up the next connection. */ |
76 |
> |
if (!response) |
77 |
|
return APR_SUCCESS; |
77 |
– |
} |
78 |
|
|
79 |
|
status = serf_bucket_response_status(response, &sl); |
80 |
|
if (SERF_BUCKET_READ_ERROR(status)) { |
97 |
|
connection. |
98 |
|
*/ |
99 |
|
if (sl.code >= 200 && sl.code < 300) { |
100 |
< |
request->conn->state = SERF_CONN_CONNECTED; |
100 |
> |
serf_bucket_t *hdrs; |
101 |
> |
const char *val; |
102 |
|
|
103 |
+ |
conn->state = SERF_CONN_CONNECTED; |
104 |
+ |
|
105 |
|
/* Body is supposed to be empty. */ |
106 |
|
apr_pool_destroy(ctx->pool); |
107 |
< |
serf_bucket_destroy(request->conn->ssltunnel_ostream); |
108 |
< |
request->conn->stream = NULL; |
107 |
> |
serf_bucket_destroy(conn->ssltunnel_ostream); |
108 |
> |
serf_bucket_destroy(conn->stream); |
109 |
> |
conn->stream = NULL; |
110 |
|
ctx = NULL; |
111 |
|
|
112 |
< |
serf__log(CONN_VERBOSE, __FILE__, |
113 |
< |
"successfully set up ssl tunnel on connection 0x%x\n", |
110 |
< |
request->conn); |
112 |
> |
serf__log_skt(CONN_VERBOSE, __FILE__, conn->skt, |
113 |
> |
"successfully set up ssl tunnel.\n"); |
114 |
|
|
115 |
+ |
/* Fix for issue #123: ignore the "Connection: close" header here, |
116 |
+ |
leaving the header in place would make the serf's main context |
117 |
+ |
loop close this connection immediately after reading the 200 OK |
118 |
+ |
response. */ |
119 |
+ |
|
120 |
+ |
hdrs = serf_bucket_response_get_headers(response); |
121 |
+ |
val = serf_bucket_headers_get(hdrs, "Connection"); |
122 |
+ |
if (val && strcasecmp("close", val) == 0) { |
123 |
+ |
serf__log_skt(CONN_VERBOSE, __FILE__, conn->skt, |
124 |
+ |
"Ignore Connection: close header on this reponse, don't " |
125 |
+ |
"close the connection now that the tunnel is set up.\n"); |
126 |
+ |
serf__bucket_headers_remove(hdrs, "Connection"); |
127 |
+ |
} |
128 |
+ |
|
129 |
|
return APR_EOF; |
130 |
|
} |
131 |
|
|
176 |
|
|
177 |
|
ctx = apr_palloc(ssltunnel_pool, sizeof(*ctx)); |
178 |
|
ctx->pool = ssltunnel_pool; |
179 |
< |
ctx->uri = apr_psprintf(ctx->pool, "%s:%d", conn->host_info.hostinfo, |
179 |
> |
ctx->uri = apr_psprintf(ctx->pool, "%s:%d", conn->host_info.hostname, |
180 |
|
conn->host_info.port); |
181 |
|
|
182 |
|
conn->ssltunnel_ostream = serf__bucket_stream_create(conn->allocator, |
183 |
|
detect_eof, |
184 |
|
conn); |
185 |
|
|
186 |
< |
/* TODO: should be the first request on the connection. */ |
187 |
< |
serf_connection_priority_request_create(conn, |
188 |
< |
setup_request, |
172 |
< |
ctx); |
186 |
> |
serf__ssltunnel_request_create(conn, |
187 |
> |
setup_request, |
188 |
> |
ctx); |
189 |
|
|
190 |
|
conn->state = SERF_CONN_SETUP_SSLTUNNEL; |
191 |
< |
serf__log(CONN_VERBOSE, __FILE__, |
192 |
< |
"setting up ssl tunnel on connection 0x%x\n", conn); |
191 |
> |
serf__log_skt(CONN_VERBOSE, __FILE__, conn->skt, |
192 |
> |
"setting up ssl tunnel on connection.\n"); |
193 |
|
|
194 |
|
return APR_SUCCESS; |
195 |
|
} |