From e4c769d0720c4484d7b1d4e609f077c9f4ea70f7 Mon Sep 17 00:00:00 2001 From: xiusin <36065131+xiusin@users.noreply.github.com> Date: Sun, 21 May 2023 21:23:24 +0800 Subject: [PATCH] net.http: add remote-addr header (#18208) --- vlib/net/http/server.v | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vlib/net/http/server.v b/vlib/net/http/server.v index 64acc0a126..89e92566c5 100644 --- a/vlib/net/http/server.v +++ b/vlib/net/http/server.v @@ -100,13 +100,17 @@ fn (mut s Server) parse_and_respond(mut conn net.TcpConn) { reader.free() } } - req := parse_request(mut reader) or { + mut req := parse_request(mut reader) or { $if debug { // only show in debug mode to prevent abuse eprintln('error parsing request: ${err}') } return } + + remote_ip := conn.peer_ip() or { '' } + req.header.add_custom('Remote-Addr', remote_ip) or {} + mut resp := s.handler.handle(req) if resp.version() == .unknown { resp.set_version(req.version)