diff --git a/spec/std/http/server/server_spec.cr b/spec/std/http/server/server_spec.cr index e57b774a47e2..48a5e8bb5c17 100644 --- a/spec/std/http/server/server_spec.cr +++ b/spec/std/http/server/server_spec.cr @@ -216,6 +216,15 @@ module HTTP response.respond_with_error("Bad Request", 400) io.to_s.should eq("HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n10\r\n400 Bad Request\n\r\n") end + + it "supports 100-continue" do + io = IO::Memory.new + response = Response.new(io) + response.continue + response.content_type = "text/html" + response << "test" + io.to_s.should eq("HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 200\r\n\r\ntest\r\n") + end end end diff --git a/src/http/server/response.cr b/src/http/server/response.cr index 615bec1dcaf5..6d11a00b6f07 100644 --- a/src/http/server/response.cr +++ b/src/http/server/response.cr @@ -79,6 +79,15 @@ class HTTP::Server raise "Can't read from HTTP::Server::Response" end + # Send a 100 Continue response to clients waiting for this before sending + # the request body + def continue + @status_code = 100 + write_headers + flush + reset + end + # Upgrades this response, writing headers and yieling the connection `IO` (a socket) to the given block. # The block must invoke `close` afterwards, the server won't do it in this case. # This is useful to implement protocol upgrades, such as websockets.