patron 0.13.4 → 1.0.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +97 -0
- data/README.md +113 -50
- data/ext/patron/extconf.rb +55 -20
- data/ext/patron/session_ext.c +1092 -761
- data/lib/patron/compat.rb +57 -0
- data/lib/patron/error.rb +25 -13
- data/lib/patron/header_parser.rb +27 -25
- data/lib/patron/request.rb +98 -142
- data/lib/patron/response.rb +33 -24
- data/lib/patron/response_decoding.rb +60 -67
- data/lib/patron/session.rb +127 -104
- data/lib/patron/util.rb +14 -12
- data/lib/patron/version.rb +3 -1
- data/lib/patron.rb +9 -15
- metadata +12 -49
- data/.autotest +0 -15
- data/.github/workflows/ci.yml +0 -26
- data/.gitignore +0 -10
- data/.rspec +0 -0
- data/.travis.yml +0 -13
- data/.yardopts +0 -1
- data/Gemfile +0 -17
- data/Rakefile +0 -31
- data/ext/patron/.gitignore +0 -4
- data/ext/patron/membuffer.c +0 -85
- data/ext/patron/membuffer.h +0 -78
- data/ext/patron/sglib.h +0 -1952
- data/lib/patron/proxy_type.rb +0 -11
- data/patron.gemspec +0 -38
- data/pic.png +0 -0
- data/script/console +0 -11
- data/script/test_server +0 -7
- data/spec/header_parser_spec.rb +0 -101
- data/spec/patron_spec.rb +0 -28
- data/spec/request_spec.rb +0 -77
- data/spec/response_spec.rb +0 -145
- data/spec/sample_response_headers/headers_wetransfer.txt +0 -18
- data/spec/sample_response_headers/headers_wetransfer_with_proxy_status.txt +0 -20
- data/spec/sample_response_headers/headers_wetransfer_with_redirect.txt +0 -24
- data/spec/sample_response_headers/headers_with_set_cookie.txt +0 -9
- data/spec/sample_response_headers/sample_http2_header.txt +0 -16
- data/spec/sample_response_headers/webmock_headers_without_trailing_crlf.txt +0 -15
- data/spec/session_spec.rb +0 -698
- data/spec/session_ssl_spec.rb +0 -313
- data/spec/spec_helper.rb +0 -34
- data/spec/support/certs/cacert.pem +0 -36
- data/spec/support/certs/privkey.pem +0 -51
- data/spec/support/config.ru +0 -146
- data/spec/support/fork.rb +0 -70
- data/spec/support/test_server.rb +0 -26
- data/spec/util_spec.rb +0 -71
data/lib/patron/proxy_type.rb
DELETED
data/patron.gemspec
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require 'patron/version'
|
|
5
|
-
|
|
6
|
-
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name = "patron"
|
|
8
|
-
spec.version = Patron::VERSION
|
|
9
|
-
spec.licenses = ["MIT"]
|
|
10
|
-
spec.platform = Gem::Platform::RUBY
|
|
11
|
-
spec.authors = ["Aeryn Riley Dowling-Toland"]
|
|
12
|
-
spec.email = ["aeryn.toland@gmail.com"]
|
|
13
|
-
spec.homepage = "https://github.com/toland/patron"
|
|
14
|
-
spec.summary = "Patron HTTP Client"
|
|
15
|
-
spec.description = "Ruby HTTP client library based on libcurl"
|
|
16
|
-
|
|
17
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
19
|
-
if spec.respond_to?(:metadata)
|
|
20
|
-
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
|
21
|
-
else
|
|
22
|
-
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
spec.required_rubygems_version = ">= 1.2.0"
|
|
26
|
-
|
|
27
|
-
spec.files = `git ls-files -z`.split("\x0")
|
|
28
|
-
spec.bindir = "exe"
|
|
29
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
30
|
-
spec.require_paths = ["lib", "ext"]
|
|
31
|
-
spec.extensions = ["ext/patron/extconf.rb"]
|
|
32
|
-
spec.post_install_message = %q{
|
|
33
|
-
Thank you for installing Patron. On OSX, make sure you are using libCURL with OpenSSL.
|
|
34
|
-
SecureTransport-based builds might cause crashes in forking environments.
|
|
35
|
-
|
|
36
|
-
For more info see https://github.com/curl/curl/issues/788
|
|
37
|
-
}
|
|
38
|
-
end
|
data/pic.png
DELETED
|
Binary file
|
data/script/console
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# File: script/console
|
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
|
4
|
-
|
|
5
|
-
cwd = File.dirname(__FILE__)
|
|
6
|
-
|
|
7
|
-
libs = " -I#{cwd + '/../lib'} -I#{cwd + '/../ext'}"
|
|
8
|
-
libs << " -r patron -r irb/completion"
|
|
9
|
-
|
|
10
|
-
puts "Loading Patron"
|
|
11
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/test_server
DELETED
data/spec/header_parser_spec.rb
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Patron::HeaderParser do
|
|
4
|
-
it 'parses a standard header' do
|
|
5
|
-
simple_headers_path = File.dirname(__FILE__) + '/sample_response_headers/headers_wetransfer.txt'
|
|
6
|
-
responses = Patron::HeaderParser.parse(File.read(simple_headers_path))
|
|
7
|
-
|
|
8
|
-
expect(responses.length).to eq(1)
|
|
9
|
-
first_response = responses[0]
|
|
10
|
-
expect(first_response.status_line).to eq("HTTP/1.1 200 OK")
|
|
11
|
-
expect(first_response.headers).to be_kind_of(Array)
|
|
12
|
-
expect(first_response.headers[0]).to eq("Date: Mon, 29 Jan 2018 00:09:09 GMT")
|
|
13
|
-
expect(first_response.headers[1]).to eq("Content-Type: text/html; charset=utf-8")
|
|
14
|
-
expect(first_response.headers[2]).to eq("Transfer-Encoding: chunked")
|
|
15
|
-
expect(first_response.headers[3]).to eq("Connection: keep-alive")
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'parses a sequence of responses resulting from a redirect' do
|
|
19
|
-
simple_headers_path = File.dirname(__FILE__) + '/sample_response_headers/headers_wetransfer_with_redirect.txt'
|
|
20
|
-
responses = Patron::HeaderParser.parse(File.read(simple_headers_path))
|
|
21
|
-
|
|
22
|
-
expect(responses.length).to eq(2)
|
|
23
|
-
first_response = responses[0]
|
|
24
|
-
|
|
25
|
-
expect(first_response.status_line).to eq("HTTP/1.1 301 Moved Permanently")
|
|
26
|
-
expect(first_response.headers).to be_kind_of(Array)
|
|
27
|
-
expect(first_response.headers[0]).to eq("Date: Mon, 29 Jan 2018 00:42:27 GMT")
|
|
28
|
-
expect(first_response.headers[2]).to eq("Connection: keep-alive")
|
|
29
|
-
expect(first_response.headers[3]).to eq("Location: https://wetransfer.com/")
|
|
30
|
-
expect(first_response.headers[4]).to be_nil
|
|
31
|
-
|
|
32
|
-
second_response = responses[1]
|
|
33
|
-
expect(second_response.status_line).to eq("HTTP/1.1 200 OK")
|
|
34
|
-
expect(second_response.headers).to be_kind_of(Array)
|
|
35
|
-
expect(second_response.headers[0]).to eq("Date: Mon, 29 Jan 2018 00:42:27 GMT")
|
|
36
|
-
expect(second_response.headers[1]).to eq("Content-Type: text/html; charset=utf-8")
|
|
37
|
-
expect(second_response.headers[2]).to eq("Transfer-Encoding: chunked")
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it 'parses response headers that set cookies' do
|
|
41
|
-
simple_headers_path = File.dirname(__FILE__) + '/sample_response_headers/headers_with_set_cookie.txt'
|
|
42
|
-
responses = Patron::HeaderParser.parse(File.read(simple_headers_path))
|
|
43
|
-
|
|
44
|
-
expect(responses.length).to eq(1)
|
|
45
|
-
first_response = responses[0]
|
|
46
|
-
|
|
47
|
-
expect(first_response.status_line).to eq("HTTP/1.1 200 OK")
|
|
48
|
-
expect(first_response.headers).to be_kind_of(Array)
|
|
49
|
-
expect(first_response.headers[0]).to eq("Content-Type: text/plain")
|
|
50
|
-
expect(first_response.headers[1]).to start_with('Server:')
|
|
51
|
-
expect(first_response.headers[2]).to eq("Date: Mon, 29 Jan 2018 01:50:54 GMT")
|
|
52
|
-
expect(first_response.headers[3]).to eq("Content-Length: 3")
|
|
53
|
-
expect(first_response.headers[4]).to eq("Connection: Keep-Alive")
|
|
54
|
-
expect(first_response.headers[5]).to eq("Set-Cookie: a=1")
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it 'parses response headers with an extra status line from a proxy' do
|
|
58
|
-
simple_headers_path = File.dirname(__FILE__) + '/sample_response_headers/headers_wetransfer_with_proxy_status.txt'
|
|
59
|
-
responses = Patron::HeaderParser.parse(File.read(simple_headers_path))
|
|
60
|
-
|
|
61
|
-
expect(responses.length).to eq(2)
|
|
62
|
-
first_response = responses[0]
|
|
63
|
-
|
|
64
|
-
expect(first_response.status_line).to eq("HTTP/1.1 200 Connection established")
|
|
65
|
-
expect(first_response.headers).to be_kind_of(Array)
|
|
66
|
-
expect(first_response.headers).to be_empty
|
|
67
|
-
|
|
68
|
-
second_response = responses[1]
|
|
69
|
-
expect(second_response.status_line).to eq("HTTP/1.1 200 OK")
|
|
70
|
-
expect(second_response.headers).to be_kind_of(Array)
|
|
71
|
-
expect(second_response.headers[0]).to eq("Date: Mon, 29 Jan 2018 00:09:09 GMT")
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it 'parses headers without the trailing CRLF from Webmock' do
|
|
75
|
-
path = File.dirname(__FILE__) + '/sample_response_headers/webmock_headers_without_trailing_crlf.txt'
|
|
76
|
-
responses = Patron::HeaderParser.parse(File.read(path))
|
|
77
|
-
|
|
78
|
-
expect(responses.length).to eq(1)
|
|
79
|
-
first_response = responses[0]
|
|
80
|
-
|
|
81
|
-
expect(first_response.status_line).to eq("HTTP/1.1 200 OK")
|
|
82
|
-
expect(first_response.headers).to be_kind_of(Array)
|
|
83
|
-
expect(first_response.headers).not_to be_empty
|
|
84
|
-
last_header = first_response.headers[-1]
|
|
85
|
-
expect(last_header).to eq('Connection: Close')
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it 'parses headers for an HTTP2 response' do
|
|
89
|
-
path = File.dirname(__FILE__) + '/sample_response_headers/sample_http2_header.txt'
|
|
90
|
-
responses = Patron::HeaderParser.parse(File.read(path))
|
|
91
|
-
|
|
92
|
-
expect(responses.length).to eq(1)
|
|
93
|
-
first_response = responses[0]
|
|
94
|
-
|
|
95
|
-
expect(first_response.status_line).to eq("HTTP/2 200")
|
|
96
|
-
expect(first_response.headers).to be_kind_of(Array)
|
|
97
|
-
expect(first_response.headers).not_to be_empty
|
|
98
|
-
last_header = first_response.headers[-1]
|
|
99
|
-
expect(last_header).to eq('strict-transport-security: max-age=15552000; includeSubDomains;')
|
|
100
|
-
end
|
|
101
|
-
end
|
data/spec/patron_spec.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require File.expand_path("./spec") + '/spec_helper.rb'
|
|
2
|
-
|
|
3
|
-
describe Patron do
|
|
4
|
-
|
|
5
|
-
it 'should return the user agent string' do
|
|
6
|
-
ua_str = Patron.user_agent_string
|
|
7
|
-
expect(ua_str).to include('curl')
|
|
8
|
-
expect(ua_str).to include('Patron')
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "should return the version number of the Patron library" do
|
|
12
|
-
version = Patron.version
|
|
13
|
-
expect(version).to match(%r|^\d+.\d+.\d+(\.\w+\.\d+)?$|)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "should return the version string of the libcurl library" do
|
|
17
|
-
version = Patron.libcurl_version
|
|
18
|
-
expect(version).to match(%r|^libcurl/\d+.\d+.\d+|)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "should return the version numbers of the libcurl library" do
|
|
22
|
-
version = Patron.libcurl_version_exact
|
|
23
|
-
expect(version.length).to eq(3)
|
|
24
|
-
expect(version[0]).to be > 0
|
|
25
|
-
expect(version[1]).to be >= 0
|
|
26
|
-
expect(version[2]).to be >= 0
|
|
27
|
-
end
|
|
28
|
-
end
|
data/spec/request_spec.rb
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
require File.expand_path("./spec") + '/spec_helper.rb'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
describe Patron::Request do
|
|
5
|
-
|
|
6
|
-
before(:each) do
|
|
7
|
-
@request = Patron::Request.new
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
describe :action do
|
|
11
|
-
|
|
12
|
-
it "should accept :get, :put, :post, :delete and :head" do
|
|
13
|
-
[:get, :put, :post, :delete, :head, :copy].each do |action|
|
|
14
|
-
expect {@request.action = action}.not_to raise_error
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "should raise an exception when assigned a bad value" do
|
|
19
|
-
expect {@request.action = :foo}.to raise_error(ArgumentError)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe :timeout do
|
|
25
|
-
|
|
26
|
-
it "should raise an exception when assigned a negative number" do
|
|
27
|
-
expect {@request.timeout = -1}.to raise_error(ArgumentError)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe :max_redirects do
|
|
33
|
-
|
|
34
|
-
it "should raise an error when assigned an integer smaller than -1" do
|
|
35
|
-
expect {@request.max_redirects = -2}.to raise_error(ArgumentError)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
describe :headers do
|
|
41
|
-
|
|
42
|
-
it "should raise an error when assigned something other than a hash" do
|
|
43
|
-
expect {@request.headers = :foo}.to raise_error(ArgumentError)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe :buffer_size do
|
|
49
|
-
|
|
50
|
-
it "should raise an exception when assigned a negative number" do
|
|
51
|
-
expect {@request.buffer_size = -1}.to raise_error(ArgumentError)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "should raise an exception when assigned 0" do
|
|
55
|
-
expect {@request.buffer_size = 0}.to raise_error(ArgumentError)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
describe :eql? do
|
|
61
|
-
|
|
62
|
-
it "should return true when two requests are equal" do
|
|
63
|
-
expect(@request).to eql(Patron::Request.new)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "should return false when two requests are not equal" do
|
|
67
|
-
req = Patron::Request.new
|
|
68
|
-
req.action = :post
|
|
69
|
-
expect(@request).not_to eql(req)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "should be able to serialize and deserialize itself" do
|
|
75
|
-
expect(Marshal.load(Marshal.dump(@request))).to eql(@request)
|
|
76
|
-
end
|
|
77
|
-
end
|
data/spec/response_spec.rb
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
# -*- coding: UTF-8 -*-
|
|
2
|
-
# Encoding pragma is needed for loading this test properly on Ruby < 2.0
|
|
3
|
-
|
|
4
|
-
## -------------------------------------------------------------------
|
|
5
|
-
##
|
|
6
|
-
## Copyright (c) 2009 Phillip Toland <phil.toland@gmail.com>
|
|
7
|
-
##
|
|
8
|
-
## Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
## of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
## in the Software without restriction, including without limitation the rights
|
|
11
|
-
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
## copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
## furnished to do so, subject to the following conditions:
|
|
14
|
-
##
|
|
15
|
-
## The above copyright notice and this permission notice shall be included in
|
|
16
|
-
## all copies or substantial portions of the Software.
|
|
17
|
-
##
|
|
18
|
-
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
-
## THE SOFTWARE.
|
|
25
|
-
##
|
|
26
|
-
## -------------------------------------------------------------------
|
|
27
|
-
require File.expand_path("./spec") + '/spec_helper.rb'
|
|
28
|
-
require 'webrick'
|
|
29
|
-
require 'base64'
|
|
30
|
-
require 'fileutils'
|
|
31
|
-
|
|
32
|
-
describe Patron::Response do
|
|
33
|
-
around(:each) do |example|
|
|
34
|
-
previous_internal = Encoding.default_internal
|
|
35
|
-
example.run
|
|
36
|
-
Encoding.default_internal = previous_internal
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
before(:each) do
|
|
40
|
-
@session = Patron::Session.new
|
|
41
|
-
@session.base_url = "http://localhost:9001"
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'recovers the status code' do
|
|
45
|
-
response = @session.get("/repetitiveheader")
|
|
46
|
-
expect(response.status).to be_kind_of(Integer)
|
|
47
|
-
expect(response.status).to eq(200)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it 'saves the definitive URL in the url attribute' do
|
|
51
|
-
headers = "HTTP/1.1 200 OK \r\nContent-Type: text/plain\r\n"
|
|
52
|
-
response = Patron::Response.new("http://example.com/url", 200, 0, headers, '', "UTF-8")
|
|
53
|
-
expect(response.url).to eq("http://example.com/url")
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it 'parses the status code and supports ok? and error?' do
|
|
57
|
-
headers = "HTTP/1.1 200 OK \r\nContent-Type: text/plain\r\n"
|
|
58
|
-
body = "abc"
|
|
59
|
-
response = Patron::Response.new("url", 200, 0, headers, body, "UTF-8")
|
|
60
|
-
expect(response.status).to eq(200)
|
|
61
|
-
expect(response).to be_ok
|
|
62
|
-
expect(response).not_to be_error
|
|
63
|
-
|
|
64
|
-
headers = "HTTP/1.1 400 Bad Request \r\nContent-Type: text/plain\r\n"
|
|
65
|
-
body = "abc"
|
|
66
|
-
response = Patron::Response.new("url", 400, 0, headers, body, "UTF-8")
|
|
67
|
-
expect(response.status).to eq(400)
|
|
68
|
-
expect(response).not_to be_ok
|
|
69
|
-
expect(response).to be_error
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "should strip extra spaces from header values" do
|
|
73
|
-
response = @session.get("/test")
|
|
74
|
-
# All digits, no spaces
|
|
75
|
-
expect(response.headers['Content-Length']).to match(/^\d+$/)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "should return an array of values when multiple header fields have same name" do
|
|
79
|
-
response = @session.get("/repetitiveheader")
|
|
80
|
-
expect(response.headers['Set-Cookie']).to be == ["a=1","b=2"]
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
describe '#decoded_body and #inspectable_body' do
|
|
84
|
-
it "should raise with explicitly binary response bodies but allow an inspectable body" do
|
|
85
|
-
Encoding.default_internal = Encoding::UTF_8
|
|
86
|
-
response = @session.get("/picture")
|
|
87
|
-
expect(response.headers['Content-Type']).to be == 'image/png'
|
|
88
|
-
expect(response.body.encoding).to be == Encoding::BINARY
|
|
89
|
-
expect(response).not_to be_body_decodable
|
|
90
|
-
expect {
|
|
91
|
-
response.decoded_body
|
|
92
|
-
}.to raise_error(Patron::NonRepresentableBody)
|
|
93
|
-
|
|
94
|
-
inspectable = response.inspectable_body
|
|
95
|
-
expect(inspectable.encoding).to eq(Encoding::UTF_8)
|
|
96
|
-
expect(inspectable).to be_valid_encoding
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "should encode body in the internal charset" do
|
|
100
|
-
allow(Encoding).to receive(:default_internal).and_return("UTF-8")
|
|
101
|
-
|
|
102
|
-
greek_encoding = Encoding.find("ISO-8859-7")
|
|
103
|
-
utf_encoding = Encoding.find("UTF-8")
|
|
104
|
-
|
|
105
|
-
headers = "HTTP/1.1 200 OK \r\nContent-Type: text/css;charset=ISO-8859-7\r\n"
|
|
106
|
-
body = "Ππ".encode(greek_encoding) # Greek alphabet
|
|
107
|
-
|
|
108
|
-
response = Patron::Response.new("url", "status", 0, headers, body, nil)
|
|
109
|
-
|
|
110
|
-
expect(response).to be_body_decodable
|
|
111
|
-
expect(response.decoded_body.encoding).to eql(utf_encoding)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
it "should fallback to default charset when header or body charset is not valid" do
|
|
115
|
-
allow(Encoding).to receive(:default_internal).and_return("UTF-8")
|
|
116
|
-
|
|
117
|
-
encoding = Encoding.find("UTF-8")
|
|
118
|
-
headers = "HTTP/1.1 200 OK \r\nContent-Type: text/css; charset=invalid\r\n"
|
|
119
|
-
body = "who knows which encoding this CSS is in?"
|
|
120
|
-
|
|
121
|
-
response = Patron::Response.new("url", "status", 0, headers, body, "UTF-8")
|
|
122
|
-
expect(response.charset).to eq('invalid')
|
|
123
|
-
|
|
124
|
-
expect(response).not_to be_body_decodable
|
|
125
|
-
expect {
|
|
126
|
-
response.decoded_body
|
|
127
|
-
}.to raise_error(Patron::HeaderCharsetInvalid)
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it "decodes a header that contains UTF-8 even though internal encoding is ASCII" do
|
|
132
|
-
Encoding.default_internal = Encoding::ASCII
|
|
133
|
-
encoding = Encoding.find("UTF-8")
|
|
134
|
-
headers = "HTTP/1.1 200 OK \r\nContent-Disposition: attachment,filename=\"žфайлец.txt\"\r\n"
|
|
135
|
-
body = "this is a file with a Russian filename set in content-disposition"
|
|
136
|
-
|
|
137
|
-
response = Patron::Response.new("url", "status", 0, headers, body, "UTF-8")
|
|
138
|
-
dispo = response.headers['Content-Disposition']
|
|
139
|
-
expect(dispo.encoding).to eq(Encoding::UTF_8)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
it "should be able to serialize and deserialize itself" do
|
|
143
|
-
expect(Marshal.load(Marshal.dump(@request))).to eql(@request)
|
|
144
|
-
end
|
|
145
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
HTTP/1.1 200 OK
|
|
2
|
-
Date: Mon, 29 Jan 2018 00:09:09 GMT
|
|
3
|
-
Content-Type: text/html; charset=utf-8
|
|
4
|
-
Transfer-Encoding: chunked
|
|
5
|
-
Connection: keep-alive
|
|
6
|
-
X-Frame-Options: SAMEORIGIN
|
|
7
|
-
X-XSS-Protection: 1; mode=block
|
|
8
|
-
X-Content-Type-Options: nosniff
|
|
9
|
-
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
|
|
10
|
-
Pragma: no-cache
|
|
11
|
-
Expires: Fri, 01 Jan 1990 00:00:00 GMT
|
|
12
|
-
Vary: Accept-Encoding, Origin
|
|
13
|
-
Set-Cookie: _wt_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJTllOGNkZDg3N2Y2Mzc2M2E1NWY2NTQwMjYzNzljODJhBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMXk4YWtnZDVNYlRYUmJJWkFFaWkzVXFWM3IzbE1aU2xSbFl3SDQ3aHArbU09BjsARg%3D%3D--fe13900e81f693acb4a80d372d864c78704fa776; domain=wetransfer.com; path=/; secure; HttpOnly
|
|
14
|
-
X-Request-Id: 62b0d737-b0f8-400b-ac3a-0f84acf241af
|
|
15
|
-
X-Opaque: dev-1.wt-19171
|
|
16
|
-
X-Runtime: 0.116529
|
|
17
|
-
Strict-Transport-Security: max-age=15552000; includeSubDomains;
|
|
18
|
-
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
HTTP/1.1 200 Connection established
|
|
2
|
-
|
|
3
|
-
HTTP/1.1 200 OK
|
|
4
|
-
Date: Mon, 29 Jan 2018 00:09:09 GMT
|
|
5
|
-
Content-Type: text/html; charset=utf-8
|
|
6
|
-
Transfer-Encoding: chunked
|
|
7
|
-
Connection: keep-alive
|
|
8
|
-
X-Frame-Options: SAMEORIGIN
|
|
9
|
-
X-XSS-Protection: 1; mode=block
|
|
10
|
-
X-Content-Type-Options: nosniff
|
|
11
|
-
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
|
|
12
|
-
Pragma: no-cache
|
|
13
|
-
Expires: Fri, 01 Jan 1990 00:00:00 GMT
|
|
14
|
-
Vary: Accept-Encoding, Origin
|
|
15
|
-
Set-Cookie: _wt_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJTllOGNkZDg3N2Y2Mzc2M2E1NWY2NTQwMjYzNzljODJhBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMXk4YWtnZDVNYlRYUmJJWkFFaWkzVXFWM3IzbE1aU2xSbFl3SDQ3aHArbU09BjsARg%3D%3D--fe13900e81f693acb4a80d372d864c78704fa776; domain=wetransfer.com; path=/; secure; HttpOnly
|
|
16
|
-
X-Request-Id: 62b0d737-b0f8-400b-ac3a-0f84acf241af
|
|
17
|
-
X-Opaque: dev-1.wt-19171
|
|
18
|
-
X-Runtime: 0.116529
|
|
19
|
-
Strict-Transport-Security: max-age=15552000; includeSubDomains;
|
|
20
|
-
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
HTTP/1.1 301 Moved Permanently
|
|
2
|
-
Date: Mon, 29 Jan 2018 00:42:27 GMT
|
|
3
|
-
Content-Length: 0
|
|
4
|
-
Connection: keep-alive
|
|
5
|
-
Location: https://wetransfer.com/
|
|
6
|
-
|
|
7
|
-
HTTP/1.1 200 OK
|
|
8
|
-
Date: Mon, 29 Jan 2018 00:42:27 GMT
|
|
9
|
-
Content-Type: text/html; charset=utf-8
|
|
10
|
-
Transfer-Encoding: chunked
|
|
11
|
-
Connection: keep-alive
|
|
12
|
-
X-Frame-Options: SAMEORIGIN
|
|
13
|
-
X-XSS-Protection: 1; mode=block
|
|
14
|
-
X-Content-Type-Options: nosniff
|
|
15
|
-
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
|
|
16
|
-
Pragma: no-cache
|
|
17
|
-
Expires: Fri, 01 Jan 1990 00:00:00 GMT
|
|
18
|
-
Vary: Accept-Encoding, Origin
|
|
19
|
-
Set-Cookie: _wt_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJWYyMGFmZGRlY2QyNDJkNTA3YTc2YmJmYzg2MWNhMGZlBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMUkvMUJqR0tCelZxQytKQU1kbDV4ZW5xNDNSaUlDNnVrODhDTEY4Q0dxbXM9BjsARg%3D%3D--b46297a54dd838e0c26b5559314b10deb1f59312; domain=wetransfer.com; path=/; secure; HttpOnly
|
|
20
|
-
X-Request-Id: 09e7a0ef-e9a1-4519-a580-8185e6d64c1c
|
|
21
|
-
X-Opaque: dev-1.wt-24185
|
|
22
|
-
X-Runtime: 0.102958
|
|
23
|
-
Strict-Transport-Security: max-age=15552000; includeSubDomains;
|
|
24
|
-
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
HTTP/2 200
|
|
2
|
-
date: Fri, 16 Feb 2018 01:59:32 GMT
|
|
3
|
-
content-type: text/html; charset=utf-8
|
|
4
|
-
x-frame-options: SAMEORIGIN
|
|
5
|
-
x-xss-protection: 1; mode=block
|
|
6
|
-
x-content-type-options: nosniff
|
|
7
|
-
cache-control: no-cache, no-store, max-age=0, must-revalidate
|
|
8
|
-
pragma: no-cache
|
|
9
|
-
expires: Fri, 01 Jan 1990 00:00:00 GMT
|
|
10
|
-
vary: Accept-Encoding, Origin
|
|
11
|
-
set-cookie: _wt_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJTAyMTlhNTA4ZDNlYzVlMWJlMDFjZDdiOWUwMDBmMjAzBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMWxHRlFjRjNGRXRaS2pVR1RrNXVvNHkwZ3didUV4L1htTXExRUppYytNV1k9BjsARg%3D%3D--15724585750f7e220903e84f5978758cb8c67aea; domain=wetransfer.com; path=/; secure; HttpOnly
|
|
12
|
-
x-request-id: 668bd810-42ae-4e02-8c58-3f9d7b052365
|
|
13
|
-
x-opaque: 6d43d0f0705486926447448fc17c8ded512fdeaf-1.wt-17271
|
|
14
|
-
x-runtime: 0.159185
|
|
15
|
-
strict-transport-security: max-age=15552000; includeSubDomains;
|
|
16
|
-
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
HTTP/1.1 200 OK
|
|
2
|
-
Cache-Control: max-age=0, private, must-revalidate
|
|
3
|
-
Content-Type: application/json; charset=utf-8
|
|
4
|
-
Date: Mon, 31 Mar 2014 09:06:55 GMT
|
|
5
|
-
Etag: "99914b932bd37a50b983c5e7c90ae93b"
|
|
6
|
-
Status: 200 OK
|
|
7
|
-
Strict-Transport-Security: max-age=31536000
|
|
8
|
-
X-Content-Type-Options: nosniff
|
|
9
|
-
X-Frame-Options: SAMEORIGIN
|
|
10
|
-
X-Request-Id: 58f4c05f-0f35-4957-ad73-1c6eb25ff1cc
|
|
11
|
-
X-Runtime: 0.014435
|
|
12
|
-
X-Ua-Compatible: chrome=1
|
|
13
|
-
X-Xss-Protection: 1; mode=block
|
|
14
|
-
Transfer-Encoding: chunked
|
|
15
|
-
Connection: Close
|