void h2o__proxy_process_request(h2o_req_t *req) { h2o_req_overrides_t *overrides = req->overrides; h2o_http1client_ctx_t *client_ctx = get_client_ctx(req); struct rp_generator_t *self; if (overrides != NULL) { if (overrides->socketpool != NULL) { self = proxy_send_prepare(req, 1); h2o_http1client_connect_with_pool(&self->client, self, client_ctx, overrides->socketpool, on_connect); return; } else if (overrides->hostport.host.base != NULL) { self = proxy_send_prepare(req, 0); h2o_http1client_connect(&self->client, self, client_ctx, req->overrides->hostport.host, req->overrides->hostport.port, 0, on_connect); return; } } { /* default logic */ h2o_iovec_t host; uint16_t port; if (h2o_url_parse_hostport(req->authority.base, req->authority.len, &host, &port) == NULL) { h2o_req_log_error(req, "lib/core/proxy.c", "invalid URL supplied for internal redirection:%s://%.*s%.*s", req->scheme->name.base, (int)req->authority.len, req->authority.base, (int)req->path.len, req->path.base); h2o_send_error(req, 502, "Gateway Error", "internal error", 0); return; } if (port == 65535) port = req->scheme->default_port; self = proxy_send_prepare(req, 0); h2o_http1client_connect(&self->client, self, client_ctx, host, port, req->scheme == &H2O_URL_SCHEME_HTTPS, on_connect); return; } }
int h2o_proxy_send_with_pool(h2o_req_t *req, h2o_http1client_ctx_t *client_ctx, h2o_proxy_location_t *upstream, h2o_socketpool_t *sockpool) { struct rp_generator_t *self = proxy_send_prepare(req, upstream, 1); self->client = h2o_http1client_connect_with_pool(client_ctx, &req->pool, sockpool, on_connect); self->client->data = self; return 0; }
int h2o_proxy_send(h2o_req_t *req, h2o_http1client_ctx_t *client_ctx, h2o_proxy_location_t *upstream) { struct rp_generator_t *self = proxy_send_prepare(req, upstream, 0); self->client = h2o_http1client_connect( client_ctx, &req->pool, h2o_strdup(&req->pool, upstream->host.base, upstream->host.len).base, upstream->port, on_connect); self->client->data = self; return 0; }