jruby-httpclient 0.2.1-java → 0.3.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jruby-httpclient}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
9
9
  s.platform = Gem::Platform.new([nil, "java", nil])
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
@@ -35,6 +35,8 @@ Gem::Specification.new do |s|
35
35
  "test/http_client/test_basic_client_operations.rb",
36
36
  "test/http_client/test_client_headers.rb",
37
37
  "test/http_client/test_client_parameters.rb",
38
+ "test/http_client/test_cookies.rb",
39
+ "test/http_client/test_redirect.rb",
38
40
  "test/http_client/test_request_entity.rb",
39
41
  "test/http_test_server.rb",
40
42
  "vendor/commons-codec-1.4.jar",
@@ -26,6 +26,8 @@ module HTTP
26
26
  setter_name = "#{parameter_name}="
27
27
  self.send(setter_name, parameter_value) if self.respond_to?(setter_name)
28
28
  end
29
+
30
+ @client = DefaultHttpClient.new(params)
29
31
  end
30
32
 
31
33
  # Request Methods
@@ -47,13 +49,13 @@ module HTTP
47
49
  end
48
50
 
49
51
  def execute(request)
50
- client = DefaultHttpClient.new(params)
51
-
52
- request.make_native_request(client, @encoding, @response_handler)
52
+ request.make_native_request(@client, @encoding, @response_handler)
53
53
  rescue SocketTimeoutException
54
54
  raise Timeout::Error, "timed out after #{so_timeout} ms"
55
- ensure
56
- client.connection_manager.shutdown
55
+ end
56
+
57
+ def shutdown
58
+ @client.connection_manager.shutdown
57
59
  end
58
60
  end
59
61
  end
@@ -1,3 +1,5 @@
1
+ require 'cgi'
2
+
1
3
  module HTTP
2
4
  class Request
3
5
  def self.create_type(&native_request_factory)
@@ -42,15 +44,17 @@ module HTTP
42
44
 
43
45
  def parse_uri
44
46
  uri = URI.parse(@uri)
45
- [uri.scheme, uri.host, uri.port, uri.path]
47
+ [uri.scheme, uri.host, uri.port, uri.path, uri.query]
46
48
  rescue URI::InvalidURIError
47
- [nil, nil, nil, @uri]
49
+ [nil, nil, nil, @uri, nil]
48
50
  end
49
51
 
50
52
  private
51
53
  define_method(:create_native_request) do |encoding|
52
- params = @params.collect { |key, value| BasicNameValuePair.new(key.to_s, value.to_s) }
53
- scheme, host, port, path = parse_uri
54
+ scheme, host, port, path, query = parse_uri
55
+ query_params = CGI.parse(query || "").merge(@params)
56
+
57
+ params = query_params.collect { |key, value| BasicNameValuePair.new(key.to_s, value.to_s) }
54
58
  request = native_request_factory.call(scheme, host, port, path, params, encoding)
55
59
 
56
60
  @headers.each { |name, value| request.add_header(name.to_s, value.to_s) }
@@ -7,6 +7,7 @@ module HTTP
7
7
  CookieSpecPNames = org.apache.http.cookie.params.CookieSpecPNames
8
8
  AuthPNames = org.apache.http.auth.params.AuthPNames
9
9
  ClientPNames = org.apache.http.client.params.ClientPNames
10
+ CookiePolicy = org.apache.http.client.params.CookiePolicy
10
11
 
11
12
  module Parameters
