diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index ed716e89..a9601135 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -1696,6 +1696,10 @@ enum lws_context_options { /**< (VH) if invalid http is coming in the first line, */ LWS_SERVER_OPTION_LIBEVENT = (1 << 21), /**< (CTX) Use libevent event loop */ + LWS_SERVER_OPTION_ONLY_RAW = (1 << 22), + /**< (VH) All connections to this vhost / port are RAW as soon as + * the connection is accepted, no HTTP is going to be coming. + */ /****** add new things just above ---^ ******/ }; diff --git a/lib/server.c b/lib/server.c index 2de0e6a4..b2377673 100644 --- a/lib/server.c +++ b/lib/server.c @@ -2018,6 +2018,8 @@ lws_server_socket_service(struct lws_context *context, struct lws *wsi, struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; lws_sockfd_type accept_fd = LWS_SOCK_INVALID; struct allocated_headers *ah; + lws_sock_file_fd_type fd; + int opts = LWS_ADOPT_SOCKET | LWS_ADOPT_ALLOW_SSL; #if LWS_POSIX struct sockaddr_in cli_addr; socklen_t clilen; @@ -2301,7 +2303,12 @@ try_pollout: break; } - if (!lws_adopt_socket_vhost(wsi->vhost, accept_fd)) + if (!(wsi->vhost->options & LWS_SERVER_OPTION_ONLY_RAW)) + opts |= LWS_ADOPT_HTTP; + + fd.sockfd = accept_fd; + if (!lws_adopt_descriptor_vhost(wsi->vhost, opts, fd, + NULL, NULL)) /* already closed cleanly as necessary */ return 1;