Skip to content

Commit 077f183

Browse files
committed
test: add tests to check pool_only_after_response
1 parent 69a4afd commit 077f183

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

Diff for: t/07-keepalive.t

+90
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,93 @@ connection must be closed
432432
--- no_error_log
433433
[error]
434434
[warn]
435+
436+
=== TEST 8 Generic interface, Connection: Keep-alive. pool_only_after_response is on. Test the connection is reused.
437+
--- http_config eval: $::HttpConfig
438+
--- config
439+
location = /a {
440+
content_by_lua '
441+
local http = require "resty.http"
442+
local httpc = http.new()
443+
httpc:connect({
444+
scheme = "http",
445+
host = "127.0.0.1",
446+
port = ngx.var.server_port,
447+
pool_only_after_response = true
448+
})
449+
450+
local res, err = httpc:request{
451+
path = "/b"
452+
}
453+
454+
local body = res:read_body()
455+
456+
ngx.say(res.headers["Connection"])
457+
ngx.say(httpc:set_keepalive())
458+
459+
httpc:connect({
460+
scheme = "http",
461+
host = "127.0.0.1",
462+
port = ngx.var.server_port
463+
})
464+
ngx.say(httpc:get_reused_times())
465+
';
466+
}
467+
location = /b {
468+
content_by_lua '
469+
ngx.say("OK")
470+
';
471+
}
472+
--- request
473+
GET /a
474+
--- response_body
475+
keep-alive
476+
1
477+
1
478+
--- no_error_log
479+
[error]
480+
[warn]
481+
482+
=== TEST 9 Generic interface, Connection: Keep-alive. pool_only_after_response is on. Don't read body and check connection isn't reused
483+
--- http_config eval: $::HttpConfig
484+
--- config
485+
location = /a {
486+
content_by_lua '
487+
local http = require "resty.http"
488+
local httpc = http.new()
489+
httpc:connect({
490+
scheme = "http",
491+
host = "127.0.0.1",
492+
port = ngx.var.server_port,
493+
pool_only_after_response = true
494+
})
495+
496+
local res, err = httpc:request{
497+
path = "/b"
498+
}
499+
500+
ngx.say(res.headers["Connection"])
501+
ngx.say(httpc:set_keepalive())
502+
503+
httpc:connect({
504+
scheme = "http",
505+
host = "127.0.0.1",
506+
port = ngx.var.server_port
507+
})
508+
ngx.say(httpc:get_reused_times())
509+
';
510+
}
511+
location = /b {
512+
content_by_lua '
513+
ngx.say("OK")
514+
';
515+
}
516+
--- request
517+
GET /a
518+
--- response_body
519+
keep-alive
520+
0
521+
0
522+
--- no_error_log
523+
[error]
524+
[warn]

0 commit comments

Comments
 (0)