Skip to content

Commit c9128e5

Browse files
committed
tests: added a passing test case for connecting to IPv6 addresses via cosockets.
1 parent 4323f3b commit c9128e5

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

t/058-tcp-socket.t

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use Test::Nginx::Socket::Lua;
55

66
repeat_each(2);
77

8-
plan tests => repeat_each() * 169;
8+
plan tests => repeat_each() * 172;
99

1010
our $HtmlDir = html_dir;
1111

@@ -3220,3 +3220,77 @@ close: 1 nil
32203220
lua socket tcp_nodelay
32213221
[error]
32223222
3223+
3224+
3225+
=== TEST 54: IPv6
3226+
--- http_config
3227+
server_tokens off;
3228+
3229+
server {
3230+
listen [::1]:$TEST_NGINX_PORT;
3231+
3232+
location /foo {
3233+
content_by_lua 'ngx.say("foo")';
3234+
more_clear_headers Date;
3235+
}
3236+
}
3237+
--- config
3238+
location /t {
3239+
#set $port 5000;
3240+
set $port $TEST_NGINX_SERVER_PORT;
3241+
3242+
content_by_lua '
3243+
local sock = ngx.socket.tcp()
3244+
local port = ngx.var.port
3245+
local ok, err = sock:connect("[::1]", port)
3246+
if not ok then
3247+
ngx.say("failed to connect: ", err)
3248+
return
3249+
end
3250+
3251+
ngx.say("connected: ", ok)
3252+
3253+
local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
3254+
-- req = "OK"
3255+
3256+
local bytes, err = sock:send(req)
3257+
if not bytes then
3258+
ngx.say("failed to send request: ", err)
3259+
return
3260+
end
3261+
3262+
ngx.say("request sent: ", bytes)
3263+
3264+
while true do
3265+
local line, err, part = sock:receive()
3266+
if line then
3267+
ngx.say("received: ", line)
3268+
3269+
else
3270+
ngx.say("failed to receive a line: ", err, " [", part, "]")
3271+
break
3272+
end
3273+
end
3274+
3275+
ok, err = sock:close()
3276+
ngx.say("close: ", ok, " ", err)
3277+
';
3278+
}
3279+
3280+
--- request
3281+
GET /t
3282+
--- response_body
3283+
connected: 1
3284+
request sent: 57
3285+
received: HTTP/1.1 200 OK
3286+
received: Server: nginx
3287+
received: Content-Type: text/plain
3288+
received: Content-Length: 4
3289+
received: Connection: close
3290+
received:
3291+
received: foo
3292+
failed to receive a line: closed []
3293+
close: 1 nil
3294+
--- no_error_log
3295+
[error]
3296+

util/build2.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ force=$2
1919
#--without-http_referer_module \
2020

2121
time ngx-build $force $version \
22+
--with-ipv6 \
2223
--with-cc-opt="-I$PCRE_INC" \
2324
--with-http_realip_module \
2425
--with-http_ssl_module \

0 commit comments

Comments
 (0)