summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-03 07:54:18 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-03 07:54:18 +0000
commit0c632c6fd391546cab623644aecc0ed85b1363da (patch)
treec350862f9052d8ad431f61f9cb4b24e929d18b64 /lib
parent60f0e763a41636dd9284d4c0d56116fb7dfaae7d (diff)
Revert r62966 and r62969
It breaks mswin's test-all git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63069 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/webrick/httpproxy.rb74
-rw-r--r--lib/webrick/httprequest.rb26
2 files changed, 31 insertions, 69 deletions
diff --git a/lib/webrick/httpproxy.rb b/lib/webrick/httpproxy.rb
index d180ff4831..be5531fec0 100644
--- a/lib/webrick/httpproxy.rb
+++ b/lib/webrick/httpproxy.rb
@@ -211,15 +211,21 @@ module WEBrick
end
def do_GET(req, res)
- perform_proxy_request(req, res, Net::HTTP::Get)
+ perform_proxy_request(req, res) do |http, path, header|
+ http.get(path, header)
+ end
end
def do_HEAD(req, res)
- perform_proxy_request(req, res, Net::HTTP::Head)
+ perform_proxy_request(req, res) do |http, path, header|
+ http.head(path, header)
+ end
end
def do_POST(req, res)
- perform_proxy_request(req, res, Net::HTTP::Post, req.body_reader)
+ perform_proxy_request(req, res) do |http, path, header|
+ http.post(path, req.body || "", header)
+ end
end
def do_OPTIONS(req, res)
@@ -295,56 +301,38 @@ module WEBrick
return FakeProxyURI
end
- def perform_proxy_request(req, res, req_class, body_stream = nil)
+ def perform_proxy_request(req, res)
uri = req.request_uri
path = uri.path.dup
path << "?" << uri.query if uri.query
header = setup_proxy_header(req, res)
upstream = setup_upstream_proxy_authentication(req, res, header)
+ response = nil
- body_tmp = []
http = Net::HTTP.new(uri.host, uri.port, upstream.host, upstream.port)
- req_fib = Fiber.new do
- http.start do
- if @config[:ProxyTimeout]
- ################################## these issues are
- http.open_timeout = 30 # secs # necessary (maybe because
- http.read_timeout = 60 # secs # Ruby's bug, but why?)
- ##################################
- end
- if body_stream && req['transfer-encoding'] =~ /\bchunked\b/i
- header['Transfer-Encoding'] = 'chunked'
- end
- http_req = req_class.new(path, header)
- http_req.body_stream = body_stream if body_stream
- http.request(http_req) do |response|
- # Persistent connection requirements are mysterious for me.
- # So I will close the connection in every response.
- res['proxy-connection'] = "close"
- res['connection'] = "close"
-
- # stream Net::HTTP::HTTPResponse to WEBrick::HTTPResponse
- res.status = response.code.to_i
- res.chunked = response.chunked?
- choose_header(response, res)
- set_cookie(response, res)
- set_via(res)
- response.read_body do |buf|
- body_tmp << buf
- Fiber.yield # wait for res.body Proc#call
- end
- end # http.request
- end
- end
- req_fib.resume # read HTTP response headers and first chunk of the body
- res.body = ->(socket) do
- while buf = body_tmp.shift
- socket.write(buf)
- buf.clear
- req_fib.resume # continue response.read_body
+ http.start do
+ if @config[:ProxyTimeout]
+ ################################## these issues are
+ http.open_timeout = 30 # secs # necessary (maybe because
+ http.read_timeout = 60 # secs # Ruby's bug, but why?)
+ ##################################
end
+ response = yield(http, path, header)
end
+
+ # Persistent connection requirements are mysterious for me.
+ # So I will close the connection in every response.
+ res['proxy-connection'] = "close"
+ res['connection'] = "close"
+
+ # Convert Net::HTTP::HTTPResponse to WEBrick::HTTPResponse
+ res.status = response.code.to_i
+ choose_header(response, res)
+ set_cookie(response, res)
+ set_via(res)
+ res.body = response.body
end
+
# :stopdoc:
end
end
diff --git a/lib/webrick/httprequest.rb b/lib/webrick/httprequest.rb
index c40f7c16e4..b40bcb0d57 100644
--- a/lib/webrick/httprequest.rb
+++ b/lib/webrick/httprequest.rb
@@ -258,32 +258,6 @@ module WEBrick
end
##
- # Prepares the HTTPRequest object for use as the
- # source for IO.copy_stream
-
- def body_reader
- @body_tmp = []
- @body_rd = Fiber.new do
- body do |buf|
- @body_tmp << buf
- Fiber.yield
- end
- end
- @body_rd.resume # grab the first chunk and yield
- self
- end
-
- # for IO.copy_stream. Note: we may return a larger string than +size+
- # here; but IO.copy_stream does not care.
- def readpartial(size, buf = ''.b) # :nodoc
- res = @body_tmp.shift or raise EOFError, 'end of file reached'
- buf.replace(res)
- res.clear
- @body_rd.resume # get more chunks
- buf
- end
-
- ##
# Request query as a Hash
def query