| @@ -98,6 +98,8 @@ fn handler :: req: Request -> http.Response |
| 98 | 98 | { |
| 99 | 99 | match http.path req |
| 100 | 100 | { "/hello" -> http.text 200 "hello" |
| 101 | + , "/no-content" -> no_body_response 204 |
| 102 | + , "/not-modified" -> no_body_response 304 |
| 101 | 103 | , "/chunked" -> |
| 102 | 104 | http.Response( 200 |
| 103 | 105 | , [("Content-Type", "text/plain")] |
| @@ -126,6 +128,14 @@ fn handler :: req: Request -> http.Response |
| 126 | 128 | } |
| 127 | 129 | } |
| 128 | 130 | |
| 131 | +fn no_body_response :: status: Int -> http.Response |
| 132 | +{ |
| 133 | + http.Response( status |
| 134 | + , [("ETag", "\"v1\""), ("Cache-Control", "max-age=60")] |
| 135 | + , Whole(bytes.from_string "not sent") |
| 136 | + ) |
| 137 | +} |
| 138 | + |
| 129 | 139 | fn pieces :: w: http.Writer texts: List<String> -> () / <io, proc> |
| 130 | 140 | { |
| 131 | 141 | match texts |
| @@ -281,6 +291,33 @@ fn a_body_by_content_length :: -> () / <io, proc, clock> |
| 281 | 291 | } |
| 282 | 292 | |
| 283 | 293 | @test |
| 294 | +fn statuses_without_bodies_reach_the_client :: -> () / <io, proc, clock> |
| 295 | +{ |
| 296 | + if enabled () |
| 297 | + { |
| 298 | + let port = http_server 2 |
| 299 | + let no_content = |
| 300 | + fetch.get (at "http://127.0.0.1:{port}/no-content") [] (local ()) |
| 301 | + assert_equal (body_text no_content) Ok((204, "", False)) |
| 302 | + match no_content |
| 303 | + { Ok(resp) -> |
| 304 | + { |
| 305 | + assert_equal (fetch.header resp "ETag") Some("\"v1\"") |
| 306 | + assert_equal (fetch.header resp "Cache-Control") Some("max-age=60") |
| 307 | + } |
| 308 | + , Error(e) -> panic (show e) |
| 309 | + } |
| 310 | + let not_modified = |
| 311 | + fetch.get (at "http://127.0.0.1:{port}/not-modified") [] (local ()) |
| 312 | + assert_equal (body_text not_modified) Ok((304, "", False)) |
| 313 | + match not_modified |
| 314 | + { Ok(resp) -> assert_equal (fetch.header resp "ETag") Some("\"v1\"") |
| 315 | + , Error(e) -> panic (show e) |
| 316 | + } |
| 317 | + } |
| 318 | +} |
| 319 | + |
| 320 | +@test |
| 284 | 321 | fn a_chunked_body :: -> () / <io, proc, clock> |
| 285 | 322 | { |
| 286 | 323 | if enabled () |