Skip to content

Commit

Permalink
add support for 100-continue in HTTP::Server::Response
Browse files Browse the repository at this point in the history
  • Loading branch information
Joakim Reinert committed Oct 6, 2018
1 parent 4fb09af commit 76dc76c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/std/http/server/server_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions src/http/server/response.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 76dc76c

Please sign in to comment.