1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Add puma.socket key for direct socket access

This commit is contained in:
Evan Phoenix 2012-06-04 12:00:11 -07:00
parent d6e43d74b8
commit 0467ea2d0a
3 changed files with 24 additions and 0 deletions

View file

@ -103,6 +103,7 @@ module Puma
RACK_INPUT = "rack.input".freeze
RACK_URL_SCHEME = "rack.url_scheme".freeze
RACK_AFTER_REPLY = "rack.after_reply".freeze
PUMA_SOCKET = "puma.socket".freeze
HTTP = "http".freeze
HTTPS = "https".freeze

View file

@ -398,6 +398,8 @@ module Puma
def handle_request(env, client, body, cl)
normalize_env env, client
env[PUMA_SOCKET] = client
if cl
body = read_body env, client, body, cl
return false unless body

View file

@ -76,4 +76,25 @@ class TestPumaServer < Test::Unit::TestCase
assert_equal "#{fifteen}#{fifteen}", data
end
def test_puma_socket
body = "HTTP/1.1 750 Upgraded to Awesome\r\nDone: Yep!\r\n"
@server.app = proc do |env|
io = env['puma.socket']
io.write body
io.close
[-1, {}, []]
end
@server.add_tcp_listener @host, @port
@server.run
sock = TCPSocket.new @host, @port
sock << "PUT / HTTP/1.0\r\n\r\nHello"
assert_equal body, sock.read
end
end