| 823 | } |
| 824 | |
| 825 | static apr_status_t open_stream(h2_proxy_session *session, const char *url, |
| 826 | request_rec *r, int standalone, |
| 827 | h2_proxy_stream **pstream) |
| 828 | { |
| 829 | h2_proxy_stream *stream; |
| 830 | apr_uri_t puri; |
| 831 | const char *authority, *scheme, *path, *orig_host; |
| 832 | apr_status_t status; |
| 833 | proxy_dir_conf *dconf; |
| 834 | |
| 835 | stream = apr_pcalloc(r->pool, sizeof(*stream)); |
| 836 | |
| 837 | stream->pool = r->pool; |
| 838 | stream->url = url; |
| 839 | stream->r = r; |
| 840 | stream->cfront = r->connection; |
| 841 | stream->standalone = standalone; |
| 842 | stream->session = session; |
| 843 | stream->state = H2_STREAM_ST_IDLE; |
| 844 | |
| 845 | stream->input = apr_brigade_create(stream->pool, stream->cfront->bucket_alloc); |
| 846 | stream->output = apr_brigade_create(stream->pool, stream->cfront->bucket_alloc); |
| 847 | |
| 848 | stream->req = h2_proxy_req_create(1, stream->pool); |
| 849 | |
| 850 | status = apr_uri_parse(stream->pool, url, &puri); |
| 851 | if (status != APR_SUCCESS) |
| 852 | return status; |
| 853 | |
| 854 | scheme = (strcmp(puri.scheme, "h2")? "http" : "https"); |
| 855 | orig_host = apr_table_get(r->headers_in, "Host"); |
| 856 | if (orig_host == NULL) { |
| 857 | orig_host = r->hostname; |
| 858 | } |
| 859 | |
| 860 | dconf = ap_get_module_config(r->per_dir_config, &proxy_module); |
| 861 | if (dconf->preserve_host) { |
| 862 | authority = orig_host; |
| 863 | if (!authority) { |
| 864 | /* Duplicate mod_proxy behaviour if ProxyPreserveHost is |
| 865 | * used but an "HTTP/0.9" request is received without a |
| 866 | * Host: header */ |
| 867 | authority = r->server->server_hostname; |
| 868 | ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(10511) |
| 869 | "incoming HTTP/0.9 request (with no Host header) " |
| 870 | "and preserve host set, " |
| 871 | "forcing hostname to be %s for uri %s", |
| 872 | authority, r->uri); |
| 873 | apr_table_setn(r->headers_in, "Host", authority); |
| 874 | } |
| 875 | } |
| 876 | else { |
| 877 | authority = puri.hostname; |
| 878 | if (!ap_strchr_c(authority, ':') && puri.port |
| 879 | && apr_uri_port_of_scheme(scheme) != puri.port) { |
| 880 | /* port info missing and port is not default for scheme: append */ |
| 881 | authority = apr_psprintf(stream->pool, "%s:%d", authority, puri.port); |
| 882 | } |
no test coverage detected