mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:19:27 +08:00
Revert "PERF: send Content-Length from Rails on all requests"
This reverts commit ea0e238ae1
.
Does not seem needed reverting
This commit is contained in:
parent
c5f9ae0de1
commit
e451d47e84
|
@ -1,37 +0,0 @@
|
|||
# Just like Rack except we dont do a to_ary check so we can calculate length
|
||||
# on body proxy objects
|
||||
# Sets the Content-Length header on responses with fixed-length bodies.
|
||||
class ContentLength
|
||||
TRANSFER_ENCODING = "Transfer-Encoding".freeze
|
||||
CONTENT_LENGTH = "Content-Length".freeze
|
||||
|
||||
include Rack::Utils
|
||||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
status, headers, body = @app.call(env)
|
||||
|
||||
if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) &&
|
||||
!headers[CONTENT_LENGTH] &&
|
||||
!headers[TRANSFER_ENCODING]
|
||||
|
||||
obody = body
|
||||
body, length = [], 0
|
||||
obody.each { |part| body << part; length += part.bytesize }
|
||||
|
||||
body = Rack::BodyProxy.new(body) do
|
||||
obody.close if obody.respond_to?(:close)
|
||||
end
|
||||
|
||||
headers[CONTENT_LENGTH] = length.to_s
|
||||
end
|
||||
|
||||
[status, headers, body]
|
||||
end
|
||||
end
|
||||
|
||||
# content length helps us instruct NGINX on how to deal with this
|
||||
Rails.configuration.middleware.unshift ContentLength
|
Loading…
Reference in New Issue
Block a user