lib/mechanize/http/agent.rb in mechanize-2.6.0 vs lib/mechanize/http/agent.rb in mechanize-2.7.0
- old
+ new
@@ -658,11 +658,20 @@
base = lbase
else
base = nil
end
- uri = referer_uri + (base ? base.uri : referer_uri) + uri
+ base = referer_uri + (base ? base.uri : referer_uri)
+
+ # Workaround for URI's bug in that it squashes consecutive
+ # slashes. See #304.
+ if uri.path.match(%r{\A(.*?/)(?!/\.\.?(?!/))(/.*)\z}i)
+ uri = URI((base + $1).to_s + $2)
+ else
+ uri = base + uri
+ end
+
# Strip initial "/.." bits from the path
uri.path.sub!(/^(\/\.\.)+(?=\/)/, '')
end
unless ['http', 'https', 'file'].include?(uri.scheme.downcase)
@@ -791,11 +800,11 @@
end
return body_io if length.zero?
out_io = case response['Content-Encoding']
- when nil, 'none', '7bit' then
+ when nil, 'none', '7bit', "" then
body_io
when 'deflate' then
content_encoding_inflate body_io
when 'gzip', 'x-gzip' then
content_encoding_gunzip body_io
@@ -838,18 +847,19 @@
save_cookies(uri, set_cookie)
end
end
def save_cookies(uri, set_cookie)
- log = log() # reduce method calls
- Mechanize::Cookie.parse(uri, set_cookie, log) { |c|
- if @cookie_jar.add(uri, c)
- log.debug("saved cookie: #{c}") if log
- else
- log.debug("rejected cookie: #{c}") if log
- end
- }
+ return [] if set_cookie.nil?
+ if log = log() # reduce method calls
+ @cookie_jar.parse(set_cookie, uri, :logger => log) { |c|
+ log.debug("saved cookie: #{c}")
+ true
+ }
+ else
+ @cookie_jar.parse(set_cookie, uri)
+ end
end
def response_follow_meta_refresh response, uri, page, redirects
delay, new_url = get_meta_refresh(response, uri, page)
return nil unless delay
@@ -911,11 +921,11 @@
raise unless response.chunked? and total.nonzero?
body_io.rewind
raise Mechanize::ChunkedTerminationError.new(e, response, body_io, uri,
@context)
- rescue Net::HTTP::Persistent::Error => e
+ rescue Net::HTTP::Persistent::Error, Errno::ECONNRESET => e
body_io.rewind
raise Mechanize::ResponseReadError.new(e, response, body_io, uri,
@context)
end
@@ -926,13 +936,16 @@
Net::HTTPUnknownResponse === response
content_length = response.content_length
unless Net::HTTP::Head === request or Net::HTTPRedirection === response then
- raise EOFError, "Content-Length (#{content_length}) does not match " \
- "response body length (#{body_io.length})" if
- content_length and content_length != body_io.length
+ if content_length and content_length != body_io.length
+ err = EOFError.new("Content-Length (#{content_length}) does not " \
+ "match response body length (#{body_io.length})")
+ raise Mechanize::ResponseReadError.new(err, response, body_io, uri,
+ @context)
+ end
end
body_io
end
@@ -1215,10 +1228,10 @@
size >= @max_file_buffer
end
def reset
- @cookie_jar.clear!
+ @cookie_jar.clear
@history.clear
end
end