Skip to content

Commit

Permalink
Use #respond_with_status in handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Aug 13, 2019
1 parent 3d5f9e8 commit c54586f
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion spec/std/http/server/handlers/handler_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ describe HTTP::Handler do
io.rewind
response = HTTP::Client::Response.from_io(io)
response.status_code.should eq(404)
response.body.should eq("Not Found\n")
response.body.should eq("404 Not Found\n")
end
end
2 changes: 1 addition & 1 deletion spec/std/http/server/handlers/websocket_handler_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe HTTP::WebSocketHandler do

response.close

io.to_s.should eq("HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\n\r\n")
io.to_s.should eq("HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain\r\nContent-Length: 16\r\n\r\n400 Bad Request\n")
end

it "returns upgrade required if Sec-WebSocket-Version is missing" do
Expand Down
2 changes: 1 addition & 1 deletion src/http/formdata.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require "mime/multipart"
# end
#
# unless name && file
# context.response.status = :bad_request
# context.response.respond_with_status(:bad_request)
# next
# end
#
Expand Down
4 changes: 1 addition & 3 deletions src/http/server/handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ module HTTP::Handler
if next_handler = @next
next_handler.call(context)
else
context.response.status = :not_found
context.response.headers["Content-Type"] = "text/plain"
context.response.puts "Not Found"
context.response.respond_with_status(:not_found)
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/http/server/handlers/static_file_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class HTTP::StaticFileHandler
# File path cannot contains '\0' (NUL) because all filesystem I know
# don't accept '\0' character as file name.
if request_path.includes? '\0'
context.response.status = :bad_request
context.response.respond_with_status(:bad_request)
return
end

Expand Down
2 changes: 1 addition & 1 deletion src/http/server/handlers/websocket_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class HTTP::WebSocketHandler
key = context.request.headers["Sec-WebSocket-Key"]?

unless key
response.status = :bad_request
response.respond_with_status(:bad_request)
return
end

Expand Down

0 comments on commit c54586f

Please sign in to comment.