Created
October 22, 2009 10:15
-
-
Save daddz/215878 to your computer and use it in GitHub Desktop.
Rack::Lint::LintError at / rack.input #<StringIO:0x000000024c7348> does not have ASCII-8BIT as its external encoding
This file contains hidden or 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
# /usr/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/lint.rb: in assert | |
11. | |
12. # :stopdoc: | |
13. | |
14. class LintError < RuntimeError; end | |
15. module Assertion | |
16. def assert(message, &block) | |
17. unless block.call | |
18. raise LintError, message... | |
19. end | |
20. end | |
21. end | |
22. include Assertion | |
23. | |
24. ## This specification aims to formalize the Rack protocol. You | |
25. ## can (and should) use Rack::Lint to enforce it. | |
# /usr/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/lint.rb: in check_input | |
233. ## === The Input Stream | |
234. ## | |
235. ## The input stream is an IO-like object which contains the raw HTTP | |
236. ## POST data. | |
237. def check_input(input) | |
238. ## When applicable, its external encoding must be "ASCII-8BIT" and it | |
239. ## must be opened in binary mode, for Ruby 1.9 compatibility. | |
240. assert("rack.input #{input} does not have ASCII-8BIT as its external encoding") {... | |
241. input.external_encoding.name == "ASCII-8BIT" | |
242. } if input.respond_to?(:external_encoding) | |
243. assert("rack.input #{input} is not opened in binary mode") { | |
244. input.binmode? | |
245. } if input.respond_to?(:binmode?) | |
246. | |
247. ## The input stream must respond to +gets+, +each+, +read+ and +rewind+. | |
# /usr/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/lint.rb: in check_env | |
188. } | |
189. ## * <tt>rack.url_scheme</tt> must either be +http+ or +https+. | |
190. assert("rack.url_scheme unknown: #{env["rack.url_scheme"].inspect}") { | |
191. %w[http https].include? env["rack.url_scheme"] | |
192. } | |
193. | |
194. ## * There must be a valid input stream in <tt>rack.input</tt>. | |
195. check_input env["rack.input"]... | |
196. ## * There must be a valid error stream in <tt>rack.errors</tt>. | |
197. check_error env["rack.errors"] | |
198. | |
199. ## * The <tt>REQUEST_METHOD</tt> must be a valid token. | |
200. assert("REQUEST_METHOD unknown: #{env["REQUEST_METHOD"]}") { | |
201. env["REQUEST_METHOD"] =~ /\A[0-9A-Za-z!\#$%&'*+.^_`|~-]+\z/ | |
202. } | |
# /usr/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/lint.rb: in _call | |
34. def call(env=nil) | |
35. dup._call(env) | |
36. end | |
37. | |
38. def _call(env) | |
39. ## It takes exactly one argument, the *environment* | |
40. assert("No env given") { env } | |
41. check_env env... | |
42. | |
43. env['rack.input'] = InputWrapper.new(env['rack.input']) | |
44. env['rack.errors'] = ErrorWrapper.new(env['rack.errors']) | |
45. | |
46. ## and returns an Array of exactly three values: | |
47. status, headers, @body = @app.call(env) | |
48. ## The *status*, | |
# /usr/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/lint.rb: in call | |
28. ## after to catch all mistakes. | |
29. | |
30. ## = Rack applications | |
31. | |
32. ## A Rack application is an Ruby object (not a class) that | |
33. ## responds to +call+. | |
34. def call(env=nil) | |
35. dup._call(env)... | |
36. end | |
37. | |
38. def _call(env) | |
39. ## It takes exactly one argument, the *environment* | |
40. assert("No env given") { env } | |
41. check_env env | |
42. | |
# /usr/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/showexceptions.rb: in call | |
17. | |
18. def initialize(app) | |
19. @app = app | |
20. @template = ERB.new(TEMPLATE) | |
21. end | |
22. | |
23. def call(env) | |
24. @app.call(env)... | |
25. rescue StandardError, LoadError, SyntaxError => e | |
26. backtrace = pretty(env, e) | |
27. [500, | |
28. {"Content-Type" => "text/html", | |
29. "Content-Length" => backtrace.join.size.to_s}, | |
30. backtrace] | |
31. end | |
# /usr/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/commonlogger.rb: in _call | |
13. dup._call(env) | |
14. end | |
15. | |
16. def _call(env) | |
17. @env = env | |
18. @logger ||= self | |
19. @time = Time.now | |
20. @status, @header, @body = @app.call(env)... | |
21. [@status, @header, self] | |
22. end | |
23. | |
24. def close | |
25. @body.close if @body.respond_to? :close | |
26. end | |
27. | |
# /usr/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/commonlogger.rb: in call | |
6. class CommonLogger | |
7. def initialize(app, logger=nil) | |
8. @app = app | |
9. @logger = logger | |
10. end | |
11. | |
12. def call(env) | |
13. dup._call(env)... | |
14. end | |
15. | |
16. def _call(env) | |
17. @env = env | |
18. @logger ||= self | |
19. @time = Time.now | |
20. @status, @header, @body = @app.call(env) | |
# /usr/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/content_length.rb: in call | |
6. include Rack::Utils | |
7. | |
8. def initialize(app) | |
9. @app = app | |
10. end | |
11. | |
12. def call(env) | |
13. status, headers, body = @app.call(env)... | |
14. headers = HeaderHash.new(headers) | |
15. | |
16. if !STATUS_WITH_NO_ENTITY_BODY.include?(status) && | |
17. !headers['Content-Length'] && | |
18. !headers['Transfer-Encoding'] && | |
19. (body.respond_to?(:to_ary) || body.respond_to?(:to_str)) | |
20. | |
# /usr/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/chunked.rb: in call | |
8. include Rack::Utils | |
9. | |
10. def initialize(app) | |
11. @app = app | |
12. end | |
13. | |
14. def call(env) | |
15. status, headers, body = @app.call(env)... | |
16. headers = HeaderHash.new(headers) | |
17. | |
18. if env['HTTP_VERSION'] == 'HTTP/1.0' || | |
19. STATUS_WITH_NO_ENTITY_BODY.include?(status) || | |
20. headers['Content-Length'] || | |
21. headers['Transfer-Encoding'] | |
22. [status, headers.to_hash, body] | |
# /usr/lib/ruby/gems/1.9.1/gems/thin-1.2.4/lib/thin/connection.rb: in block in pre_process | |
69. | |
70. # When we're under a non-async framework like rails, we can still spawn | |
71. # off async responses using the callback info, so there's little point | |
72. # in removing this. | |
73. response = AsyncResponse | |
74. catch(:async) do | |
75. # Process the request calling the Rack adapter | |
76. response = @app.call(@request.env)... | |
77. end | |
78. response | |
79. rescue Exception | |
80. handle_error | |
81. terminate_request | |
82. nil # Signal to post_process that the request could not be processed | |
83. end | |
# /usr/lib/ruby/gems/1.9.1/gems/thin-1.2.4/lib/thin/connection.rb: in catch | |
67. # callback is no longer referenced, so be tidy! | |
68. @request.async_callback = method(:post_process) | |
69. | |
70. # When we're under a non-async framework like rails, we can still spawn | |
71. # off async responses using the callback info, so there's little point | |
72. # in removing this. | |
73. response = AsyncResponse | |
74. catch(:async) do... | |
75. # Process the request calling the Rack adapter | |
76. response = @app.call(@request.env) | |
77. end | |
78. response | |
79. rescue Exception | |
80. handle_error | |
81. terminate_request | |
# /usr/lib/ruby/gems/1.9.1/gems/thin-1.2.4/lib/thin/connection.rb: in pre_process | |
67. # callback is no longer referenced, so be tidy! | |
68. @request.async_callback = method(:post_process) | |
69. | |
70. # When we're under a non-async framework like rails, we can still spawn | |
71. # off async responses using the callback info, so there's little point | |
72. # in removing this. | |
73. response = AsyncResponse | |
74. catch(:async) do... | |
75. # Process the request calling the Rack adapter | |
76. response = @app.call(@request.env) | |
77. end | |
78. response | |
79. rescue Exception | |
80. handle_error | |
81. terminate_request | |
# /usr/lib/ruby/gems/1.9.1/gems/thin-1.2.4/lib/thin/connection.rb: in process | |
50. # is ready to be processed. | |
51. def process | |
52. if threaded? | |
53. @request.threaded = true | |
54. EventMachine.defer(method(:pre_process), method(:post_process)) | |
55. else | |
56. @request.threaded = false | |
57. post_process(pre_process)... | |
58. end | |
59. end | |
60. | |
61. def pre_process | |
62. # Add client info to the request env | |
63. @request.remote_address = remote_address | |
64. | |
# /usr/lib/ruby/gems/1.9.1/gems/thin-1.2.4/lib/thin/connection.rb: in receive_data | |
35. @request = Request.new | |
36. @response = Response.new | |
37. end | |
38. | |
39. # Called when data is received from the client. | |
40. def receive_data(data) | |
41. trace { data } | |
42. process if @request.parse(data)... | |
43. rescue InvalidRequest => e | |
44. log "!! Invalid request" | |
45. log_error e | |
46. close_connection | |
47. end | |
48. | |
49. # Called when all data was received and the request | |
# /usr/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.8/lib/eventmachine.rb: in run_machine | |
235. @reactor_running = true | |
236. initialize_event_machine | |
237. (b = blk || block) and add_timer(0, b) | |
238. if @next_tick_queue && !@next_tick_queue.empty? | |
239. add_timer(0) { signal_loopbreak } | |
240. end | |
241. @reactor_thread = Thread.current | |
242. run_machine... | |
243. ensure | |
244. begin | |
245. release_machine | |
246. ensure | |
247. if @threadpool | |
248. @threadpool.each { |t| t.exit } | |
249. @threadpool.each { |t| t.kill! if t.alive? } | |
# /usr/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.8/lib/eventmachine.rb: in run | |
235. @reactor_running = true | |
236. initialize_event_machine | |
237. (b = blk || block) and add_timer(0, b) | |
238. if @next_tick_queue && !@next_tick_queue.empty? | |
239. add_timer(0) { signal_loopbreak } | |
240. end | |
241. @reactor_thread = Thread.current | |
242. run_machine... | |
243. ensure | |
244. begin | |
245. release_machine | |
246. ensure | |
247. if @threadpool | |
248. @threadpool.each { |t| t.exit } | |
249. @threadpool.each { |t| t.kill! if t.alive? } | |
# /usr/lib/ruby/gems/1.9.1/gems/thin-1.2.4/lib/thin/backends/base.rb: in start | |
50. @running = true | |
51. end | |
52. | |
53. # Allow for early run up of eventmachine. | |
54. if EventMachine.reactor_running? | |
55. starter.call | |
56. else | |
57. EventMachine.run(&starter)... | |
58. end | |
59. end | |
60. | |
61. # Stop of the backend from accepting new connections. | |
62. def stop | |
63. @running = false | |
64. @stopping = true | |
# /usr/lib/ruby/gems/1.9.1/gems/thin-1.2.4/lib/thin/server.rb: in start | |
149. log ">> Thin web server (v#{VERSION::STRING} codename #{VERSION::CODENAME})" | |
150. debug ">> Debugging ON" | |
151. trace ">> Tracing ON" | |
152. | |
153. log ">> Maximum connections set to #{@backend.maximum_connections}" | |
154. log ">> Listening on #{@backend}, CTRL+C to stop" | |
155. | |
156. @backend.start... | |
157. end | |
158. alias :start! :start | |
159. | |
160. # == Gracefull shutdown | |
161. # Stops the server after processing all current connections. | |
162. # As soon as this method is called, the server stops accepting | |
163. # new requests and wait for all current connections to finish. | |
# /usr/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/handler/thin.rb: in run | |
7. class Thin | |
8. def self.run(app, options={}) | |
9. app = Rack::Chunked.new(Rack::ContentLength.new(app)) | |
10. server = ::Thin::Server.new(options[:Host] || '0.0.0.0', | |
11. options[:Port] || 8080, | |
12. app) | |
13. yield server if block_given? | |
14. server.start... | |
15. end | |
16. end | |
17. end | |
18. end | |
# /home/dominic/.gem/ruby/1.9.1/gems/rack-1.0.1/bin/rackup: in <top (required)> | |
169. | |
170. if pid | |
171. File.open(pid, 'w'){ |f| f.write("#{Process.pid}") } | |
172. at_exit { File.delete(pid) if File.exist?(pid) } | |
173. end | |
174. end | |
175. | |
176. server.run app, options... | |
# /usr/bin/rackup: in load | |
12. | |
13. if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then | |
14. version = $1 | |
15. ARGV.shift | |
16. end | |
17. | |
18. gem 'rack', version | |
19. load Gem.bin_path('rack', 'rackup', version)... | |
# /usr/bin/rackup: in <main> | |
12. | |
13. if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then | |
14. version = $1 | |
15. ARGV.shift | |
16. end | |
17. | |
18. gem 'rack', version | |
19. load Gem.bin_path('rack', 'rackup', version) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment