http-request 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ module HttpRequest
12
12
  @keep_alive = options[:keep_alive].nil? ? true : options[:keep_alive]
13
13
 
14
14
  # Let's do this
15
- @uri = Addressable::URI.parse(url)
15
+ @uri = parse_uri(url)
16
16
  open
17
17
  end
18
18
 
@@ -57,30 +57,29 @@ module HttpRequest
57
57
 
58
58
  def request(verb, path, headers={}, body=nil)
59
59
  if path =~ /^http/i
60
- new_uri = Addressable::URI.parse(path)
60
+ new_uri = parse_uri(path)
61
61
  if new_uri.origin != uri.origin
62
62
  # TODO.. get an error class for this..
63
- raise "Ummm... you're trying to talk to another server you duffis.."
63
+ raise "Ummm... you're trying to talk to another server"
64
64
  end
65
- uri.path = new_uri.path
65
+ @uri = new_uri
66
+ else
67
+ # Update the path and query
68
+ # Note: also normalize the path in case its malformed.. dum dums
69
+ uri.join! parse_uri(path.gsub('//','/')).request_uri
66
70
  end
67
71
 
68
72
  # Open the connection if its closed or hasn't been started..
69
73
  open if closed?
70
74
 
71
- # headers['Date'] = Time.now.httpdate # need this..?
75
+ # Default headers
72
76
  headers['User-Agent'] ||= user_agent
73
77
  headers['Connection'] ||= 'keep-alive' if keep_alive
74
78
  headers['Content-Length'] ||= body.bytesize.to_s if body
75
79
 
76
- # TODO.. link traversal..
77
- # ..will our host change tho... like the thing we actually connect to?
78
- # it could very well... so we should check that out..
79
- # maybe we have a "host" or "host_id" variable for this stuff..?
80
-
81
80
  # Build request
82
81
  req_klass = instance_eval("Net::HTTP::"+verb.to_s.capitalize)
83
- req = req_klass.new([uri.path, uri.query].join('?'), headers)
82
+ req = req_klass.new(uri.request_uri, headers)
84
83
  req.body = body if !body.nil? && !body.empty?
85
84
 
86
85
  # Make the HTTP request
@@ -108,12 +107,20 @@ module HttpRequest
108
107
 
109
108
  # Handle URL Redirection
110
109
  if auto_redirect && raw_response.kind_of?(Net::HTTPRedirection) && !response.header['location'].nil?
111
- @uri = Addressable::URI.parse(response.header['location'])
112
- request(verb, path, headers, body)
110
+ @uri = parse_uri(response.header['location'])
111
+ close # close existing connection..
112
+ request(verb, uri.request_uri, headers, body)
113
113
  else
114
114
  response
115
115
  end
116
116
  end
117
117
 
118
+
119
+ private
120
+
121
+ def parse_uri(uri)
122
+ Addressable::URI.parse(Addressable::URI.encode(Addressable::URI.unencode(uri)))
123
+ end
124
+
118
125
  end
119
126
  end
@@ -1,3 +1,3 @@
1
1
  module HttpRequest
2
- VERSION = '1.1.3'
2
+ VERSION = '1.1.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-request
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: