| 2442 | } |
| 2443 | |
| 2444 | AP_DECLARE(const char *) ap_select_protocol(conn_rec *c, request_rec *r, |
| 2445 | server_rec *s, |
| 2446 | const apr_array_header_t *choices) |
| 2447 | { |
| 2448 | apr_pool_t *pool = r? r->pool : c->pool; |
| 2449 | core_server_config *conf; |
| 2450 | const char *protocol = NULL, *existing; |
| 2451 | apr_array_header_t *proposals; |
| 2452 | |
| 2453 | if (!s) { |
| 2454 | s = (r? r->server : c->base_server); |
| 2455 | } |
| 2456 | conf = ap_get_core_module_config(s->module_config); |
| 2457 | |
| 2458 | if (APLOGcdebug(c)) { |
| 2459 | const char *p = apr_array_pstrcat(pool, conf->protocols, ','); |
| 2460 | ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, APLOGNO(03155) |
| 2461 | "select protocol from %s, choices=%s for server %s", |
| 2462 | p, apr_array_pstrcat(pool, choices, ','), |
| 2463 | s->server_hostname); |
| 2464 | } |
| 2465 | |
| 2466 | if (conf->protocols->nelts <= 0) { |
| 2467 | /* nothing configured, by default, we only allow http/1.1 here. |
| 2468 | * For now... |
| 2469 | */ |
| 2470 | if (ap_array_str_contains(choices, AP_PROTOCOL_HTTP1)) { |
| 2471 | return AP_PROTOCOL_HTTP1; |
| 2472 | } |
| 2473 | else { |
| 2474 | return NULL; |
| 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | proposals = apr_array_make(pool, choices->nelts + 1, sizeof(char *)); |
| 2479 | ap_run_protocol_propose(c, r, s, choices, proposals); |
| 2480 | |
| 2481 | /* If the existing protocol has not been proposed, but is a choice, |
| 2482 | * add it to the proposals implicitly. |
| 2483 | */ |
| 2484 | existing = ap_get_protocol(c); |
| 2485 | if (!ap_array_str_contains(proposals, existing) |
| 2486 | && ap_array_str_contains(choices, existing)) { |
| 2487 | APR_ARRAY_PUSH(proposals, const char*) = existing; |
| 2488 | } |
| 2489 | |
| 2490 | if (proposals->nelts > 0) { |
| 2491 | int i; |
| 2492 | const apr_array_header_t *prefs = NULL; |
| 2493 | |
| 2494 | /* Default for protocols_honor_order is 'on' or != 0 */ |
| 2495 | if (conf->protocols_honor_order == 0 && choices->nelts > 0) { |
| 2496 | prefs = choices; |
| 2497 | } |
| 2498 | else { |
| 2499 | prefs = conf->protocols; |
| 2500 | } |
| 2501 |
no test coverage detected