Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28b0fde
commit daa7c56
Showing
17 changed files
with
221 additions
and
234 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
require "thin/version" | ||
require "thin/system" | ||
require "thin/server" | ||
module Thin | ||
module Backends | ||
autoload :Prefork, "thin/backends/prefork" | ||
autoload :SingleProcess, "thin/backends/single_process" | ||
end | ||
|
||
autoload :Async, "thin/async" | ||
autoload :CatchAsync, "thin/catch_async" | ||
autoload :Chunked, "thin/chunked" | ||
autoload :Configurator, "thin/configurator" | ||
autoload :Connection, "thin/connection" | ||
autoload :FastEnumerator, "thin/fast_enumerator" | ||
autoload :Listener, "thin/listener" | ||
autoload :Request, "thin/request" | ||
autoload :Response, "thin/response" | ||
autoload :Runner, "thin/runner" | ||
autoload :Server, "thin/server" | ||
autoload :StreamFile, "thin/stream_file" | ||
autoload :Streamed, "thin/streamed" | ||
autoload :System, "thin/system" | ||
autoload :Threaded, "thin/threaded" | ||
autoload :Version, "thin/version" | ||
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module Thin | ||
# Like Rack::Chunk but support async responses | ||
# Make sure it is mounted before any middleware that wraps the body | ||
class Chunked | ||
include Rack::Utils | ||
|
||
# Same as Rack::Chunked::Body, but doesn't send the tail automaticaly. | ||
class Body < SimpleDelegator | ||
TERM = "\r\n" | ||
TAIL = "0#{TERM}#{TERM}" | ||
|
||
def initialize(body) | ||
super | ||
@body = body | ||
end | ||
|
||
def each | ||
term = TERM | ||
@body.each do |chunk| | ||
size = Rack::Utils.bytesize(chunk) | ||
next if size == 0 | ||
|
||
chunk = chunk.dup.force_encoding(Encoding::BINARY) if chunk.respond_to?(:force_encoding) | ||
yield [size.to_s(16), term, chunk, term].join | ||
end | ||
|
||
if @body.respond_to?(:callback) | ||
@body.callback { yield TAIL } | ||
else | ||
yield TAIL | ||
end | ||
end | ||
|
||
def close | ||
@body.close if @body.respond_to?(:close) | ||
end | ||
end | ||
|
||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
status, headers, body = @app.call(env) | ||
headers = HeaderHash.new(headers) | ||
|
||
if env['HTTP_VERSION'] == 'HTTP/1.0' || | ||
STATUS_WITH_NO_ENTITY_BODY.include?(status) || | ||
headers['Content-Length'] || | ||
headers['Transfer-Encoding'] | ||
[status, headers, body] | ||
else | ||
headers.delete('Content-Length') | ||
headers['Transfer-Encoding'] = 'chunked' | ||
[status, headers, Body.new(body)] | ||
end | ||
end | ||
end | ||
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.