* @param c The current connection
* @param r The current request or NULL
* @param s The server/virtual host selected
- * @param offers a list of protocol identifiers offered by the client
- * @param proposals the list of protocol identifiers proposed by the hooks
+ * @param offers A list of protocol identifiers offered by the client
+ * @param proposals The list of protocol identifiers proposed by the hooks
* @return OK or DECLINED
*/
AP_DECLARE_HOOK(int,protocol_propose,(conn_rec *c, request_rec *r,
* @param c The current connection
* @param r The current request or NULL
* @param s The server/virtual host selected
- * @param choices a list of protocol identifiers, normally the clients whishes
+ * @param choices A list of protocol identifiers, normally the clients whishes
* @param proposals the list of protocol identifiers proposed by the hooks
* @return OK or DECLINED
*/
* protocol switching must register here and return the correct protocol
* identifier for connections they switched.
*
+ * To find out the protocol for the current connection, better call
+ * @see ap_get_protocol which internally uses this hook.
+ *
* @param c The current connection
- * @return The identifier of the protocol in place
+ * @return The identifier of the protocol in place or NULL
*/
AP_DECLARE_HOOK(const char *,protocol_get,(const conn_rec *c))
* @param c The current connection
* @param r The current request or NULL
* @param s The server/virtual host selected
- * @param choices a list of protocol identifiers, normally the clients whishes
- * @return the selected protocol
+ * @param choices A list of protocol identifiers, normally the clients whishes
+ * @return The selected protocol
*/
AP_DECLARE(const char *) ap_select_protocol(conn_rec *c, request_rec *r,
server_rec *s,
server_rec *s,
const char *protocol);
+/**
+ * Call the protocol_get hook to determine the protocol currently in use
+ * for the given connection.
+ *
+ * Unless another protocol has been switch to, will default to
+ * @see AP_PROTOCOL_HTTP1 and modules implementing a new protocol must
+ * report a switched connection via the protocol_get hook.
+ *
+ * @param c The connection to determine the protocol for
+ * @return the protocol in use, never NULL
+ */
+AP_DECLARE(const char *) ap_get_protocol(conn_rec *c);
+
/** @see ap_bucket_type_error */
typedef struct ap_bucket_error ap_bucket_error;
* -> sniff for the magic PRIamble. On TLS, this might trigger the ALPN.
*/
if (!h2_ctx_protocol_get(c)
- && !strcmp(AP_PROTOCOL_HTTP1, ap_run_protocol_get(c))) {
+ && !strcmp(AP_PROTOCOL_HTTP1, ap_get_protocol(c))) {
apr_status_t status;
temp = apr_brigade_create(c->pool, c->bucket_alloc);
if (status == APR_SUCCESS) {
if (h2_ctx_protocol_get(c)
- || strcmp(AP_PROTOCOL_HTTP1, ap_run_protocol_get(c))) {
+ || strcmp(AP_PROTOCOL_HTTP1, ap_get_protocol(c))) {
/* h2 or another protocol has been selected. */
}
else {
int proposed = 0;
const char **protos = h2_h2_is_tls(c)? h2_tls_protos : h2_clear_protos;
- if (strcmp(AP_PROTOCOL_HTTP1, ap_run_protocol_get(c))) {
+ if (strcmp(AP_PROTOCOL_HTTP1, ap_get_protocol(c))) {
/* We do not know how to switch from anything else but http/1.1.
*/
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c,
APLOGNO(02836) "ALPN selected protocol: '%s'",
protocol);
- if (strcmp(protocol, ap_run_protocol_get(f->c))) {
+ if (strcmp(protocol, ap_get_protocol(f->c))) {
status = ap_switch_protocol(f->c, NULL, sslconn->server,
protocol);
if (status != APR_SUCCESS) {
}
}
-static const char *core_protocol_get(const conn_rec *c)
-{
- return AP_PROTOCOL_HTTP1;
-}
-
static int core_upgrade_handler(request_rec *r)
{
conn_rec *c = r->connection;
if (offers && offers->nelts > 0) {
const char *protocol = ap_select_protocol(c, r, r->server,
offers);
- if (strcmp(protocol, ap_run_protocol_get(c))) {
+ if (strcmp(protocol, ap_get_protocol(c))) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02909)
"Upgrade selects '%s'", protocol);
/* Let the client know what we are upgrading to. */
ap_hook_open_htaccess(ap_open_htaccess, NULL, NULL, APR_HOOK_REALLY_LAST);
ap_hook_optional_fn_retrieve(core_optional_fn_retrieve, NULL, NULL,
APR_HOOK_MIDDLE);
- ap_hook_protocol_get(core_protocol_get, NULL, NULL, APR_HOOK_REALLY_LAST);
/* register the core's insert_filter hook and register core-provided
* filters
return strcmp(proto1, proto2);
}
+AP_DECLARE(const char *) ap_get_protocol(conn_rec *c)
+{
+ const char *protocol = ap_run_protocol_get(c);
+ return protocol? protocol : AP_PROTOCOL_HTTP1;
+}
+
AP_DECLARE(const char *) ap_select_protocol(conn_rec *c, request_rec *r,
server_rec *s,
apr_array_header_t *choices)
{
apr_pool_t *pool = r? r->pool : c->pool;
apr_array_header_t *proposals;
- const char *protocol = NULL, *existing = ap_run_protocol_get(c);
+ const char *protocol = NULL, *existing = ap_get_protocol(c);
core_server_config *conf = ap_get_core_module_config(s->module_config);
if (APLOGcdebug(c)) {
server_rec *s,
const char *protocol)
{
- const char *current = ap_run_protocol_get(c);
+ const char *current = ap_get_protocol(c);
int rc;
if (!strcmp(current, protocol)) {