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