Skip to content

Instantly share code, notes, and snippets.

@nikushi
Last active December 29, 2015 23:59
Show Gist options
  • Select an option

  • Save nikushi/7746158 to your computer and use it in GitHub Desktop.

Select an option

Save nikushi/7746158 to your computer and use it in GitHub Desktop.
GF->rack-streaming-proxy->webrickのレスポンスストリームで、GFからわたってきたチャンクデータをwebrickがContent-Lenghtヘッダを付けてしまう。
[242, 261] in /Users/nikushi.nobuhiro/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/httpresponse.rb
   242:       if @status == 304 || @status == 204 || HTTPStatus::info?(@status)
   243:         @header.delete('content-length')
   244:         @body = ""
   245:       elsif chunked?
   246:         @header["transfer-encoding"] = "chunked"
   247:         @header.delete('content-length')
   248:       elsif %r{^multipart/byteranges} =~ @header['content-type']
   249:         @header.delete('content-length')
   250:       elsif @header['content-length'].nil?
   251:         unless @body.is_a?(IO)
=> 252:           @header['content-length'] = @body ? @body.bytesize : 0
   253:         end
   254:       end
   255:
   256:       # Keep-Alive connection.
   257:       if @header['connection'] == "close"
   258:          @keep_alive = false
   259:       elsif keep_alive?
   260:         if chunked? || @header['content-length'] || @status == 304 || @status == 204 || HTTPStatus.info?(@status)
   261:           @header['connection'] = "Keep-Alive"
(byebug) pp @header
{"date"=>"Mon, 02 Dec 2013 07:27:32 GMT",
 "server"=>"Plack::Handler::Starlet",
 "content-type"=>"image/png",
 "x-frame-options"=>"DENY",
 "x-xss-protection"=>"1",
 "x-powered-by"=>"GrowthForecast/0.72",
 "transfer-encoding"=>"chunked",
 "connection"=>"close",
 "cache-control"=>"no-cache",
 "x-request-id"=>"ca888f6b-32de-49df-86bd-bf399560865d",
 "x-runtime"=>"15.869122"}
(byebug) n
[247, 266] in /Users/nikushi.nobuhiro/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/httpresponse.rb
   247:         @header.delete('content-length')
   248:       elsif %r{^multipart/byteranges} =~ @header['content-type']
   249:         @header.delete('content-length')
   250:       elsif @header['content-length'].nil?
   251:         unless @body.is_a?(IO)
   252:           @header['content-length'] = @body ? @body.bytesize : 0
   253:         end
   254:       end
   255:
   256:       # Keep-Alive connection.
=> 257:       if @header['connection'] == "close"
   258:          @keep_alive = false
   259:       elsif keep_alive?
   260:         if chunked? || @header['content-length'] || @status == 304 || @status == 204 || HTTPStatus.info?(@status)
   261:           @header['connection'] = "Keep-Alive"
   262:         else
   263:           msg = "Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true"
   264:           @logger.warn(msg)
   265:           @header['connection'] = "close"
   266:           @keep_alive = false
(byebug) pp @header
{"date"=>"Mon, 02 Dec 2013 07:27:32 GMT",
 "server"=>"Plack::Handler::Starlet",
 "content-type"=>"image/png",
 "x-frame-options"=>"DENY",
 "x-xss-protection"=>"1",
 "x-powered-by"=>"GrowthForecast/0.72",
 "transfer-encoding"=>"chunked",
 "connection"=>"close",
 "cache-control"=>"no-cache",
 "x-request-id"=>"ca888f6b-32de-49df-86bd-bf399560865d",
 "x-runtime"=>"15.869122",
 "content-length"=>10396}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment