From 69ef43ba003c7dd5025d904d37256376aae911d7 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 16 Jul 2020 21:23:35 +0200 Subject: [PATCH] vweb: fix ip() --- vlib/vweb/vweb.v | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 5abb934891..d17d3c4431 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -508,9 +508,17 @@ pub fn (mut ctx Context) serve_static(url, file_path, mime_type string) { } pub fn (ctx &Context) ip() string { + mut ip := ctx.req.headers['X-Forwarded-For'] + if ip == '' { + ip = ctx.req.headers['X-Real-IP'] + } + if ip.contains(',') { + ip = ip.all_before(',') + } + return ip // TODO make return ctx.conn.peer_ip() or { '' } work - res := ctx.conn.peer_ip() or { '' } - return res + //res := ctx.conn.peer_ip() or { '' } + //return res } pub fn (mut ctx Context) error(s string) {