corntrace-fakeweb 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/CHANGELOG +197 -0
- data/LICENSE.txt +281 -0
- data/README.rdoc +222 -0
- data/Rakefile +70 -0
- data/fakeweb.gemspec +123 -0
- data/lib/fake_web.rb +179 -0
- data/lib/fake_web/VERSION +1 -0
- data/lib/fake_web/ext/net_http.rb +81 -0
- data/lib/fake_web/registry.rb +114 -0
- data/lib/fake_web/responder.rb +120 -0
- data/lib/fake_web/response.rb +10 -0
- data/lib/fake_web/stub_socket.rb +15 -0
- data/lib/fake_web/utility.rb +65 -0
- data/lib/fakeweb.rb +2 -0
- data/test/fixtures/google_response_from_curl +12 -0
- data/test/fixtures/google_response_with_transfer_encoding +17 -0
- data/test/fixtures/google_response_without_transfer_encoding +11 -0
- data/test/fixtures/test_example.txt +1 -0
- data/test/fixtures/test_txt_file +3 -0
- data/test/test_allow_net_connect.rb +85 -0
- data/test/test_deprecations.rb +54 -0
- data/test/test_fake_authentication.rb +92 -0
- data/test/test_fake_web.rb +553 -0
- data/test/test_fake_web_open_uri.rb +58 -0
- data/test/test_helper.rb +87 -0
- data/test/test_missing_open_uri.rb +25 -0
- data/test/test_missing_pathname.rb +37 -0
- data/test/test_other_net_http_libraries.rb +36 -0
- data/test/test_precedence.rb +79 -0
- data/test/test_query_string.rb +45 -0
- data/test/test_regexes.rb +157 -0
- data/test/test_response_headers.rb +73 -0
- data/test/test_trailing_slashes.rb +53 -0
- data/test/test_utility.rb +76 -0
- data/test/vendor/right_http_connection-1.2.4/History.txt +59 -0
- data/test/vendor/right_http_connection-1.2.4/Manifest.txt +7 -0
- data/test/vendor/right_http_connection-1.2.4/README.txt +54 -0
- data/test/vendor/right_http_connection-1.2.4/Rakefile +103 -0
- data/test/vendor/right_http_connection-1.2.4/lib/net_fix.rb +160 -0
- data/test/vendor/right_http_connection-1.2.4/lib/right_http_connection.rb +435 -0
- data/test/vendor/right_http_connection-1.2.4/setup.rb +1585 -0
- data/test/vendor/samuel-0.2.1/.document +5 -0
- data/test/vendor/samuel-0.2.1/.gitignore +5 -0
- data/test/vendor/samuel-0.2.1/LICENSE +20 -0
- data/test/vendor/samuel-0.2.1/README.rdoc +70 -0
- data/test/vendor/samuel-0.2.1/Rakefile +62 -0
- data/test/vendor/samuel-0.2.1/VERSION +1 -0
- data/test/vendor/samuel-0.2.1/lib/samuel.rb +52 -0
- data/test/vendor/samuel-0.2.1/lib/samuel/net_http.rb +10 -0
- data/test/vendor/samuel-0.2.1/lib/samuel/request.rb +96 -0
- data/test/vendor/samuel-0.2.1/samuel.gemspec +69 -0
- data/test/vendor/samuel-0.2.1/test/request_test.rb +193 -0
- data/test/vendor/samuel-0.2.1/test/samuel_test.rb +42 -0
- data/test/vendor/samuel-0.2.1/test/test_helper.rb +66 -0
- data/test/vendor/samuel-0.2.1/test/thread_test.rb +32 -0
- metadata +167 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestResponseHeaders < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_content_type_when_registering_with_string_and_content_type_header_as_symbol_option
|
6
|
+
FakeWeb.register_uri(:get, "http://example.com/users.json", :body => '[{"username": "chrisk"}]', :content_type => "application/json")
|
7
|
+
response = Net::HTTP.start("example.com") { |query| query.get("/users.json") }
|
8
|
+
assert_equal '[{"username": "chrisk"}]', response.body
|
9
|
+
assert_equal "application/json", response['Content-Type']
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_content_type_when_registering_with_string_and_content_type_header_as_string_option
|
13
|
+
FakeWeb.register_uri(:get, "http://example.com/users.json", :body => '[{"username": "chrisk"}]', 'Content-Type' => "application/json")
|
14
|
+
response = Net::HTTP.start("example.com") { |query| query.get("/users.json") }
|
15
|
+
assert_equal "application/json", response['Content-Type']
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_content_type_when_registering_with_string_only
|
19
|
+
FakeWeb.register_uri(:get, "http://example.com/users.json", :body => '[{"username": "chrisk"}]')
|
20
|
+
response = Net::HTTP.start("example.com") { |query| query.get("/users.json") }
|
21
|
+
assert_equal '[{"username": "chrisk"}]', response.body
|
22
|
+
assert_nil response['Content-Type']
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_cookies_when_registering_with_file_and_set_cookie_header
|
26
|
+
FakeWeb.register_uri(:get, "http://example.com/", :body => fixture_path("test_example.txt"),
|
27
|
+
:set_cookie => "user_id=1; example=yes")
|
28
|
+
response = Net::HTTP.start("example.com") { |query| query.get("/") }
|
29
|
+
assert_equal "test example content", response.body
|
30
|
+
assert_equal "user_id=1; example=yes", response['Set-Cookie']
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_registering_with_baked_response_ignores_header_options
|
34
|
+
fake_response = Net::HTTPOK.new('1.1', '200', 'OK')
|
35
|
+
fake_response["Server"] = "Apache/1.3.27 (Unix)"
|
36
|
+
FakeWeb.register_uri(:get, "http://example.com/", :response => fake_response,
|
37
|
+
:server => "FakeWeb/1.2.3 (Ruby)")
|
38
|
+
response = Net::HTTP.start("example.com") { |query| query.get("/") }
|
39
|
+
assert_equal "200", response.code
|
40
|
+
assert_equal "OK", response.message
|
41
|
+
assert_equal "Apache/1.3.27 (Unix)", response["Server"]
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_headers_are_rotated_when_registering_with_response_rotation
|
45
|
+
FakeWeb.register_uri(:get, "http://example.com",
|
46
|
+
[{:body => 'test1', :expires => "Thu, 14 Jun 2009 16:00:00 GMT",
|
47
|
+
:content_type => "text/plain"},
|
48
|
+
{:body => 'test2', :expires => "Thu, 14 Jun 2009 16:00:01 GMT"}])
|
49
|
+
|
50
|
+
first_response = second_response = nil
|
51
|
+
Net::HTTP.start("example.com") do |query|
|
52
|
+
first_response = query.get("/")
|
53
|
+
second_response = query.get("/")
|
54
|
+
end
|
55
|
+
assert_equal 'test1', first_response.body
|
56
|
+
assert_equal "Thu, 14 Jun 2009 16:00:00 GMT", first_response['Expires']
|
57
|
+
assert_equal "text/plain", first_response['Content-Type']
|
58
|
+
assert_equal 'test2', second_response.body
|
59
|
+
assert_equal "Thu, 14 Jun 2009 16:00:01 GMT", second_response['Expires']
|
60
|
+
assert_nil second_response['Content-Type']
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_registering_with_status_option_and_response_headers
|
64
|
+
FakeWeb.register_uri(:get, "http://example.com", :status => ["301", "Moved Permanently"],
|
65
|
+
:location => "http://www.example.com")
|
66
|
+
|
67
|
+
response = Net::HTTP.start("example.com") { |query| query.get("/") }
|
68
|
+
assert_equal "301", response.code
|
69
|
+
assert_equal "Moved Permanently", response.message
|
70
|
+
assert_equal "http://www.example.com", response["Location"]
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestFakeWebTrailingSlashes < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_registering_root_without_slash_and_ask_predicate_method_with_slash
|
6
|
+
FakeWeb.register_uri(:get, "http://www.example.com", :body => "root")
|
7
|
+
assert FakeWeb.registered_uri?(:get, "http://www.example.com/")
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_registering_root_without_slash_and_request
|
11
|
+
FakeWeb.register_uri(:get, "http://www.example.com", :body => "root")
|
12
|
+
response = Net::HTTP.start("www.example.com") { |query| query.get('/') }
|
13
|
+
assert_equal "root", response.body
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_registering_root_with_slash_and_ask_predicate_method_without_slash
|
17
|
+
FakeWeb.register_uri(:get, "http://www.example.com/", :body => "root")
|
18
|
+
assert FakeWeb.registered_uri?(:get, "http://www.example.com")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_registering_root_with_slash_and_request
|
22
|
+
FakeWeb.register_uri(:get, "http://www.example.com/", :body => "root")
|
23
|
+
response = Net::HTTP.start("www.example.com") { |query| query.get('/') }
|
24
|
+
assert_equal "root", response.body
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_registering_path_without_slash_and_ask_predicate_method_with_slash
|
28
|
+
FakeWeb.register_uri(:get, "http://www.example.com/users", :body => "User list")
|
29
|
+
assert !FakeWeb.registered_uri?(:get, "http://www.example.com/users/")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_registering_path_without_slash_and_request_with_slash
|
33
|
+
FakeWeb.allow_net_connect = false
|
34
|
+
FakeWeb.register_uri(:get, "http://www.example.com/users", :body => "User list")
|
35
|
+
assert_raise FakeWeb::NetConnectNotAllowedError do
|
36
|
+
response = Net::HTTP.start("www.example.com") { |query| query.get('/users/') }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_registering_path_with_slash_and_ask_predicate_method_without_slash
|
41
|
+
FakeWeb.register_uri(:get, "http://www.example.com/users/", :body => "User list")
|
42
|
+
assert !FakeWeb.registered_uri?(:get, "http://www.example.com/users")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_registering_path_with_slash_and_request_without_slash
|
46
|
+
FakeWeb.allow_net_connect = false
|
47
|
+
FakeWeb.register_uri(:get, "http://www.example.com/users/", :body => "User list")
|
48
|
+
assert_raise FakeWeb::NetConnectNotAllowedError do
|
49
|
+
response = Net::HTTP.start("www.example.com") { |query| query.get('/users') }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestUtility < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_decode_userinfo_from_header_handles_basic_auth
|
6
|
+
authorization_header = "Basic dXNlcm5hbWU6c2VjcmV0"
|
7
|
+
userinfo = FakeWeb::Utility.decode_userinfo_from_header(authorization_header)
|
8
|
+
assert_equal "username:secret", userinfo
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_encode_unsafe_chars_in_userinfo_does_not_encode_userinfo_safe_punctuation
|
12
|
+
userinfo = "user;&=+$,:secret"
|
13
|
+
assert_equal userinfo, FakeWeb::Utility.encode_unsafe_chars_in_userinfo(userinfo)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_encode_unsafe_chars_in_userinfo_does_not_encode_rfc_3986_unreserved_characters
|
17
|
+
userinfo = "-_.!~*'()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:secret"
|
18
|
+
assert_equal userinfo, FakeWeb::Utility.encode_unsafe_chars_in_userinfo(userinfo)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_encode_unsafe_chars_in_userinfo_does_encode_other_characters
|
22
|
+
userinfo, safe_userinfo = 'us#rn@me:sec//ret?"', 'us%23rn%40me:sec%2F%2Fret%3F%22'
|
23
|
+
assert_equal safe_userinfo, FakeWeb::Utility.encode_unsafe_chars_in_userinfo(userinfo)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_strip_default_port_from_uri_strips_80_from_http_with_path
|
27
|
+
uri = "http://example.com:80/foo/bar"
|
28
|
+
stripped_uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
|
29
|
+
assert_equal "http://example.com/foo/bar", stripped_uri
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_strip_default_port_from_uri_strips_80_from_http_without_path
|
33
|
+
uri = "http://example.com:80"
|
34
|
+
stripped_uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
|
35
|
+
assert_equal "http://example.com", stripped_uri
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_strip_default_port_from_uri_strips_443_from_https_without_path
|
39
|
+
uri = "https://example.com:443"
|
40
|
+
stripped_uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
|
41
|
+
assert_equal "https://example.com", stripped_uri
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_strip_default_port_from_uri_strips_443_from_https
|
45
|
+
uri = "https://example.com:443/foo/bar"
|
46
|
+
stripped_uri = FakeWeb::Utility.strip_default_port_from_uri(uri)
|
47
|
+
assert_equal "https://example.com/foo/bar", stripped_uri
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_strip_default_port_from_uri_does_not_strip_8080_from_http
|
51
|
+
uri = "http://example.com:8080/foo/bar"
|
52
|
+
assert_equal uri, FakeWeb::Utility.strip_default_port_from_uri(uri)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_strip_default_port_from_uri_does_not_strip_443_from_http
|
56
|
+
uri = "http://example.com:443/foo/bar"
|
57
|
+
assert_equal uri, FakeWeb::Utility.strip_default_port_from_uri(uri)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_strip_default_port_from_uri_does_not_strip_80_from_query_string
|
61
|
+
uri = "http://example.com/?a=:80&b=c"
|
62
|
+
assert_equal uri, FakeWeb::Utility.strip_default_port_from_uri(uri)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_strip_default_port_from_uri_does_not_modify_strings_that_do_not_start_with_http_or_https
|
66
|
+
uri = "httpz://example.com:80/"
|
67
|
+
assert_equal uri, FakeWeb::Utility.strip_default_port_from_uri(uri)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_uri_escape_delegates_to_uri_parser_when_available
|
71
|
+
parsing_object = URI.const_defined?(:Parser) ? URI::Parser.any_instance : URI
|
72
|
+
parsing_object.expects(:escape).with("string", /unsafe/).returns("escaped")
|
73
|
+
assert_equal "escaped", FakeWeb::Utility.uri_escape("string", /unsafe/)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
== 0.0.1 2007-05-15
|
2
|
+
* 1 major enhancement:
|
3
|
+
* Initial release
|
4
|
+
|
5
|
+
== 0.1.2 2007-06-27
|
6
|
+
|
7
|
+
* No major changes.
|
8
|
+
|
9
|
+
== 0.1.3 2007-07-09
|
10
|
+
|
11
|
+
* No change.
|
12
|
+
|
13
|
+
== 0.1.4 2007-08-10
|
14
|
+
|
15
|
+
* r1442, todd, 2007-08-07 15:45:24
|
16
|
+
* # 373, Add support in right_http_connection for bailing out to a block while
|
17
|
+
reading the HTTP response (to support GET streaming...)
|
18
|
+
|
19
|
+
* r1411, todd, 2007-08-03 15:14:45
|
20
|
+
* # 373, Stream uploads (PUTs) if the source is a file, stream, or anything
|
21
|
+
read()-able
|
22
|
+
|
23
|
+
== 1.1.0 2007-08-15
|
24
|
+
Initial public release
|
25
|
+
|
26
|
+
== 1.2.0 2007-10-05
|
27
|
+
|
28
|
+
* r1867, konstantin, 2007-10-05 06:19:45
|
29
|
+
* # 220, (re)open connection to server if none exists or connection params
|
30
|
+
have changed
|
31
|
+
|
32
|
+
== 1.2.1
|
33
|
+
|
34
|
+
* r2648, konstantin, 01-24-08 11:12:00
|
35
|
+
* net_fix.rb moved from right_aws gem to fix the problem with uploading the streamable
|
36
|
+
objects to S3
|
37
|
+
|
38
|
+
* r2764, konstantin, 02-08-08 00:05:00 +03:00
|
39
|
+
* "RightAws: incompatible Net::HTTP monkey-patch" exception is raised if our net_fix
|
40
|
+
patch was overriden (by attachment_fu for example, to avoid this load attachment_fu
|
41
|
+
before loading the right_http_connection gem).
|
42
|
+
|
43
|
+
== 1.2.2
|
44
|
+
|
45
|
+
* r3524, konstantin, 2008-04-17 11:35:42 +0400
|
46
|
+
* Fixed a problem with incorrect error handling (connection retries always failed).
|
47
|
+
|
48
|
+
== 1.2.3
|
49
|
+
|
50
|
+
- Added support for setting retry & timeout parameters in the constructor
|
51
|
+
- Improve handling of data streams during upload: if there is a failure and a retry, reset
|
52
|
+
the seek pointer for the subsequent re-request
|
53
|
+
|
54
|
+
== 1.2.4
|
55
|
+
|
56
|
+
* r4984, konstantin, 2008-08-11 14:49:18 +0400
|
57
|
+
* fixed a bug: <NoMethodError: You have a nil object when you didn't expect it!
|
58
|
+
The error occurred while evaluating nil.body_stream>
|
59
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
RightScale::HttpConnection
|
2
|
+
by RightScale, Inc.
|
3
|
+
www.RightScale.com
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Rightscale::HttpConnection is a robust HTTP/S library. It implements a retry
|
8
|
+
algorithm for low-level network errors.
|
9
|
+
|
10
|
+
== FEATURES:
|
11
|
+
|
12
|
+
- provides put/get streaming
|
13
|
+
- does configurable retries on connect and read timeouts, DNS failures, etc.
|
14
|
+
- HTTPS certificate checking
|
15
|
+
|
16
|
+
== SYNOPSIS:
|
17
|
+
|
18
|
+
|
19
|
+
== REQUIREMENTS:
|
20
|
+
|
21
|
+
- 2/11/08: If you use RightScale::HttpConnection in conjunction with attachment_fu, the
|
22
|
+
HttpConnection gem must be included (using the require statement) AFTER
|
23
|
+
attachment_fu.
|
24
|
+
This is due to a conflict between the HttpConnection gem and another
|
25
|
+
gem required by attachment_fu.
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
== INSTALL:
|
30
|
+
|
31
|
+
sudo gem install right_http_connection
|
32
|
+
|
33
|
+
== LICENSE:
|
34
|
+
|
35
|
+
Copyright (c) 2007-2008 RightScale, Inc.
|
36
|
+
|
37
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
38
|
+
a copy of this software and associated documentation files (the
|
39
|
+
'Software'), to deal in the Software without restriction, including
|
40
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
41
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
42
|
+
permit persons to whom the Software is furnished to do so, subject to
|
43
|
+
the following conditions:
|
44
|
+
|
45
|
+
The above copyright notice and this permission notice shall be
|
46
|
+
included in all copies or substantial portions of the Software.
|
47
|
+
|
48
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
49
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
50
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
51
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
52
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
53
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
54
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
9
|
+
require 'fileutils'
|
10
|
+
require 'hoe'
|
11
|
+
include FileUtils
|
12
|
+
require File.join(File.dirname(__FILE__), 'lib', 'right_http_connection')
|
13
|
+
|
14
|
+
AUTHOR = 'RightScale' # can also be an array of Authors
|
15
|
+
EMAIL = "rubygems@rightscale.com"
|
16
|
+
DESCRIPTION = "RightScale's robust HTTP/S connection module"
|
17
|
+
GEM_NAME = 'right_http_connection' # what ppl will type to install your gem
|
18
|
+
RUBYFORGE_PROJECT = 'rightscale' # The unix name for your project
|
19
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
20
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
21
|
+
|
22
|
+
NAME = "right_http_connection"
|
23
|
+
REV = nil # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
24
|
+
VERS = RightHttpConnection::VERSION::STRING + (REV ? ".#{REV}" : "")
|
25
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
|
26
|
+
RDOC_OPTS = ['--quiet', '--title', 'right_http_connection documentation',
|
27
|
+
"--opname", "index.html",
|
28
|
+
"--line-numbers",
|
29
|
+
"--main", "README",
|
30
|
+
"--inline-source"]
|
31
|
+
|
32
|
+
# Suppress Hoe's self-inclusion as a dependency for our Gem. This also keeps
|
33
|
+
# Rake & rubyforge out of the dependency list. Users must manually install
|
34
|
+
# these gems to run tests, etc.
|
35
|
+
# TRB 2/19/09: also do this for the extra_dev_deps array present in newer hoes.
|
36
|
+
# Older versions of RubyGems will try to install developer-dependencies as
|
37
|
+
# required runtime dependencies....
|
38
|
+
class Hoe
|
39
|
+
def extra_deps
|
40
|
+
@extra_deps.reject do |x|
|
41
|
+
Array(x).first == 'hoe'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
def extra_dev_deps
|
45
|
+
@extra_dev_deps.reject do |x|
|
46
|
+
Array(x).first == 'hoe'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generate all the Rake tasks
|
52
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
53
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
54
|
+
p.author = AUTHOR
|
55
|
+
p.description = DESCRIPTION
|
56
|
+
p.email = EMAIL
|
57
|
+
p.summary = DESCRIPTION
|
58
|
+
p.url = HOMEPATH
|
59
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
60
|
+
p.test_globs = ["test/**/test_*.rb"]
|
61
|
+
p.clean_globs = CLEAN #An array of file patterns to delete on clean.
|
62
|
+
p.remote_rdoc_dir = "right_http_gem_doc"
|
63
|
+
|
64
|
+
# == Optional
|
65
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
66
|
+
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
67
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
desc 'Generate website files'
|
72
|
+
task :website_generate do
|
73
|
+
Dir['website/**/*.txt'].each do |txt|
|
74
|
+
sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
desc 'Upload website files to rubyforge'
|
79
|
+
task :website_upload do
|
80
|
+
config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
|
81
|
+
host = "#{config["username"]}@rubyforge.org"
|
82
|
+
remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/"
|
83
|
+
# remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
84
|
+
local_dir = 'website'
|
85
|
+
sh %{rsync -av #{local_dir}/ #{host}:#{remote_dir}}
|
86
|
+
end
|
87
|
+
|
88
|
+
desc 'Generate and upload website files'
|
89
|
+
task :website => [:website_generate, :website_upload]
|
90
|
+
|
91
|
+
desc 'Release the website and new gem version'
|
92
|
+
task :deploy => [:check_version, :website, :release]
|
93
|
+
|
94
|
+
task :check_version do
|
95
|
+
unless ENV['VERSION']
|
96
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
97
|
+
exit
|
98
|
+
end
|
99
|
+
unless ENV['VERSION'] == VERS
|
100
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
101
|
+
exit
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2008 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#
|
23
|
+
#
|
24
|
+
|
25
|
+
# Net::HTTP and Net::HTTPGenericRequest fixes to support 100-continue on
|
26
|
+
# POST and PUT. The request must have 'expect' field set to '100-continue'.
|
27
|
+
|
28
|
+
|
29
|
+
module Net
|
30
|
+
|
31
|
+
class BufferedIO #:nodoc:
|
32
|
+
# Monkey-patch Net::BufferedIO to read > 1024 bytes from the socket at a time
|
33
|
+
|
34
|
+
# Default size (in bytes) of the max read from a socket into the user space read buffers for socket IO
|
35
|
+
DEFAULT_SOCKET_READ_SIZE = 16*1024
|
36
|
+
|
37
|
+
@@socket_read_size = DEFAULT_SOCKET_READ_SIZE
|
38
|
+
|
39
|
+
def self.socket_read_size=(readsize)
|
40
|
+
if(readsize <= 0)
|
41
|
+
return
|
42
|
+
end
|
43
|
+
@@socket_read_size = readsize
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.socket_read_size?()
|
47
|
+
@@socket_read_size
|
48
|
+
end
|
49
|
+
|
50
|
+
def rbuf_fill
|
51
|
+
timeout(@read_timeout) {
|
52
|
+
@rbuf << @io.sysread(@@socket_read_size)
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
#-- Net::HTTPGenericRequest --
|
59
|
+
|
60
|
+
class HTTPGenericRequest
|
61
|
+
# Monkey-patch Net::HTTPGenericRequest to read > 1024 bytes from the local data
|
62
|
+
# source at a time (used in streaming PUTs)
|
63
|
+
|
64
|
+
# Default size (in bytes) of the max read from a local source (File, String,
|
65
|
+
# etc.) to the user space write buffers for socket IO.
|
66
|
+
DEFAULT_LOCAL_READ_SIZE = 16*1024
|
67
|
+
|
68
|
+
@@local_read_size = DEFAULT_LOCAL_READ_SIZE
|
69
|
+
|
70
|
+
def self.local_read_size=(readsize)
|
71
|
+
if(readsize <= 0)
|
72
|
+
return
|
73
|
+
end
|
74
|
+
@@local_read_size = readsize
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.local_read_size?()
|
78
|
+
@@local_read_size
|
79
|
+
end
|
80
|
+
|
81
|
+
def exec(sock, ver, path, send_only=nil) #:nodoc: internal use only
|
82
|
+
if @body
|
83
|
+
send_request_with_body sock, ver, path, @body, send_only
|
84
|
+
elsif @body_stream
|
85
|
+
send_request_with_body_stream sock, ver, path, @body_stream, send_only
|
86
|
+
else
|
87
|
+
write_header(sock, ver, path)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def send_request_with_body(sock, ver, path, body, send_only=nil)
|
94
|
+
self.content_length = body.length
|
95
|
+
delete 'Transfer-Encoding'
|
96
|
+
supply_default_content_type
|
97
|
+
write_header(sock, ver, path) unless send_only == :body
|
98
|
+
sock.write(body) unless send_only == :header
|
99
|
+
end
|
100
|
+
|
101
|
+
def send_request_with_body_stream(sock, ver, path, f, send_only=nil)
|
102
|
+
unless content_length() or chunked?
|
103
|
+
raise ArgumentError,
|
104
|
+
"Content-Length not given and Transfer-Encoding is not `chunked'"
|
105
|
+
end
|
106
|
+
supply_default_content_type
|
107
|
+
write_header(sock, ver, path) unless send_only == :body
|
108
|
+
unless send_only == :header
|
109
|
+
if chunked?
|
110
|
+
while s = f.read(@@local_read_size)
|
111
|
+
sock.write(sprintf("%x\r\n", s.length) << s << "\r\n")
|
112
|
+
end
|
113
|
+
sock.write "0\r\n\r\n"
|
114
|
+
else
|
115
|
+
while s = f.read(@@local_read_size)
|
116
|
+
sock.write s
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
#-- Net::HTTP --
|
125
|
+
|
126
|
+
class HTTP
|
127
|
+
def request(req, body = nil, &block) # :yield: +response+
|
128
|
+
unless started?
|
129
|
+
start {
|
130
|
+
req['connection'] ||= 'close'
|
131
|
+
return request(req, body, &block)
|
132
|
+
}
|
133
|
+
end
|
134
|
+
if proxy_user()
|
135
|
+
unless use_ssl?
|
136
|
+
req.proxy_basic_auth proxy_user(), proxy_pass()
|
137
|
+
end
|
138
|
+
end
|
139
|
+
# set body
|
140
|
+
req.set_body_internal body
|
141
|
+
begin_transport req
|
142
|
+
# if we expect 100-continue then send a header first
|
143
|
+
send_only = ((req.is_a?(Post)||req.is_a?(Put)) && (req['expect']=='100-continue')) ? :header : nil
|
144
|
+
req.exec @socket, @curr_http_version, edit_path(req.path), send_only
|
145
|
+
begin
|
146
|
+
res = HTTPResponse.read_new(@socket)
|
147
|
+
# if we expected 100-continue then send a body
|
148
|
+
if res.is_a?(HTTPContinue) && send_only && req['content-length'].to_i > 0
|
149
|
+
req.exec @socket, @curr_http_version, edit_path(req.path), :body
|
150
|
+
end
|
151
|
+
end while res.kind_of?(HTTPContinue)
|
152
|
+
res.reading_body(@socket, req.response_body_permitted?) {
|
153
|
+
yield res if block_given?
|
154
|
+
}
|
155
|
+
end_transport req, res
|
156
|
+
res
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|