From 14d17f36e798c5917a9ce89b8acd406170017463 Mon Sep 17 00:00:00 2001 From: Eugine Blikh Date: Sat, 29 Sep 2018 21:47:49 +0300 Subject: [PATCH] Add configuration option "ignore_unknown_upgrade" In case when upgrade should be ignored --- http/server.lua | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/http/server.lua b/http/server.lua index c985a3b..6e33572 100644 --- a/http/server.lua +++ b/http/server.lua @@ -988,8 +988,10 @@ local function httpd_http11_handler(session) local proto_name = p.headers['upgrade']:lower() local proto = session.server.upgrades[proto_name] if not proto then - session:write('HTTP/1.1 400 Bad Request\r\n\r\n') - return false + if not session.server.options.ignore_unknown_upgrade then + session:write('HTTP/1.1 400 Bad Request\r\n\r\n') + return false + end else local ok, upgrade_ok = pcall(proto.upgrade, session, p) if not ok then @@ -1249,17 +1251,18 @@ local httpd_mt = { } local httpd_options_default = { - max_header_size = 4096, - header_timeout = 100, - handler = handler, - app_dir = '.', - charset = 'utf-8', - cache_templates = true, - cache_controllers = true, - cache_static = true, - log_requests = true, - log_errors = true, - display_errors = true, + max_header_size = 4096, + header_timeout = 100, + handler = handler, + app_dir = '.', + charset = 'utf-8', + cache_templates = true, + cache_controllers = true, + cache_static = true, + log_requests = true, + log_errors = true, + display_errors = true, + ignore_unknown_upgrade = true, } local function httpd_new(host, port, options)