@@ -327,6 +327,84 @@ defmodule Mint.HTTP1Test do
327327 assert conn . buffer == "XXX"
328328 end
329329
330+ test "100 Continue informational response followed by final response" , % { conn: conn } do
331+ { :ok , conn , ref } = HTTP1 . request ( conn , "POST" , "/" , [ { "expect" , "100-continue" } ] , "hello" )
332+
333+ response =
334+ "HTTP/1.1 100 Continue\r \n \r \n " <>
335+ "HTTP/1.1 201 Created\r \n content-length: 2\r \n \r \n ok"
336+
337+ assert { :ok , conn ,
338+ [
339+ { :status , ^ ref , 100 } ,
340+ { :headers , ^ ref , [ ] } ,
341+ { :status , ^ ref , 201 } ,
342+ { :headers , ^ ref , [ { "content-length" , "2" } ] } ,
343+ { :data , ^ ref , "ok" } ,
344+ { :done , ^ ref }
345+ ] } = HTTP1 . stream ( conn , { :tcp , conn . socket , response } )
346+
347+ assert HTTP1 . open? ( conn )
348+ end
349+
350+ test "103 Early Hints informational response followed by final response" , % { conn: conn } do
351+ { :ok , conn , ref } = HTTP1 . request ( conn , "GET" , "/" , [ ] , nil )
352+
353+ response =
354+ "HTTP/1.1 103 Early Hints\r \n link: </style.css>; rel=preload\r \n \r \n " <>
355+ "HTTP/1.1 200 OK\r \n content-length: 2\r \n \r \n ok"
356+
357+ assert { :ok , _conn ,
358+ [
359+ { :status , ^ ref , 103 } ,
360+ { :headers , ^ ref , [ { "link" , "</style.css>; rel=preload" } ] } ,
361+ { :status , ^ ref , 200 } ,
362+ { :headers , ^ ref , [ { "content-length" , "2" } ] } ,
363+ { :data , ^ ref , "ok" } ,
364+ { :done , ^ ref }
365+ ] } = HTTP1 . stream ( conn , { :tcp , conn . socket , response } )
366+ end
367+
368+ test "multiple informational responses before final response" , % { conn: conn } do
369+ { :ok , conn , ref } = HTTP1 . request ( conn , "POST" , "/" , [ { "expect" , "100-continue" } ] , "x" )
370+
371+ response =
372+ "HTTP/1.1 100 Continue\r \n \r \n " <>
373+ "HTTP/1.1 103 Early Hints\r \n link: </a>; rel=preload\r \n \r \n " <>
374+ "HTTP/1.1 200 OK\r \n content-length: 2\r \n \r \n ok"
375+
376+ assert { :ok , _conn ,
377+ [
378+ { :status , ^ ref , 100 } ,
379+ { :headers , ^ ref , [ ] } ,
380+ { :status , ^ ref , 103 } ,
381+ { :headers , ^ ref , [ { "link" , "</a>; rel=preload" } ] } ,
382+ { :status , ^ ref , 200 } ,
383+ { :headers , ^ ref , [ { "content-length" , "2" } ] } ,
384+ { :data , ^ ref , "ok" } ,
385+ { :done , ^ ref }
386+ ] } = HTTP1 . stream ( conn , { :tcp , conn . socket , response } )
387+ end
388+
389+ test "informational response split across multiple TCP messages" , % { conn: conn } do
390+ { :ok , conn , ref } = HTTP1 . request ( conn , "POST" , "/" , [ { "expect" , "100-continue" } ] , "x" )
391+
392+ assert { :ok , conn , [ { :status , ^ ref , 100 } , { :headers , ^ ref , [ ] } ] } =
393+ HTTP1 . stream ( conn , { :tcp , conn . socket , "HTTP/1.1 100 Continue\r \n \r \n " } )
394+
395+ assert { :ok , _conn ,
396+ [
397+ { :status , ^ ref , 201 } ,
398+ { :headers , ^ ref , [ { "content-length" , "2" } ] } ,
399+ { :data , ^ ref , "ok" } ,
400+ { :done , ^ ref }
401+ ] } =
402+ HTTP1 . stream (
403+ conn ,
404+ { :tcp , conn . socket , "HTTP/1.1 201 Created\r \n content-length: 2\r \n \r \n ok" }
405+ )
406+ end
407+
330408 test "body following a 101 switching-protocols" , % { conn: conn } do
331409 { :ok , conn , ref } = HTTP1 . request ( conn , "GET" , "/socket/websocket" , [ ] , nil )
332410
0 commit comments