client: allow http[s] to select targeted protocol name in vhost

This commit is contained in:
Andy Green 2017-02-15 09:12:39 +08:00
parent 238766be6b
commit 186ba832b3
3 changed files with 22 additions and 13 deletions

View file

@ -562,6 +562,7 @@ lws_client_connect_via_info(struct lws_client_connect_info *i)
{
struct lws *wsi;
int v = SPEC_LATEST_SUPPORTED;
const struct lws_protocols *p;
if (i->context->requested_kill)
return NULL;
@ -590,7 +591,6 @@ lws_client_connect_via_info(struct lws_client_connect_info *i)
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;
@ -599,6 +599,15 @@ lws_client_connect_via_info(struct lws_client_connect_info *i)
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;

View file

@ -857,6 +857,18 @@ lws_protocol_get(struct lws *wsi)
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)

View file

@ -251,18 +251,6 @@ lws_select_vhost(struct lws_context *context, int port, const char *servername)
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)
{