ledgetech / ledge

An RFC compliant and ESI capable HTTP cache for Nginx / OpenResty, backed by Redis
453 stars 59 forks source link

IPV6 server name fails #169

Open magnNorth opened 6 years ago

magnNorth commented 6 years ago

Hey, trying to pass an ipv6 request through esi make thing fall over. https://github.com/pintsized/ledge/blob/35bbcdadc55f65c1c3e43f0ebd054868e345eb94/lib/ledge/esi.lua#L366

the error esi.lua:373: esi_fetch_include(): failed to parse host name "9999:da0:a8:f610::f:316": invalid port connecting to 9999:da0:a8:f610::f:316:443

suggests that the format of the request is incorrect. Testing with simple curls: curl -g -6 https://9999:da0:a8:f610::f:316:443 - fails while curl -g -6 https://[9999:da0:a8:f610::f:316]:443 - work just fine.

I have bypassed the effect of this code block ` local upstream = host

   if upstream == ngx_var.http_host then
        upstream = ngx_var.server_addr
        port = ngx_var.server_port
    end

` by ignoring the reassignment of upstream = ngx_var.server_addr. doing this makes the system work correctly but ultimately the detection and correct request for the IPV6 server_addr would be a better solution.

hamishforbes commented 6 years ago

Yeah looks like ngx.socket.tcp requires ipv6 addresses to be wrapped as well, but hte server_addr var doesn't wrap them. https://github.com/openresty/lua-nginx-module/blob/90d7522342e78ecb1f1ea2b5d066ade404a48b24/t/058-tcp-socket.t#L3251

I guess we'll have to detect ipv6 server_addr values and wrap them ourselves!