Last active
December 22, 2015 01:19
-
-
Save CootCraig/6395964 to your computer and use it in GitHub Desktop.
Demonstration of reel (0.4.0.pre) http responses returning incorrect reel (0.4.0.pre)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
require 'celluloid/autostart' | |
require 'reel' | |
require 'json' | |
module Test | |
APP_LOGGER = Logger.new('log.txt'); | |
Celluloid.logger = APP_LOGGER | |
APP_LOGGER.debug "hello" | |
class WebServer < Reel::Server | |
EXTRA_HEADERS = { :'Access-Control-Allow-Origin' => '*' } | |
def initialize | |
@silly_counter = 10000 | |
@data = [] | |
host = '0.0.0.0' | |
port = 8091 | |
APP_LOGGER.debug "---\n---\n---\nWebServer starting host #{host} port #{port}" | |
super(host, port, &method(:on_connection)) | |
end | |
def on_connection(connection) | |
while request = connection.request | |
@silly_counter += 1 | |
@data << @silly_counter.to_s | |
payload = @data.to_json | |
APP_LOGGER.debug "respond with length #{payload.length} payload |#{payload}|" | |
connection.respond :ok, EXTRA_HEADERS, payload | |
end | |
end | |
end | |
Celluloid::Actor[:web_server] = WebServer.new | |
sleep | |
end | |
=begin | |
Author: Craig Anderson craig@coot.net | |
Demonstrate a reel (0.4.0.pre), celluloid (0.15.0.pre2) application | |
where a series of get's are done with a text body returned. The text | |
body is increased in size on ezch get. The Content-Length:9 of the first | |
response body is correct, but the same Content-Length:9 is returned with | |
each subsequent response, so the body is truncated by the browser. | |
$ which jruby | |
/opt/ruby/jruby/bin/jruby | |
$ which bundle | |
/opt/ruby/jruby/bin/bundle | |
$ jruby -v | |
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM) 64-Bit Server VM 1.7.0_25-b15 [linux-amd64] | |
$ bundle install | |
$ bundle list | |
Gems included by the bundle: | |
* bundler (1.3.5) | |
* celluloid (0.15.0.pre2) | |
* celluloid-io (0.14.1) | |
* certified (0.1.1) | |
* http (0.4.0) | |
* http_parser.rb (0.5.3) | |
* nio4r (0.5.0) | |
* rack (1.5.2) | |
* reel (0.4.0.pre) | |
* timers (1.1.0) | |
* websocket_parser (0.1.4) | |
$ jruby app.rb | |
Using developer tools in chromium browser: | |
Version 28.0.1500.71 Ubuntu 13.04 (28.0.1500.71-0ubuntu1.13.04.1) | |
The following log mixes the browser request, browser output, response headers and log file text. | |
--- request | |
http://localhost:8091/ | |
--- response | |
Access-Control-Allow-Origin:* | |
Connection:Keep-Alive | |
Content-Length:9 | |
["10001"] | |
--- log | |
D, [2013-08-30T20:26:23.927000 #4331] DEBUG -- : respond with length 9 payload |["10001"]| | |
--- request | |
http://localhost:8091/ | |
--- response | |
Access-Control-Allow-Origin:* | |
Connection:Keep-Alive | |
Content-Length:9 | |
["10001", | |
--- log | |
D, [2013-08-30T20:29:45.530000 #4331] DEBUG -- : respond with length 17 payload |["10001","10002"]| | |
--- request | |
http://localhost:8091/ | |
--- response | |
Access-Control-Allow-Origin:* | |
Connection:Keep-Alive | |
Content-Length:9 | |
["10001", | |
--- log | |
D, [2013-08-30T20:31:44.061000 #4331] DEBUG -- : respond with length 25 payload |["10001","10002","10003"]| | |
=end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem "celluloid", "~> 0.15.0.pre" | |
gem "reel", "~> 0.4.0.pre" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GEM | |
remote: https://rubygems.org/ | |
specs: | |
celluloid (0.15.0.pre2) | |
timers (>= 1.0.0) | |
celluloid-io (0.14.1) | |
celluloid (>= 0.14.1) | |
nio4r (>= 0.4.5) | |
certified (0.1.1) | |
http (0.4.0) | |
certified | |
http_parser.rb | |
http_parser.rb (0.5.3-java) | |
nio4r (0.5.0-java) | |
rack (1.5.2) | |
reel (0.4.0.pre) | |
celluloid-io (>= 0.8.0) | |
http (>= 0.2.0) | |
http_parser.rb (>= 0.5.3) | |
rack (>= 1.4.0) | |
websocket_parser (>= 0.1.2) | |
timers (1.1.0) | |
websocket_parser (0.1.4) | |
http | |
PLATFORMS | |
java | |
DEPENDENCIES | |
celluloid (~> 0.15.0.pre) | |
reel (~> 0.4.0.pre) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
With this change headers[CONTENT_LENGTH] is not present when the check/assignment | |
of length is done. The example works correctly. | |
$ diff response.rb.orig response.rb | |
21c21 | |
< headers = body_or_headers | |
--- | |
> headers = {}.merge body_or_headers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is setting the headers[CONTENT_LENGTH] on the first call
and then leaving it alone on subsequent calls
jruby-1.7.4/lib/ruby/gems/shared/gems/reel-0.4.0.pre/lib/reel/response.rb:
module Reel
class Response
...
def initialize(status, body_or_headers = nil, body = nil)
...
case @Body
when String
headers[CONTENT_LENGTH] ||= @body.bytesize
when IO
headers[CONTENT_LENGTH] ||= @Body.stat.size