@@ -193,6 +193,12 @@ unittest
193
193
virtual hosts
194
194
*/
195
195
void handleHTTPConnection (TCPConnection connection, HTTPServerContext context)
196
+ @safe {
197
+ auto raddr = connection.remoteAddress;
198
+ handleHTTPConnection(connection, context, raddr);
199
+ }
200
+ // / ditto
201
+ void handleHTTPConnection (TCPConnection connection, HTTPServerContext context, ref NetworkAddress remote_address)
196
202
@safe {
197
203
import vibe.http.internal.http1.server : handleHTTP1Connection;
198
204
import vibe.http.internal.http2.server : handleHTTP2Connection;
@@ -212,7 +218,7 @@ void handleHTTPConnection(TCPConnection connection, HTTPServerContext context)
212
218
// check wether the client's address is banned
213
219
foreach (ref virtual_host; context.m_virtualHosts)
214
220
if ((virtual_host.settings.rejectConnectionPredicate ! is null ) &&
215
- virtual_host.settings.rejectConnectionPredicate(connection.remoteAddress() ))
221
+ virtual_host.settings.rejectConnectionPredicate(remote_address ))
216
222
return ;
217
223
218
224
// Set NODELAY to true, to avoid delays caused by sending the response
@@ -235,13 +241,13 @@ void handleHTTPConnection(TCPConnection connection, HTTPServerContext context)
235
241
else {
236
242
logDebug(" Accept TLS connection: %s" , context.tlsContext.kind);
237
243
// TODO: reverse DNS lookup for peer_name of the incoming connection for TLS client certificate verification purposes
238
- tls_stream = createTLSStreamFL(http_stream, context.tlsContext, TLSStreamState.accepting, null , connection.remoteAddress );
244
+ tls_stream = createTLSStreamFL(http_stream, context.tlsContext, TLSStreamState.accepting, null , remote_address );
239
245
240
246
Nullable! string proto = tls_stream.alpn;
241
247
if (! proto.isNull && proto == " h2" && (context.m_virtualHosts[0 ].settings.options & HTTPServerOption.enableHTTP2)) {
242
248
logTrace(" Using HTTP/2 as requested per ALPN" );
243
249
HTTP2Settings settings;
244
- auto h2context = new HTTP2ServerContext(context, settings);
250
+ auto h2context = new HTTP2ServerContext(context, settings, remote_address );
245
251
handleHTTP2Connection(tls_stream, connection, h2context);
246
252
return ;
247
253
}
@@ -250,7 +256,7 @@ void handleHTTPConnection(TCPConnection connection, HTTPServerContext context)
250
256
}
251
257
}
252
258
253
- handleHTTP1Connection(connection, tls_stream, http_stream, context);
259
+ handleHTTP1Connection(connection, tls_stream, http_stream, context, remote_address );
254
260
255
261
logTrace(" Done handling connection." );
256
262
}
@@ -1900,9 +1906,10 @@ private HTTPListener listenHTTPPlain(HTTPServerSettings settings, HTTPServerRequ
1900
1906
if (reuseAddress) options |= TCPListenOptions.reuseAddress; else options &= ~ TCPListenOptions.reuseAddress;
1901
1907
if (reusePort) options |= TCPListenOptions.reusePort; else options &= ~ TCPListenOptions.reusePort;
1902
1908
auto ret = listenTCP(listen_info.bindPort, (TCPConnection conn) nothrow @safe {
1903
- try handleHTTPConnection (conn, listen_info);
1909
+ auto raddr = conn.remoteAddress;
1910
+ try handleHTTPConnection (conn, listen_info, raddr);
1904
1911
catch (Exception e) {
1905
- logError(" HTTP connection handler has thrown at the peer %s: %s" , conn.peerAddress , e.msg);
1912
+ logError(" HTTP connection handler has thrown at the peer %s: %s" , raddr , e.msg);
1906
1913
debug logDebug(" Full error: %s" , () @trusted { return e.toString().sanitize(); } ());
1907
1914
try conn.close();
1908
1915
catch (Exception e) logError(" Failed to close connection: %s" , e.msg);
0 commit comments