12
13
  CLIENT_PARAMETERS = {
@@ -13,4 +13,8 @@ class BasicAuthTest < Test::Unit::TestCase
13
13
  def setup
14
14
  @client = HTTP::Client.new(:default_host => "http://localhost:8080")
15
15
  end
16
+
17
+ def teardown
18
+ @client.shutdown
19
+ end
16
20
  end
@@ -49,7 +49,23 @@ class TestBasicClientOperations < Test::Unit::TestCase
49
49
  assert_equal("put", result)
50
50
  end
51
51
 
52
+ def test_get_can_take_parameters_in_url
53
+ result = @client.get("http://localhost:8080/echo?content=bar")
54
+
55
+ assert_equal("bar", result)
56
+ end
57
+
58
+ def test_get_url_parameters_take_precedence_over_optional_parameters
59
+ result = @client.get("http://localhost:8080/echo?content=bar", :content => "zed")
60
+
61
+ assert_equal("bar", result)
62
+ end
63
+
52
64
  def setup
53
65
  @client = HTTP::Client.new(:default_host => "http://localhost:8080")
54
66
  end
67
+
68
+ def teardown
69
+ @client.shutdown
70
+ end
55
71
  end
@@ -53,4 +53,8 @@ class TestClientHeaders < Test::Unit::TestCase
53
53
  def setup
54
54
  @client = HTTP::Client.new(:default_host => "http://localhost:8080")
55
55
  end
56
+
57
+ def teardown
58
+ @client.shutdown
59
+ end
56
60
  end
@@ -0,0 +1,18 @@
1
+ require 'helper'
2
+
3
+ class CookieTest < Test::Unit::TestCase
4
+ def test_cookies_can_be_remembered
5
+ @client.get("/set_cookie", :cookie => "nom nom nom")
6
+ result = @client.get("/echo_cookie")
7
+
8
+ assert_equal("nom nom nom", result)
9
+ end
10
+
11
+ def setup
12
+ @client = HTTP::Client.new(:default_host => "http://localhost:8080", :cookie_policy => HTTP::CookiePolicy::BROWSER_COMPATIBILITY)
13
+ end
14
+
15
+ def teardown
16
+ @client.shutdown
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+
3
+ class RedirectTest < Test::Unit::TestCase
4
+ def test_get_redirect
5
+ result = @client.get("/redirect", :content => "foo")
6
+
7
+ assert_equal("foo", result)
8
+ end
9
+
10
+ def setup
11
+ @client = HTTP::Client.new(:default_host => "http://localhost:8080", :handle_redirects => true)
12
+ end
13
+
14
+ def teardown
15
+ @client.shutdown
16
+ end
17
+ end
@@ -20,4 +20,8 @@ class RequestEntityTest < Test::Unit::TestCase
20
20
  def setup
21
21
  @client = HTTP::Client.new(:default_host => "http://localhost:8080")
22
22
  end
23
+
24
+ def teardown
25
+ @client.shutdown
26
+ end
23
27
  end
@@ -8,9 +8,32 @@ module HTTP
8
8
  SERVER.mount('/echo_header', HeaderEchoServlet)
9
9
  SERVER.mount('/protected', ProtectedServlet)
10
10
  SERVER.mount('/body', BodyServlet)
11
+ SERVER.mount('/redirect', RedirectServlet)
12
+ SERVER.mount('/set_cookie', SetCookieServlet)
13
+ SERVER.mount('/echo_cookie', EchoCookieServlet)
11
14
  Thread.new { SERVER.start }
12
15
  end
13
16
 
17
+ class SetCookieServlet < WEBrick::HTTPServlet::AbstractServlet
18
+ def do_GET(request, response)
19
+ response.cookies << WEBrick::Cookie.new("test_cookie", request.query['cookie'])
20
+ end
21
+ end
22
+
23
+ class EchoCookieServlet < WEBrick::HTTPServlet::AbstractServlet
24
+ def do_GET(request, response)
25
+ puts request.cookies.length
26
+ cookie = request.cookies.find { |c| c.name == "test_cookie" }
27
+ response.body = cookie.value
28
+ end
29
+ end
30
+
31
+ class RedirectServlet < WEBrick::HTTPServlet::AbstractServlet
32
+ def do_GET(request, response)
33
+ response.set_redirect(WEBrick::HTTPStatus::MovedPermanently, "/echo?content=#{request.query['content']}")
34
+ end
35
+ end
36
+
14
37
  class BodyServlet < WEBrick::HTTPServlet::AbstractServlet
15
38
  def do_POST(request, response)
16
39
  response.status = 200
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jruby-httpclient
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
5
+ version: 0.3.0
6
6
  platform: java
7
7
  authors:
8
8
  - Adam Esterline
@@ -73,6 +73,8 @@ files:
73
73
  - test/http_client/test_basic_client_operations.rb
74
74
  - test/http_client/test_client_headers.rb
75
75
  - test/http_client/test_client_parameters.rb
76
+ - test/http_client/test_cookies.rb
77
+ - test/http_client/test_redirect.rb
76
78
  - test/http_client/test_request_entity.rb
77
79
  - test/http_test_server.rb
78
80
  - vendor/commons-codec-1.4.jar