1 module hunt.http.server.HttpServerOptions; 2 3 import hunt.http.server.ClientAuth; 4 import hunt.http.server.HttpRequestOptions; 5 6 import hunt.http.HttpOptions; 7 import hunt.net.TcpSslOptions; 8 import hunt.net.NetServerOptions; 9 10 import hunt.system.Memory; 11 12 /** 13 * 14 */ 15 class HttpServerOptions : HttpOptions { 16 17 /** 18 * Default value of whether client auth is required (SSL/TLS) = No 19 */ 20 enum ClientAuth DEFAULT_CLIENT_AUTH = ClientAuth.NONE; 21 22 private NetServerOptions _netServerOptions; 23 private HttpRequestOptions _httpRequestOptions; 24 private ClientAuth clientAuth; 25 private bool _canUpgrade = true; 26 27 this() { 28 NetServerOptions netOptions = new NetServerOptions(); 29 // netOptions.workerThreadSize = totalCPUs(); 30 this(netOptions, new HttpRequestOptions()); 31 } 32 33 this(NetServerOptions options) { 34 this(options, new HttpRequestOptions()); 35 } 36 37 this(NetServerOptions serverOptions, HttpRequestOptions requestOptions) { 38 _netServerOptions = serverOptions; 39 _httpRequestOptions = requestOptions; 40 clientAuth = DEFAULT_CLIENT_AUTH; 41 super(serverOptions); 42 } 43 44 override NetServerOptions getTcpConfiguration() { 45 return _netServerOptions; 46 } 47 48 HttpRequestOptions requestOptions() { 49 return _httpRequestOptions; 50 } 51 52 /** 53 * 54 * @return the port 55 */ 56 int getPort() { 57 return _netServerOptions.getPort(); 58 } 59 60 /** 61 * Set the port 62 * 63 * @param port the port 64 * @return a reference to this, so the API can be used fluently 65 */ 66 HttpServerOptions setPort(ushort port) { 67 _netServerOptions.setPort(port); 68 return this; 69 } 70 71 /** 72 * 73 * @return the host 74 */ 75 string getHost() { 76 return _netServerOptions.getHost(); 77 } 78 79 /** 80 * Set the host 81 * @param host the host 82 * @return a reference to this, so the API can be used fluently 83 */ 84 HttpServerOptions setHost(string host) { 85 _netServerOptions.setHost(host); 86 return this; 87 } 88 89 /** 90 * 91 */ 92 ClientAuth getClientAuth() { 93 return clientAuth; 94 } 95 96 /** 97 * Set whether client auth is required 98 * 99 * @param clientAuth One of "NONE, REQUEST, REQUIRED". If it's set to "REQUIRED" then server will require the 100 * SSL cert to be presented otherwise it won't accept the request. If it's set to "REQUEST" then 101 * it won't mandate the certificate to be presented, basically make it optional. 102 * @return a reference to this, so the API can be used fluently 103 */ 104 HttpServerOptions setClientAuth(ClientAuth clientAuth) { 105 this.clientAuth = clientAuth; 106 return this; 107 } 108 109 bool canUpgrade() { 110 return _canUpgrade; 111 } 112 113 HttpServerOptions canUpgrade(bool value) { 114 _canUpgrade = value; 115 return this; 116 } 117 118 /* ------------------------------ Session APIs ------------------------------ */ 119 120 private string sessionIdParameterName = "hunt-session-id"; 121 private int defaultMaxInactiveInterval = 10 * 60; //second 122 123 string getSessionIdParameterName() { 124 return sessionIdParameterName; 125 } 126 127 void setSessionIdParameterName(string name) { 128 this.sessionIdParameterName = name; 129 } 130 131 int getDefaultMaxInactiveInterval() { 132 return defaultMaxInactiveInterval; 133 } 134 135 void setDefaultMaxInactiveInterval(int interval) { 136 this.defaultMaxInactiveInterval = interval; 137 } 138 } 139 140