From 95d2855f62aa31cfc65f270811c71edc43476aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 3 May 2017 17:44:00 +0200 Subject: Add the idle_timeout HTTP/1.1 protocol option This fixes the connection being dropped because of request_timeout despite there being some active streams. --- test/handlers/loop_handler_timeout_h.erl | 15 ++++++++------- test/loop_handler_SUITE.erl | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/handlers/loop_handler_timeout_h.erl b/test/handlers/loop_handler_timeout_h.erl index 1628074..7061dbe 100644 --- a/test/handlers/loop_handler_timeout_h.erl +++ b/test/handlers/loop_handler_timeout_h.erl @@ -1,8 +1,9 @@ %% This module implements a loop handler that sends %% itself a timeout that will intentionally arrive -%% too late, as it configures itself to only wait -%% 200ms before closing the connection in init/2. -%% This results in a 204 reply being sent back by Cowboy. +%% after the HTTP/1.1 request_timeout. The protocol +%% is not supposed to close the connection when a +%% request is ongoing, and therefore this handler +%% will eventually send a 200 reply. -module(loop_handler_timeout_h). @@ -11,11 +12,11 @@ -export([terminate/3]). init(Req, _) -> - erlang:send_after(1000, self(), timeout), - {cowboy_loop, Req, undefined, hibernate}. + erlang:send_after(6000, self(), timeout), + {cowboy_loop, Req, #{hibernate => true}}. info(timeout, Req, State) -> - {stop, cowboy_req:reply(500, Req), State}. + {stop, cowboy_req:reply(200, #{}, <<"Good!">>, Req), State}. -terminate(timeout, _, _) -> +terminate(stop, _, _) -> ok. diff --git a/test/loop_handler_SUITE.erl b/test/loop_handler_SUITE.erl index 5feb032..6e7993f 100644 --- a/test/loop_handler_SUITE.erl +++ b/test/loop_handler_SUITE.erl @@ -83,9 +83,9 @@ loop_body(Config) -> {response, fin, 200, _} = gun:await(ConnPid, Ref), ok. -loop_timeout(Config) -> - doc("Ensure that the loop handler timeout results in a 204 response."), +loop_request_timeout(Config) -> + doc("Ensure that the request_timeout isn't applied when a request is ongoing."), ConnPid = gun_open(Config), Ref = gun:get(ConnPid, "/loop_timeout", [{<<"accept-encoding">>, <<"gzip">>}]), - {response, fin, 204, _} = gun:await(ConnPid, Ref), + {response, nofin, 200, _} = gun:await(ConnPid, Ref, 10000), ok. -- cgit v1.2.3