htty 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{spec/system/scenarios/exit/actual_stderr → .gemtest} +0 -0
- data/.gitignore +8 -0
- data/.yardopts +1 -0
- data/Gemfile +8 -0
- data/History.markdown +28 -20
- data/MIT-LICENSE.markdown +1 -1
- data/README.markdown +37 -37
- data/Rakefile +85 -0
- data/autotest/discover.rb +3 -0
- data/htty.gemspec +36 -0
- data/lib/htty.rb +1 -6
- data/lib/htty/cli/body_open_command.rb +93 -0
- data/lib/htty/cli/command.rb +5 -7
- data/lib/htty/cli/commands/address.rb +1 -1
- data/lib/htty/cli/commands/body_request.rb +3 -1
- data/lib/htty/cli/commands/body_request_open.rb +46 -0
- data/lib/htty/cli/commands/body_response.rb +5 -3
- data/lib/htty/cli/commands/body_response_open.rb +57 -0
- data/lib/htty/cli/commands/body_set.rb +1 -1
- data/lib/htty/cli/commands/body_unset.rb +1 -1
- data/lib/htty/cli/commands/cookies_add.rb +1 -1
- data/lib/htty/cli/commands/cookies_remove.rb +1 -1
- data/lib/htty/cli/commands/cookies_remove_all.rb +1 -1
- data/lib/htty/cli/commands/cookies_use.rb +1 -1
- data/lib/htty/cli/commands/follow.rb +1 -1
- data/lib/htty/cli/commands/fragment_set.rb +1 -1
- data/lib/htty/cli/commands/fragment_unset.rb +1 -1
- data/lib/htty/cli/commands/headers_set.rb +1 -1
- data/lib/htty/cli/commands/headers_unset.rb +1 -1
- data/lib/htty/cli/commands/headers_unset_all.rb +1 -1
- data/lib/htty/cli/commands/host_set.rb +1 -1
- data/lib/htty/cli/commands/path_set.rb +1 -1
- data/lib/htty/cli/commands/port_set.rb +1 -1
- data/lib/htty/cli/commands/query_add.rb +1 -1
- data/lib/htty/cli/commands/query_remove.rb +1 -1
- data/lib/htty/cli/commands/query_set.rb +1 -1
- data/lib/htty/cli/commands/query_unset.rb +1 -1
- data/lib/htty/cli/commands/query_unset_all.rb +1 -1
- data/lib/htty/cli/commands/reuse.rb +1 -1
- data/lib/htty/cli/commands/scheme_set.rb +1 -1
- data/lib/htty/cli/commands/userinfo_set.rb +1 -1
- data/lib/htty/cli/commands/userinfo_unset.rb +1 -1
- data/lib/htty/cli/http_method_command.rb +1 -1
- data/lib/htty/platform.rb +10 -0
- data/lib/htty/request.rb +5 -1
- data/lib/htty/tempfile_preserving_extname.rb +16 -0
- data/lib/htty/version.rb +6 -0
- data/spec/unit/htty/cli/commands/body_request_spec.rb +4 -9
- data/spec/unit/htty/cli/commands/body_response_spec.rb +3 -1
- data/spec/unit/htty/request_spec.rb +10 -1
- data/spec/unit/{htty_spec.rb → htty/version_spec.rb} +1 -1
- metadata +145 -35
- data/VERSION +0 -1
- data/spec/system/scenarios/exit/actual_stdout +0 -2
- data/spec/system/scenarios/quit/actual_stderr +0 -0
- data/spec/system/scenarios/quit/actual_stdout +0 -2
data/lib/htty/cli/command.rb
CHANGED
@@ -200,15 +200,13 @@ public
|
|
200
200
|
|
201
201
|
protected
|
202
202
|
|
203
|
-
# Yields the last request in #session. If
|
204
|
-
#
|
205
|
-
def
|
203
|
+
# Yields the last request in #session. If the block returns a different
|
204
|
+
# request, it is added to the requests of #session.
|
205
|
+
def add_request_if_new
|
206
206
|
requests = session.requests
|
207
207
|
last_request = requests.last
|
208
|
-
|
209
|
-
requests <<
|
210
|
-
else
|
211
|
-
requests[requests.length - 1] = yield(last_request)
|
208
|
+
unless (new_request = yield(last_request)).equal?(last_request)
|
209
|
+
requests << new_request
|
212
210
|
end
|
213
211
|
self
|
214
212
|
end
|
@@ -80,7 +80,7 @@ class HTTY::CLI::Commands::Address < HTTY::CLI::Command
|
|
80
80
|
|
81
81
|
# Performs the _address_ command.
|
82
82
|
def perform
|
83
|
-
|
83
|
+
add_request_if_new do |request|
|
84
84
|
self.class.notify_if_cookies_cleared request do
|
85
85
|
request.address(*arguments)
|
86
86
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.expand_path("#{File.dirname __FILE__}/../command")
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/body_request_open")
|
2
3
|
require File.expand_path("#{File.dirname __FILE__}/body_response")
|
3
4
|
require File.expand_path("#{File.dirname __FILE__}/body_set")
|
4
5
|
require File.expand_path("#{File.dirname __FILE__}/body_unset")
|
@@ -32,7 +33,8 @@ class HTTY::CLI::Commands::BodyRequest < HTTY::CLI::Command
|
|
32
33
|
|
33
34
|
# Returns related command classes for the _body-request_ command.
|
34
35
|
def self.see_also_commands
|
35
|
-
[HTTY::CLI::Commands::
|
36
|
+
[HTTY::CLI::Commands::BodyRequestOpen,
|
37
|
+
HTTY::CLI::Commands::BodySet,
|
36
38
|
HTTY::CLI::Commands::BodyUnset,
|
37
39
|
HTTY::CLI::Commands::HeadersRequest,
|
38
40
|
HTTY::CLI::Commands::BodyResponse]
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path("#{File.dirname __FILE__}/../body_open_command")
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../command")
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/body_request")
|
4
|
+
require File.expand_path("#{File.dirname __FILE__}/body_response_open")
|
5
|
+
|
6
|
+
module HTTY; end
|
7
|
+
|
8
|
+
class HTTY::CLI; end
|
9
|
+
|
10
|
+
module HTTY::CLI::Commands; end
|
11
|
+
|
12
|
+
# Encapsulates the _body-request-open_ command.
|
13
|
+
class HTTY::CLI::Commands::BodyRequestOpen < HTTY::CLI::Command
|
14
|
+
|
15
|
+
include HTTY::CLI::BodyOpenCommand
|
16
|
+
|
17
|
+
# Returns the name of a category under which help for the _body-request-open_
|
18
|
+
# command should appear.
|
19
|
+
def self.category
|
20
|
+
'Building Requests'
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the help text for the _body-request-open_ command.
|
24
|
+
def self.help
|
25
|
+
'Opens the body of the request in an external program'
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the preamble to the extended help text for the _body-request-open_
|
29
|
+
# command.
|
30
|
+
def self.help_extended_preamble
|
31
|
+
'Opens the body content used for the request in a program on your system ' +
|
32
|
+
'that is mapped to the type of content. Does not communicate with the host.'
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns related command classes for the _body-request-open_ command.
|
36
|
+
def self.see_also_commands
|
37
|
+
[HTTY::CLI::Commands::BodyRequest,
|
38
|
+
HTTY::CLI::Commands::BodyResponseOpen]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Performs the _body-request-open_ command.
|
42
|
+
def perform
|
43
|
+
open session.requests.last
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.expand_path("#{File.dirname __FILE__}/../../no_response_error")
|
2
2
|
require File.expand_path("#{File.dirname __FILE__}/../command")
|
3
3
|
require File.expand_path("#{File.dirname __FILE__}/body_request")
|
4
|
+
require File.expand_path("#{File.dirname __FILE__}/body_response_open")
|
4
5
|
require File.expand_path("#{File.dirname __FILE__}/headers_response")
|
5
6
|
require File.expand_path("#{File.dirname __FILE__}/status")
|
6
7
|
|
@@ -13,8 +14,8 @@ module HTTY::CLI::Commands; end
|
|
13
14
|
# Encapsulates the _body-response_ command.
|
14
15
|
class HTTY::CLI::Commands::BodyResponse < HTTY::CLI::Command
|
15
16
|
|
16
|
-
# Returns the name of a category under which help for the
|
17
|
-
# should appear.
|
17
|
+
# Returns the name of a category under which help for the _body-response_
|
18
|
+
# command should appear.
|
18
19
|
def self.category
|
19
20
|
'Inspecting Responses'
|
20
21
|
end
|
@@ -38,7 +39,8 @@ class HTTY::CLI::Commands::BodyResponse < HTTY::CLI::Command
|
|
38
39
|
|
39
40
|
# Returns related command classes for the _body-response_ command.
|
40
41
|
def self.see_also_commands
|
41
|
-
[HTTY::CLI::Commands::
|
42
|
+
[HTTY::CLI::Commands::BodyResponseOpen,
|
43
|
+
HTTY::CLI::Commands::HeadersResponse,
|
42
44
|
HTTY::CLI::Commands::Status,
|
43
45
|
HTTY::CLI::Commands::BodyRequest]
|
44
46
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path("#{File.dirname __FILE__}/../../no_response_error")
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../body_open_command")
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/../command")
|
4
|
+
require File.expand_path("#{File.dirname __FILE__}/body_request_open")
|
5
|
+
require File.expand_path("#{File.dirname __FILE__}/body_response")
|
6
|
+
|
7
|
+
module HTTY; end
|
8
|
+
|
9
|
+
class HTTY::CLI; end
|
10
|
+
|
11
|
+
module HTTY::CLI::Commands; end
|
12
|
+
|
13
|
+
# Encapsulates the _body-response-open_ command.
|
14
|
+
class HTTY::CLI::Commands::BodyResponseOpen < HTTY::CLI::Command
|
15
|
+
|
16
|
+
include HTTY::CLI::BodyOpenCommand
|
17
|
+
|
18
|
+
# Returns the name of a category under which help for the _body-response-open_
|
19
|
+
# command should appear.
|
20
|
+
def self.category
|
21
|
+
'Inspecting Responses'
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns the string used to invoke the _body-response-open_ command from the
|
25
|
+
# command line.
|
26
|
+
def self.command_line
|
27
|
+
'body[-response]-open'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the help text for the _body-response-open_ command.
|
31
|
+
def self.help
|
32
|
+
'Opens the body of the response in an external program'
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the preamble to the extended help text for the _body-response-open_
|
36
|
+
# command.
|
37
|
+
def self.help_extended_preamble
|
38
|
+
'Opens the body content received in the response in a program on your ' +
|
39
|
+
'system that is mapped to the type of content. Does not communicate with ' +
|
40
|
+
'the host.'
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns related command classes for the _body-response-open_ command.
|
44
|
+
def self.see_also_commands
|
45
|
+
[HTTY::CLI::Commands::BodyResponse,
|
46
|
+
HTTY::CLI::Commands::BodyRequestOpen]
|
47
|
+
end
|
48
|
+
|
49
|
+
# Performs the _body-response-open_ command.
|
50
|
+
def perform
|
51
|
+
unless (response = session.last_response)
|
52
|
+
raise HTTY::NoResponseError
|
53
|
+
end
|
54
|
+
open response
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -41,7 +41,7 @@ class HTTY::CLI::Commands::BodySet < HTTY::CLI::Command
|
|
41
41
|
|
42
42
|
# Performs the _body-set_ command.
|
43
43
|
def perform
|
44
|
-
|
44
|
+
add_request_if_new do |request|
|
45
45
|
puts notice('Hit Return three times to signify the end of the body')
|
46
46
|
lines = []
|
47
47
|
empty_line_count = 0
|
@@ -40,7 +40,7 @@ class HTTY::CLI::Commands::CookiesRemoveAll < HTTY::CLI::Command
|
|
40
40
|
|
41
41
|
# Performs the _cookies-remove-all_ command.
|
42
42
|
def perform
|
43
|
-
|
43
|
+
add_request_if_new do |request|
|
44
44
|
request.cookies_remove_all(*arguments)
|
45
45
|
end
|
46
46
|
end
|
@@ -52,7 +52,7 @@ class HTTY::CLI::Commands::CookiesUse < HTTY::CLI::Command
|
|
52
52
|
"wrong number of arguments (#{arguments.length} for 0)"
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
add_request_if_new do |request|
|
56
56
|
changed_request = request.cookies_use(session.last_response)
|
57
57
|
phrase = pluralize('cookie', changed_request.cookies.length)
|
58
58
|
phrase = phrase[0..0].upcase + phrase[1..-1]
|
@@ -43,7 +43,7 @@ class HTTY::CLI::Commands::Follow < HTTY::CLI::Command
|
|
43
43
|
"wrong number of arguments (#{arguments.length} for 0)"
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
add_request_if_new do |request|
|
47
47
|
self.class.notify_if_cookies_cleared request do
|
48
48
|
request.follow session.last_response
|
49
49
|
end
|
@@ -48,7 +48,7 @@ class HTTY::CLI::Commands::FragmentSet < HTTY::CLI::Command
|
|
48
48
|
|
49
49
|
# Performs the _fragment-set_ command.
|
50
50
|
def perform
|
51
|
-
|
51
|
+
add_request_if_new do |request|
|
52
52
|
clean_arguments = arguments.collect do |a|
|
53
53
|
a.gsub(/^#/, '')
|
54
54
|
end
|
@@ -38,7 +38,7 @@ class HTTY::CLI::Commands::FragmentUnset < HTTY::CLI::Command
|
|
38
38
|
|
39
39
|
# Performs the _fragment-unset_ command.
|
40
40
|
def perform
|
41
|
-
|
41
|
+
add_request_if_new do |request|
|
42
42
|
self.class.notify_if_cookies_cleared request do
|
43
43
|
request.fragment_unset(*arguments)
|
44
44
|
end
|
@@ -38,7 +38,7 @@ class HTTY::CLI::Commands::HeadersUnsetAll < HTTY::CLI::Command
|
|
38
38
|
|
39
39
|
# Performs the _headers-unset-all_ command.
|
40
40
|
def perform
|
41
|
-
|
41
|
+
add_request_if_new do |request|
|
42
42
|
request.headers_unset_all(*arguments)
|
43
43
|
end
|
44
44
|
end
|
@@ -44,7 +44,7 @@ class HTTY::CLI::Commands::HostSet < HTTY::CLI::Command
|
|
44
44
|
|
45
45
|
# Performs the _host-set_ command.
|
46
46
|
def perform
|
47
|
-
|
47
|
+
add_request_if_new do |request|
|
48
48
|
self.class.notify_if_cookies_cleared request do
|
49
49
|
request.host_set(*arguments)
|
50
50
|
end
|
@@ -46,7 +46,7 @@ class HTTY::CLI::Commands::PathSet < HTTY::CLI::Command
|
|
46
46
|
|
47
47
|
# Performs the _path-set_ command.
|
48
48
|
def perform
|
49
|
-
|
49
|
+
add_request_if_new do |request|
|
50
50
|
self.class.notify_if_cookies_cleared request do
|
51
51
|
request.path_set(*escape_or_warn_of_escape_sequences(arguments))
|
52
52
|
end
|
@@ -45,7 +45,7 @@ class HTTY::CLI::Commands::PortSet < HTTY::CLI::Command
|
|
45
45
|
|
46
46
|
# Performs the _port-set_ command.
|
47
47
|
def perform
|
48
|
-
|
48
|
+
add_request_if_new do |request|
|
49
49
|
self.class.notify_if_cookies_cleared request do
|
50
50
|
request.port_set(*arguments)
|
51
51
|
end
|
@@ -60,7 +60,7 @@ class HTTY::CLI::Commands::QueryAdd < HTTY::CLI::Command
|
|
60
60
|
|
61
61
|
# Performs the _query-add_ command.
|
62
62
|
def perform
|
63
|
-
|
63
|
+
add_request_if_new do |request|
|
64
64
|
self.class.notify_if_cookies_cleared request do
|
65
65
|
escaped_arguments = escape_or_warn_of_escape_sequences(arguments)
|
66
66
|
escaped_arguments.each_slice 2 do |name, value|
|
@@ -62,7 +62,7 @@ class HTTY::CLI::Commands::QueryRemove < HTTY::CLI::Command
|
|
62
62
|
|
63
63
|
# Performs the _query-remove_ command.
|
64
64
|
def perform
|
65
|
-
|
65
|
+
add_request_if_new do |request|
|
66
66
|
self.class.notify_if_cookies_cleared request do
|
67
67
|
request.query_remove(*escape_or_warn_of_escape_sequences(arguments))
|
68
68
|
end
|
@@ -60,7 +60,7 @@ class HTTY::CLI::Commands::QuerySet < HTTY::CLI::Command
|
|
60
60
|
|
61
61
|
# Performs the _query-set_ command.
|
62
62
|
def perform
|
63
|
-
|
63
|
+
add_request_if_new do |request|
|
64
64
|
self.class.notify_if_cookies_cleared request do
|
65
65
|
escaped_arguments = escape_or_warn_of_escape_sequences(arguments)
|
66
66
|
escaped_arguments.each_slice 2 do |name, value|
|
@@ -61,7 +61,7 @@ class HTTY::CLI::Commands::QueryUnset < HTTY::CLI::Command
|
|
61
61
|
|
62
62
|
# Performs the _query-unset_ command.
|
63
63
|
def perform
|
64
|
-
|
64
|
+
add_request_if_new do |request|
|
65
65
|
self.class.notify_if_cookies_cleared request do
|
66
66
|
unset_method = (arguments.length == 2) ? :query_remove : :query_unset
|
67
67
|
request.send(unset_method,
|
@@ -40,7 +40,7 @@ class HTTY::CLI::Commands::QueryUnsetAll < HTTY::CLI::Command
|
|
40
40
|
|
41
41
|
# Performs the _query-unset-all_ command.
|
42
42
|
def perform
|
43
|
-
|
43
|
+
add_request_if_new do |request|
|
44
44
|
self.class.notify_if_cookies_cleared request do
|
45
45
|
request.query_unset_all(*arguments)
|
46
46
|
end
|
@@ -59,7 +59,7 @@ class HTTY::CLI::Commands::SchemeSet < HTTY::CLI::Command
|
|
59
59
|
|
60
60
|
# Performs the _scheme-set_ command.
|
61
61
|
def perform
|
62
|
-
|
62
|
+
add_request_if_new do |request|
|
63
63
|
self.class.notify_if_cookies_cleared request do
|
64
64
|
request.scheme_set(*arguments)
|
65
65
|
end
|
@@ -55,7 +55,7 @@ class HTTY::CLI::Commands::UserinfoSet < HTTY::CLI::Command
|
|
55
55
|
|
56
56
|
# Performs the _userinfo-set_ command.
|
57
57
|
def perform
|
58
|
-
|
58
|
+
add_request_if_new do |request|
|
59
59
|
arguments = self.arguments
|
60
60
|
if (arguments.length == 1) && (arguments.first.scan(':').length == 1)
|
61
61
|
arguments = arguments.first.split(':')
|
@@ -37,7 +37,7 @@ class HTTY::CLI::Commands::UserinfoUnset < HTTY::CLI::Command
|
|
37
37
|
|
38
38
|
# Performs the _userinfo-unset_ command.
|
39
39
|
def perform
|
40
|
-
|
40
|
+
add_request_if_new do |request|
|
41
41
|
self.class.notify_if_cookies_cleared request do
|
42
42
|
request.userinfo_unset(*arguments)
|
43
43
|
end
|
@@ -33,7 +33,7 @@ module HTTY::CLI::HTTPMethodCommand
|
|
33
33
|
|
34
34
|
# Performs the command.
|
35
35
|
def perform
|
36
|
-
|
36
|
+
add_request_if_new do |request|
|
37
37
|
unless body? || request.body.to_s.empty?
|
38
38
|
puts notice("The body of your #{method.to_s.upcase} request is not " +
|
39
39
|
'being sent')
|
data/lib/htty/request.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'base64'
|
2
2
|
require 'pathname'
|
3
3
|
require 'uri'
|
4
|
-
require File.expand_path("#{File.dirname __FILE__}/../htty")
|
4
|
+
require File.expand_path("#{File.dirname __FILE__}/../htty/version")
|
5
5
|
require File.expand_path("#{File.dirname __FILE__}/cookies_util")
|
6
6
|
require File.expand_path("#{File.dirname __FILE__}/no_location_header_error")
|
7
7
|
require File.expand_path("#{File.dirname __FILE__}/no_response_error")
|
@@ -62,6 +62,10 @@ class HTTY::Request < HTTY::Payload
|
|
62
62
|
# * <tt>:fragment</tt>
|
63
63
|
def self.build_uri(components)
|
64
64
|
scheme = (components[:scheme] || 'http') + '://'
|
65
|
+
unless %w(http:// https://).include?(scheme)
|
66
|
+
raise ArgumentError, 'only http:// and https:// schemes are supported'
|
67
|
+
end
|
68
|
+
|
65
69
|
authority = build_authority(components)
|
66
70
|
path_query_and_fragment = build_path_query_and_fragment(components)
|
67
71
|
path_query_and_fragment ||= '/' if authority
|