3131import java .net .URI ;
3232import java .net .http .HttpClient ;
3333import java .net .http .HttpHeaders ;
34+ import java .net .http .HttpTimeoutException ;
3435import java .nio .charset .StandardCharsets ;
3536import java .time .Duration ;
3637import java .time .Instant ;
4142import java .util .Collections ;
4243import java .util .List ;
4344import java .util .Map ;
45+ import java .util .Set ;
4446import java .util .concurrent .CompletableFuture ;
4547import java .util .concurrent .CopyOnWriteArrayList ;
4648import java .util .concurrent .CountDownLatch ;
4749import java .util .concurrent .ExecutionException ;
50+ import java .util .concurrent .Executors ;
51+ import java .util .concurrent .ScheduledExecutorService ;
4852import java .util .concurrent .TimeUnit ;
4953
5054import javax .net .ssl .SSLHandshakeException ;
@@ -131,6 +135,27 @@ void oversizedAnswerRefused() throws Exception {
131135 }
132136 }
133137
138+ @ Test
139+ void deadlineEndsSilentBody () throws Exception {
140+ try (TestHttpEndpoint endpoint = new TestHttpEndpoint (offer -> "v=0 and the rest" , 201 )) {
141+ endpoint .stallBodies ();
142+ CountDownLatch head = new CountDownLatch (1 );
143+ HttpCall call = new HttpCall (HttpCall .newClient (false ), endpoint .uri (), "POST" , null ,
144+ Duration .ofSeconds (2 ));
145+ CompletableFuture <HttpCall .Response > response = call .send ("application/sdp" , new byte [] { 'o' },
146+ 1024 , received -> head .countDown ());
147+ try {
148+ assertTrue (head .await (TIMEOUT_SECONDS , TimeUnit .SECONDS ));
149+ ExecutionException failed = assertThrows (ExecutionException .class , () -> await (response ));
150+ assertInstanceOf (HttpTimeoutException .class , failed .getCause ());
151+ endpoint .awaitHangUp (TIMEOUT_SECONDS );
152+ }
153+ finally {
154+ call .abort ();
155+ }
156+ }
157+ }
158+
134159 @ Test
135160 void abortEndsRead () throws Exception {
136161 // The server sends the head and half the answer, then waits. An abort
@@ -276,6 +301,29 @@ void tunnelRefusesBasicByDefault() throws Exception {
276301 }
277302 }
278303
304+ @ Test
305+ void overflowingRetryDateReturnsResponse () throws Exception {
306+ ScheduledExecutorService timer = Executors .newSingleThreadScheduledExecutor ();
307+ try (TestHttpEndpoint endpoint = new TestHttpEndpoint (offer -> "come back later" , 201 )) {
308+ endpoint .answerStatus = 503 ;
309+ endpoint .answerHeaders = "Retry-After: 31 Dec 999999999 23:59:59 GMT\r \n " ;
310+ HttpCall call = post (HttpCall .newClient (false ), endpoint .uri ()).retry (timer , Set .of (503 ));
311+ try {
312+ HttpCall .Response response = await (call .send ("application/sdp" , new byte [] { 'o' }, 1024 ,
313+ head -> { }));
314+ assertEquals (503 , response .status );
315+ assertEquals ("come back later" , response .body );
316+ assertEquals (1 , endpoint .requests .size ());
317+ }
318+ finally {
319+ call .abort ();
320+ }
321+ }
322+ finally {
323+ timer .shutdownNow ();
324+ }
325+ }
326+
279327 @ Test
280328 void retryAfterRead () {
281329 long now = 1_000_000_000_000L ;
@@ -289,6 +337,7 @@ void retryAfterRead() {
289337 assertEquals (5000 , HttpCall .retryDelayMillis (inFive , now ));
290338 assertEquals (0 , HttpCall .retryDelayMillis (past , now ));
291339 assertEquals (Long .MAX_VALUE , HttpCall .retryDelayMillis ("99999999999999999999" , now ));
340+ assertEquals (-1 , HttpCall .retryDelayMillis ("31 Dec 999999999 23:59:59 GMT" , now ));
292341 assertEquals (-1 , HttpCall .retryDelayMillis ("soon" , now ));
293342 assertEquals (-1 , HttpCall .retryDelayMillis ("" , now ));
294343 assertEquals (-1 , HttpCall .retryDelayMillis (null , now ));
0 commit comments