1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Speed up entity body checking

This commit is contained in:
Evan Phoenix 2011-12-21 09:28:55 -08:00
parent e4a4eb964e
commit ba27787d0d
2 changed files with 8 additions and 4 deletions

View file

@ -1,5 +1,3 @@
require 'set'
module Puma
# Every standard HTTP code mapped to the appropriate message. These are
@ -46,7 +44,9 @@ module Puma
}
# For some HTTP status codes the client only expects headers.
STATUS_WITH_NO_ENTITY_BODY = Set.new((100..199).to_a << 204 << 205 << 304)
STATUS_WITH_NO_ENTITY_BODY = {
204 => true, 205 => true, 304 => true
}
# Frequently used constants when constructing requests or responses. Many times
# the constant just refers to a string with the same contents. Using these constants

View file

@ -341,7 +341,7 @@ module Puma
end
content_length = nil
no_body = STATUS_WITH_NO_ENTITY_BODY.include? status
no_body = false
if res_body.kind_of? Array and res_body.size == 1
content_length = res_body[0].size
@ -366,6 +366,8 @@ module Puma
client.write " "
client.write HTTP_STATUS_CODES[status]
client.write "\r\n"
no_body = status < 200 || STATUS_WITH_NO_ENTITY_BODY[status]
end
else
allow_chunked = false
@ -382,6 +384,8 @@ module Puma
client.write " "
client.write HTTP_STATUS_CODES[status]
client.write "\r\n"
no_body = status < 200 || STATUS_WITH_NO_ENTITY_BODY[status]
end
end