| 77 | } |
| 78 | |
| 79 | apr_status_t h2_request_rcreate(h2_request **preq, apr_pool_t *pool, |
| 80 | request_rec *r, h2_hd_scratch *scratch) |
| 81 | { |
| 82 | h2_request *req; |
| 83 | const char *scheme, *authority, *path; |
| 84 | h1_ctx x; |
| 85 | |
| 86 | *preq = NULL; |
| 87 | scheme = apr_pstrdup(pool, r->parsed_uri.scheme? r->parsed_uri.scheme |
| 88 | : ap_http_scheme(r)); |
| 89 | authority = apr_pstrdup(pool, r->hostname); |
| 90 | path = apr_uri_unparse(pool, &r->parsed_uri, APR_URI_UNP_OMITSITEPART); |
| 91 | |
| 92 | if (!r->method || !scheme || !r->hostname || !path) { |
| 93 | return APR_EINVAL; |
| 94 | } |
| 95 | |
| 96 | /* The authority we carry in h2_request is the 'authority' part of |
| 97 | * the URL for the request. r->hostname has stripped any port info that |
| 98 | * might have been present. Do we need to add it? |
| 99 | */ |
| 100 | if (!ap_strchr_c(authority, ':')) { |
| 101 | if (r->parsed_uri.port_str) { |
| 102 | /* Yes, it was there, add it again. */ |
| 103 | authority = apr_pstrcat(pool, authority, ":", r->parsed_uri.port_str, NULL); |
| 104 | } |
| 105 | else if (!r->parsed_uri.hostname && r->server && r->server->port) { |
| 106 | /* If there was no hostname in the parsed URL, the URL was relative. |
| 107 | * In that case, we restore port from our server->port, if it |
| 108 | * is known and not the default port for the scheme. */ |
| 109 | apr_port_t defport = apr_uri_port_of_scheme(scheme); |
| 110 | if (defport != r->server->port) { |
| 111 | /* port info missing and port is not default for scheme: append */ |
| 112 | authority = apr_psprintf(pool, "%s:%d", authority, |
| 113 | (int)r->server->port); |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | req = apr_pcalloc(pool, sizeof(*req)); |
| 119 | req->method = apr_pstrdup(pool, r->method); |
| 120 | req->scheme = scheme; |
| 121 | req->authority = authority; |
| 122 | req->path = path; |
| 123 | req->headers = apr_table_make(pool, 10); |
| 124 | req->http_status = H2_HTTP_STATUS_UNSET; |
| 125 | req->request_time = apr_time_now(); |
| 126 | |
| 127 | x.pool = pool; |
| 128 | x.headers = req->headers; |
| 129 | x.status = APR_SUCCESS; |
| 130 | x.scratch = scratch; |
| 131 | apr_table_do(set_h1_header, &x, r->headers_in, NULL); |
| 132 | |
| 133 | *preq = req; |
| 134 | return x.status; |
| 135 | } |
| 136 |
no test coverage detected