From 46a624bae7def6f480433739ca4a9959d80f578a Mon Sep 17 00:00:00 2001 From: heromyth Date: Thu, 3 Mar 2022 11:22:17 +0800 Subject: [PATCH] Add a setting for HTTP Upgrade. --- source/hunt/framework/config/ApplicationConfig.d | 3 ++- source/hunt/framework/controller/Controller.d | 2 ++ source/hunt/framework/provider/HttpServiceProvider.d | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/source/hunt/framework/config/ApplicationConfig.d b/source/hunt/framework/config/ApplicationConfig.d index 05af7436..14c172e3 100755 --- a/source/hunt/framework/config/ApplicationConfig.d +++ b/source/hunt/framework/config/ApplicationConfig.d @@ -22,7 +22,7 @@ import std.socket : Address, parseAddress; import std.string; import hunt.http.MultipartOptions; -import hunt.logging.ConsoleLogger; +import hunt.logging.Logger; import hunt.util.Configuration; @@ -106,6 +106,7 @@ class ApplicationConfig { size_t keepAliveTimeOut = 30; size_t maxHeaderSize = 60 * 1024; int cacheControl; + bool canUpgrade = true; bool enableCors = false; // CORS support string allowOrigin = "*"; string allowMethods = "*"; diff --git a/source/hunt/framework/controller/Controller.d b/source/hunt/framework/controller/Controller.d index bd07fa4d..70baea44 100755 --- a/source/hunt/framework/controller/Controller.d +++ b/source/hunt/framework/controller/Controller.d @@ -112,6 +112,8 @@ abstract class Controller } HttpConnection httpConnection = context.httpConnection(); + if(httpConnection is null) + throw new Error("The http connection is null!"); _request = new Request(context.getRequest(), httpConnection.getRemoteAddress(), diff --git a/source/hunt/framework/provider/HttpServiceProvider.d b/source/hunt/framework/provider/HttpServiceProvider.d index b4e4efdb..b2f5b8d4 100644 --- a/source/hunt/framework/provider/HttpServiceProvider.d +++ b/source/hunt/framework/provider/HttpServiceProvider.d @@ -16,7 +16,7 @@ import hunt.http.server.WebSocketHandler; import hunt.http.WebSocketPolicy; import hunt.http.WebSocketCommon; -import hunt.logging.ConsoleLogger; +import hunt.logging.Logger; import poodinis; @@ -62,6 +62,7 @@ class HttpServiceProvider : ServiceProvider { .maxRequestSize(cast(int)appConfig.http.maxHeaderSize) .maxFileSize(cast(int)appConfig.upload.maxSize) .ioThreadSize(appConfig.http.ioThreads) + .canUpgrade(appConfig.http.canUpgrade) .resourceCacheTime(staticFilesConfig.cacheTime.seconds); version(WITH_HUNT_TRACE) {