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:
parent
e4a4eb964e
commit
ba27787d0d
2 changed files with 8 additions and 4 deletions
|
@ -1,5 +1,3 @@
|
||||||
require 'set'
|
|
||||||
|
|
||||||
module Puma
|
module Puma
|
||||||
|
|
||||||
# Every standard HTTP code mapped to the appropriate message. These are
|
# 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.
|
# 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
|
# Frequently used constants when constructing requests or responses. Many times
|
||||||
# the constant just refers to a string with the same contents. Using these constants
|
# the constant just refers to a string with the same contents. Using these constants
|
||||||
|
|
|
@ -341,7 +341,7 @@ module Puma
|
||||||
end
|
end
|
||||||
|
|
||||||
content_length = nil
|
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
|
if res_body.kind_of? Array and res_body.size == 1
|
||||||
content_length = res_body[0].size
|
content_length = res_body[0].size
|
||||||
|
@ -366,6 +366,8 @@ module Puma
|
||||||
client.write " "
|
client.write " "
|
||||||
client.write HTTP_STATUS_CODES[status]
|
client.write HTTP_STATUS_CODES[status]
|
||||||
client.write "\r\n"
|
client.write "\r\n"
|
||||||
|
|
||||||
|
no_body = status < 200 || STATUS_WITH_NO_ENTITY_BODY[status]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
allow_chunked = false
|
allow_chunked = false
|
||||||
|
@ -382,6 +384,8 @@ module Puma
|
||||||
client.write " "
|
client.write " "
|
||||||
client.write HTTP_STATUS_CODES[status]
|
client.write HTTP_STATUS_CODES[status]
|
||||||
client.write "\r\n"
|
client.write "\r\n"
|
||||||
|
|
||||||
|
no_body = status < 200 || STATUS_WITH_NO_ENTITY_BODY[status]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue