jruby-httpclient 1.0.0-java → 1.1.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/jruby-httpclient.gemspec +3 -3
- data/lib/http_client/jruby/client.rb +8 -0
- data/lib/http_client/jruby/methods.rb +16 -0
- data/lib/http_client/jruby/response.rb +25 -2
- data/lib/http_client/mri/methods.rb +36 -0
- data/test/http_client/test_server_headers.rb +23 -0
- metadata +3 -2
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ Jeweler::Tasks.new do |gem|
|
|
20
20
|
gem.summary = %Q{A thin wrapper around the Apache HttpClient}
|
21
21
|
gem.description = %Q{An HTTP client designed for use with JRuby in a threaded environment}
|
22
22
|
gem.email = "adam@esterlines.com"
|
23
|
-
gem.authors = ["Adam Esterline"]
|
23
|
+
gem.authors = ["Adam Esterline", "Aaron Spiegel"]
|
24
24
|
gem.platform = Gem::Platform::JAVA
|
25
25
|
# dependencies defined in Gemfile
|
26
26
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/jruby-httpclient.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{jruby-httpclient}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.1.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=
|
12
|
-
s.authors = ["Adam Esterline"]
|
13
|
-
s.date = %q{
|
12
|
+
s.authors = ["Adam Esterline", "Aaron Spiegel"]
|
13
|
+
s.date = %q{2012-01-01}
|
14
14
|
s.description = %q{An HTTP client designed for use with JRuby in a threaded environment}
|
15
15
|
s.email = %q{adam@esterlines.com}
|
16
16
|
s.extra_rdoc_files = [
|
@@ -12,6 +12,14 @@ module HTTP
|
|
12
12
|
def get(params, options = {})
|
13
13
|
read_response(Get.new(params, options))
|
14
14
|
end
|
15
|
+
|
16
|
+
def head(params, options = {})
|
17
|
+
read_response(Head.new(params, options))
|
18
|
+
end
|
19
|
+
|
20
|
+
def options(params, options = {})
|
21
|
+
read_response(Options.new(params, options))
|
22
|
+
end
|
15
23
|
|
16
24
|
def post(params, options = {})
|
17
25
|
read_response(Post.new(params, options))
|
@@ -67,6 +67,20 @@ module HTTP
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
class Head < Request
|
71
|
+
def create_native_request
|
72
|
+
query_string = URLEncodedUtils.format(@query_params, encoding)
|
73
|
+
HttpHead.new(create_uri(query_string))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class Options < Request
|
78
|
+
def create_native_request
|
79
|
+
query_string = URLEncodedUtils.format(@query_params, encoding)
|
80
|
+
HttpOptions.new(create_uri(query_string))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
70
84
|
class Delete < Request
|
71
85
|
def create_native_request
|
72
86
|
HttpDelete.new(create_uri)
|
@@ -81,6 +95,8 @@ module HTTP
|
|
81
95
|
|
82
96
|
private
|
83
97
|
HttpGet = org.apache.http.client.methods.HttpGet
|
98
|
+
HttpHead = org.apache.http.client.methods.HttpHead
|
99
|
+
HttpOptions = org.apache.http.client.methods.HttpOptions
|
84
100
|
HttpPost = org.apache.http.client.methods.HttpPost
|
85
101
|
HttpDelete = org.apache.http.client.methods.HttpDelete
|
86
102
|
HttpPut = org.apache.http.client.methods.HttpPut
|
@@ -9,7 +9,12 @@ module HTTP
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def body
|
12
|
-
|
12
|
+
# HTTP HEAD requests have no entity, nor any body
|
13
|
+
if @native_response.entity
|
14
|
+
@body ||= EntityUtils.to_string(@native_response.entity)
|
15
|
+
else
|
16
|
+
nil
|
17
|
+
end
|
13
18
|
end
|
14
19
|
|
15
20
|
def status_code
|
@@ -26,7 +31,25 @@ module HTTP
|
|
26
31
|
end
|
27
32
|
|
28
33
|
def [](header_name)
|
29
|
-
@native_response.
|
34
|
+
@native_response.get_headers(header_name).map{|h| h.get_value}.join(", ")
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
@native_response.get_all_headers.map(&:to_s).join("\n")
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_hash
|
42
|
+
hash = {}
|
43
|
+
each do |name, value|
|
44
|
+
hash[name] = hash[name] ? hash[name] + ", #{value}" : value
|
45
|
+
end
|
46
|
+
hash
|
47
|
+
end
|
48
|
+
|
49
|
+
def each
|
50
|
+
@native_response.header_iterator.each do |h|
|
51
|
+
yield h.get_name, h.get_value
|
52
|
+
end
|
30
53
|
end
|
31
54
|
end
|
32
55
|
|
@@ -59,6 +59,42 @@ module HTTP
|
|
59
59
|
params_as_hash.map { |name, value| "#{URI.encode(name.to_s)}=#{URI.encode(value.to_s)}" }.join("&")
|
60
60
|
end
|
61
61
|
end
|
62
|
+
|
63
|
+
class Head < Request
|
64
|
+
def create_request
|
65
|
+
host, port, path, query = parse_uri
|
66
|
+
head = Net::HTTP::Head.new("#{path}?#{query || to_query_string(@params)}")
|
67
|
+
[host, port, head]
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_query_string(params_as_hash)
|
71
|
+
params_as_hash.map { |name, value| "#{URI.encode(name.to_s)}=#{URI.encode(value.to_s)}" }.join("&")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class Options < Request
|
76
|
+
def create_request
|
77
|
+
host, port, path, query = parse_uri
|
78
|
+
options = Net::HTTP::Options.new("#{path}?#{query || to_query_string(@params)}")
|
79
|
+
[host, port, options]
|
80
|
+
end
|
81
|
+
|
82
|
+
def to_query_string(params_as_hash)
|
83
|
+
params_as_hash.map { |name, value| "#{URI.encode(name.to_s)}=#{URI.encode(value.to_s)}" }.join("&")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class Patch < Request
|
88
|
+
def create_request
|
89
|
+
host, port, path, query = parse_uri
|
90
|
+
patch = Net::HTTP::Patch.new("#{path}?#{query || to_query_string(@params)}")
|
91
|
+
[host, port, patch]
|
92
|
+
end
|
93
|
+
|
94
|
+
def to_query_string(params_as_hash)
|
95
|
+
params_as_hash.map { |name, value| "#{URI.encode(name.to_s)}=#{URI.encode(value.to_s)}" }.join("&")
|
96
|
+
end
|
97
|
+
end
|
62
98
|
|
63
99
|
class Post < Request
|
64
100
|
def create_request
|
@@ -7,6 +7,29 @@ class ServerHeadersTest < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
assert_equal("FooBar", response.headers["Test-Header"])
|
9
9
|
end
|
10
|
+
|
11
|
+
def test_response_headers_to_hash
|
12
|
+
get = HTTP::Get.new("/set_header")
|
13
|
+
response = @client.execute(get)
|
14
|
+
response_hash = response.headers.to_hash
|
15
|
+
assert_equal(response_hash["Test-Header"], "FooBar")
|
16
|
+
assert_equal(response_hash["Content-Length"], "0")
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_response_headers_iteration
|
20
|
+
get = HTTP::Get.new("/set_header")
|
21
|
+
response = @client.execute(get)
|
22
|
+
|
23
|
+
headers = values = []
|
24
|
+
response.headers.each do |header, value|
|
25
|
+
headers << header; values << value
|
26
|
+
end
|
27
|
+
|
28
|
+
assert headers.include? "Test-Header"
|
29
|
+
assert headers.include? "Content-Length"
|
30
|
+
assert values.include? "FooBar"
|
31
|
+
assert values.include? "0"
|
32
|
+
end
|
10
33
|
|
11
34
|
def setup
|
12
35
|
@client = HTTP::Client.new(:default_host => "http://localhost:8080")
|
metadata
CHANGED
@@ -2,15 +2,16 @@
|
|
2
2
|
name: jruby-httpclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.
|
5
|
+
version: 1.1.0
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Adam Esterline
|
9
|
+
- Aaron Spiegel
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
13
|
|
13
|
-
date:
|
14
|
+
date: 2012-01-01 00:00:00 -07:00
|
14
15
|
default_executable:
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|