From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH 3/3] extras/proxy_pass: flesh out upload support + tests
Date: Tue, 3 Mar 2015 07:59:30 +0000 [thread overview]
Message-ID: <1425369570-28427-4-git-send-email-e@80x24.org> (raw)
In-Reply-To: <1425369570-28427-1-git-send-email-e@80x24.org>
This module will probably become an official part of yahns
soon, so finally add tests for this module.
---
| 9 ++-------
| 24 +++++++++++++++++++++++-
2 files changed, 25 insertions(+), 8 deletions(-)
--git a/extras/proxy_pass.rb b/extras/proxy_pass.rb
index de6a2b1..0bec4ee 100644
--- a/extras/proxy_pass.rb
+++ b/extras/proxy_pass.rb
@@ -135,12 +135,7 @@ class ProxyPass # :nodoc:
end
def call(env)
- case request_method = env["REQUEST_METHOD"]
- when "GET", "HEAD" # OK
- else
- return [ 405, [%w(Content-Length 0), %w(Content-Length 0)], [] ]
- end
-
+ request_method = env['REQUEST_METHOD']
req = Rack::Request.new(env)
path = @path.gsub(/\$(\w+)/) { req.__send__($1.to_sym) }
req = "#{request_method} #{path} HTTP/1.1\r\n" \
@@ -204,7 +199,7 @@ class ProxyPass # :nodoc:
buf.replace("#{buf.size.to_s(16)}\r\n#{buf}\r\n")
ures.req_write(buf, @timeout)
end
- ures.req_write("0\r\n\r\n")
+ ures.req_write("0\r\n\r\n", @timeout)
else # common if we hit uploads
while input.read(16384, buf)
ures.req_write(buf, @timeout)
--git a/test/test_extras_proxy_pass.rb b/test/test_extras_proxy_pass.rb
index 513e574..8842683 100644
--- a/test/test_extras_proxy_pass.rb
+++ b/test/test_extras_proxy_pass.rb
@@ -59,6 +59,8 @@ class TestExtrasProxyPass < Testcase
end
end
+ gplv3 = File.open('COPYING')
+
Net::HTTP.start(host, port) do |http|
res = http.request(Net::HTTP::Get.new('/'))
assert_equal 200, res.code.to_i
@@ -69,9 +71,29 @@ class TestExtrasProxyPass < Testcase
assert_equal n, res['Content-Length'].to_i
assert_nil res.body
- res = http.put(Net::HTTP::Put.new('/'))
+ # chunked encoding
+ req = Net::HTTP::Put.new('/')
+ req.body_stream = gplv3
+ req.content_type = 'application/octet-stream'
+ req['Transfer-Encoding'] = 'chunked'
+ res = http.request(req)
+ gplv3.rewind
+ assert_equal gplv3.read, res.body
+ assert_equal 201, res.code.to_i
+
+ # normal content-length
+ gplv3.rewind
+ req = Net::HTTP::Put.new('/')
+ req.body_stream = gplv3
+ req.content_type = 'application/octet-stream'
+ req.content_length = gplv3.size
+ res = http.request(req)
+ gplv3.rewind
+ assert_equal gplv3.read, res.body
+ assert_equal 201, res.code.to_i
end
ensure
+ gplv3.close if gplv3
quit_wait pid
quit_wait pid2
end
--
EW
prev parent reply other threads:[~2015-03-03 7:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-03 7:59 [PUSHED] extras/proxy_pass updates Eric Wong
2015-03-03 7:59 ` [PATCH 1/3] extras/proxy_pass: do not name unused variable Eric Wong
2015-03-03 7:59 ` [PATCH 2/3] extras/proxy_pass: log exceptions leading to 502 Eric Wong
2015-03-03 7:59 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/yahns/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1425369570-28427-4-git-send-email-e@80x24.org \
--to=e@80x24.org \
--cc=yahns-public@yhbt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/yahns.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).