{
struct lws *wsi;
int v = SPEC_LATEST_SUPPORTED;
+ const struct lws_protocols *p;
if (i->context->requested_kill)
return NULL;
wsi->ietf_spec_revision = v;
wsi->user_space = NULL;
wsi->state = LWSS_CLIENT_UNCONNECTED;
- wsi->protocol = NULL;
wsi->pending_timeout = NO_PENDING_TIMEOUT;
wsi->position_in_fds_table = -1;
wsi->u.hdr.c_port = i->port;
wsi->vhost = i->context->vhost_list;
wsi->protocol = &wsi->vhost->protocols[0];
+
+ /* for http[s] connection, allow protocol selection by name */
+
+ if (i->method && i->vhost && i->protocol) {
+ p = lws_vhost_name_to_protocol(i->vhost, i->protocol);
+ if (p)
+ wsi->protocol = p;
+ }
+
if (wsi && !wsi->user_space && i->userdata) {
wsi->user_space_externally_allocated = 1;
wsi->user_space = i->userdata;
return wsi->protocol;
}
+LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
+lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name)
+{
+ int n;
+
+ for (n = 0; n < vh->count_protocols; n++)
+ if (!strcmp(name, vh->protocols[n].name))
+ return &vh->protocols[n];
+
+ return NULL;
+}
+
LWS_VISIBLE int
lws_callback_all_protocol(struct lws_context *context,
const struct lws_protocols *protocol, int reason)
return NULL;
}
-LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
-lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name)
-{
- int n;
-
- for (n = 0; n < vh->count_protocols; n++)
- if (!strcmp(name, vh->protocols[n].name))
- return &vh->protocols[n];
-
- return NULL;
-}
-
LWS_VISIBLE LWS_EXTERN const char *
lws_get_mimetype(const char *file, const struct lws_http_mount *m)
{