htty 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/MIT-LICENSE.rdoc +9 -0
  2. data/README.rdoc +199 -0
  3. data/VERSION +1 -0
  4. data/app/htty.rb +14 -0
  5. data/app/htty/cli.rb +77 -0
  6. data/app/htty/cli/command.rb +185 -0
  7. data/app/htty/cli/commands.rb +43 -0
  8. data/app/htty/cli/commands/address.rb +84 -0
  9. data/app/htty/cli/commands/body_clear.rb +20 -0
  10. data/app/htty/cli/commands/body_request.rb +51 -0
  11. data/app/htty/cli/commands/body_response.rb +59 -0
  12. data/app/htty/cli/commands/body_set.rb +58 -0
  13. data/app/htty/cli/commands/body_unset.rb +45 -0
  14. data/app/htty/cli/commands/cd.rb +20 -0
  15. data/app/htty/cli/commands/cookie_add.rb +20 -0
  16. data/app/htty/cli/commands/cookie_remove.rb +20 -0
  17. data/app/htty/cli/commands/cookies.rb +68 -0
  18. data/app/htty/cli/commands/cookies_add.rb +62 -0
  19. data/app/htty/cli/commands/cookies_clear.rb +20 -0
  20. data/app/htty/cli/commands/cookies_remove.rb +60 -0
  21. data/app/htty/cli/commands/cookies_remove_all.rb +50 -0
  22. data/app/htty/cli/commands/cookies_use.rb +57 -0
  23. data/app/htty/cli/commands/delete.rb +20 -0
  24. data/app/htty/cli/commands/exit.rb +20 -0
  25. data/app/htty/cli/commands/follow.rb +56 -0
  26. data/app/htty/cli/commands/form.rb +20 -0
  27. data/app/htty/cli/commands/form_add.rb +20 -0
  28. data/app/htty/cli/commands/form_clear.rb +26 -0
  29. data/app/htty/cli/commands/form_remove.rb +20 -0
  30. data/app/htty/cli/commands/form_remove_all.rb +20 -0
  31. data/app/htty/cli/commands/fragment_clear.rb +20 -0
  32. data/app/htty/cli/commands/fragment_set.rb +59 -0
  33. data/app/htty/cli/commands/fragment_unset.rb +48 -0
  34. data/app/htty/cli/commands/get.rb +20 -0
  35. data/app/htty/cli/commands/header_set.rb +20 -0
  36. data/app/htty/cli/commands/header_unset.rb +20 -0
  37. data/app/htty/cli/commands/headers_clear.rb +20 -0
  38. data/app/htty/cli/commands/headers_request.rb +70 -0
  39. data/app/htty/cli/commands/headers_response.rb +65 -0
  40. data/app/htty/cli/commands/headers_set.rb +57 -0
  41. data/app/htty/cli/commands/headers_unset.rb +54 -0
  42. data/app/htty/cli/commands/headers_unset_all.rb +48 -0
  43. data/app/htty/cli/commands/help.rb +100 -0
  44. data/app/htty/cli/commands/history.rb +60 -0
  45. data/app/htty/cli/commands/history_verbose.rb +81 -0
  46. data/app/htty/cli/commands/host_set.rb +59 -0
  47. data/app/htty/cli/commands/http_delete.rb +40 -0
  48. data/app/htty/cli/commands/http_get.rb +42 -0
  49. data/app/htty/cli/commands/http_head.rb +36 -0
  50. data/app/htty/cli/commands/http_options.rb +36 -0
  51. data/app/htty/cli/commands/http_post.rb +34 -0
  52. data/app/htty/cli/commands/http_put.rb +29 -0
  53. data/app/htty/cli/commands/http_trace.rb +36 -0
  54. data/app/htty/cli/commands/path_set.rb +54 -0
  55. data/app/htty/cli/commands/port_set.rb +55 -0
  56. data/app/htty/cli/commands/post.rb +20 -0
  57. data/app/htty/cli/commands/put.rb +20 -0
  58. data/app/htty/cli/commands/query_clear.rb +20 -0
  59. data/app/htty/cli/commands/query_set.rb +59 -0
  60. data/app/htty/cli/commands/query_unset.rb +56 -0
  61. data/app/htty/cli/commands/query_unset_all.rb +50 -0
  62. data/app/htty/cli/commands/quit.rb +24 -0
  63. data/app/htty/cli/commands/reuse.rb +74 -0
  64. data/app/htty/cli/commands/scheme_set.rb +69 -0
  65. data/app/htty/cli/commands/status.rb +52 -0
  66. data/app/htty/cli/commands/undo.rb +13 -0
  67. data/app/htty/cli/commands/userinfo_clear.rb +20 -0
  68. data/app/htty/cli/commands/userinfo_set.rb +56 -0
  69. data/app/htty/cli/commands/userinfo_unset.rb +47 -0
  70. data/app/htty/cli/cookie_clearing_command.rb +26 -0
  71. data/app/htty/cli/display.rb +182 -0
  72. data/app/htty/cli/http_method_command.rb +75 -0
  73. data/app/htty/cli/url_escaping.rb +27 -0
  74. data/app/htty/cookies_util.rb +36 -0
  75. data/app/htty/no_location_header_error.rb +12 -0
  76. data/app/htty/no_response_error.rb +12 -0
  77. data/app/htty/no_set_cookie_header_error.rb +13 -0
  78. data/app/htty/ordered_hash.rb +69 -0
  79. data/app/htty/payload.rb +48 -0
  80. data/app/htty/request.rb +471 -0
  81. data/app/htty/requests_util.rb +92 -0
  82. data/app/htty/response.rb +34 -0
  83. data/app/htty/session.rb +29 -0
  84. data/bin/htty +5 -0
  85. data/spec/unit/htty/cli_spec.rb +27 -0
  86. data/spec/unit/htty/ordered_hash_spec.rb +54 -0
  87. data/spec/unit/htty/request_spec.rb +1236 -0
  88. data/spec/unit/htty/response_spec.rb +0 -0
  89. data/spec/unit/htty/session_spec.rb +13 -0
  90. metadata +158 -0
@@ -0,0 +1,20 @@
1
+ # Defines HTTY::CLI::Commands::FormRemoveAll.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+
5
+ module HTTY; end
6
+
7
+ class HTTY::CLI; end
8
+
9
+ module HTTY::CLI::Commands; end
10
+
11
+ # Encapsulates the _form-remove-all_ command.
12
+ class HTTY::CLI::Commands::FormRemoveAll < HTTY::CLI::Command
13
+
14
+ # Returns the name of a category under which help for the _form-remove-all_
15
+ # command should appear.
16
+ def self.category
17
+ 'Building Requests'
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ # Defines HTTY::CLI::Commands::FragmentClear.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/fragment_unset")
5
+
6
+ module HTTY; end
7
+
8
+ class HTTY::CLI; end
9
+
10
+ module HTTY::CLI::Commands; end
11
+
12
+ # Encapsulates the _fragment-clear_ command.
13
+ class HTTY::CLI::Commands::FragmentClear < HTTY::CLI::Command
14
+
15
+ # Returns the command that the _fragment-clear_ command is an alias for.
16
+ def self.alias_for
17
+ HTTY::CLI::Commands::FragmentUnset
18
+ end
19
+
20
+ end
@@ -0,0 +1,59 @@
1
+ # Defines HTTY::CLI::Commands::FragmentSet.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/../url_escaping")
5
+ require File.expand_path("#{File.dirname __FILE__}/address")
6
+ require File.expand_path("#{File.dirname __FILE__}/fragment_unset")
7
+
8
+ module HTTY; end
9
+
10
+ class HTTY::CLI; end
11
+
12
+ module HTTY::CLI::Commands; end
13
+
14
+ # Encapsulates the _fragment-set_ command.
15
+ class HTTY::CLI::Commands::FragmentSet < HTTY::CLI::Command
16
+
17
+ include HTTY::CLI::UrlEscaping
18
+
19
+ # Returns the name of a category under which help for the _fragment-set_
20
+ # command should appear.
21
+ def self.category
22
+ 'Navigation'
23
+ end
24
+
25
+ # Returns the arguments for the command-line usage of the _fragment-set_ command.
26
+ def self.command_line_arguments
27
+ 'fragment'
28
+ end
29
+
30
+ # Returns the help text for the _fragment-set_ command.
31
+ def self.help
32
+ "Sets the fragment of the request's address"
33
+ end
34
+
35
+ # Returns the extended help text for the _fragment-set_ command.
36
+ def self.help_extended
37
+ 'Sets the page fragment used for the request. Does not communicate with ' +
38
+ "the endpoint.\n" +
39
+ "\n" +
40
+ 'The console prompt shows the address for the current request.'
41
+ end
42
+
43
+ # Returns related command classes for the _fragment-set_ command.
44
+ def self.see_also_commands
45
+ [HTTY::CLI::Commands::FragmentUnset,
46
+ HTTY::CLI::Commands::Address]
47
+ end
48
+
49
+ # Performs the _fragment-set_ command.
50
+ def perform
51
+ add_request_if_has_response do |request|
52
+ clean_arguments = arguments.collect do |a|
53
+ a.gsub(/^#/, '')
54
+ end
55
+ request.fragment_set(*escape_or_warn_of_escape_sequences(clean_arguments))
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,48 @@
1
+ # Defines HTTY::CLI::Commands::FragmentUnset.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/address")
5
+ require File.expand_path("#{File.dirname __FILE__}/fragment_set")
6
+
7
+ module HTTY; end
8
+
9
+ class HTTY::CLI; end
10
+
11
+ module HTTY::CLI::Commands; end
12
+
13
+ # Encapsulates the _fragment-unset_ command.
14
+ class HTTY::CLI::Commands::FragmentUnset < HTTY::CLI::Command
15
+
16
+ # Returns the name of a category under which help for the _fragment-unset_
17
+ # command should appear.
18
+ def self.category
19
+ 'Navigation'
20
+ end
21
+
22
+ # Returns the help text for the _fragment-unset_ command.
23
+ def self.help
24
+ "Removes the fragment from the request's address"
25
+ end
26
+
27
+ # Returns the extended help text for the _fragment-unset_ command.
28
+ def self.help_extended
29
+ 'Removes the page fragment used for the request. Does not communicate ' +
30
+ "with the endpoint.\n" +
31
+ "\n" +
32
+ 'The console prompt shows the address for the current request.'
33
+ end
34
+
35
+ # Returns related command classes for the _fragment-unset_ command.
36
+ def self.see_also_commands
37
+ [HTTY::CLI::Commands::FragmentSet,
38
+ HTTY::CLI::Commands::Address]
39
+ end
40
+
41
+ # Performs the _fragment-unset_ command.
42
+ def perform
43
+ add_request_if_has_response do |request|
44
+ request.fragment_unset(*arguments)
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,20 @@
1
+ # Defines HTTY::CLI::Commands::Get.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/http_get")
5
+
6
+ module HTTY; end
7
+
8
+ class HTTY::CLI; end
9
+
10
+ module HTTY::CLI::Commands; end
11
+
12
+ # Encapsulates the _get_ command.
13
+ class HTTY::CLI::Commands::Get < HTTY::CLI::Command
14
+
15
+ # Returns the command that the _get_ command is an alias for.
16
+ def self.alias_for
17
+ HTTY::CLI::Commands::HttpGet
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ # Defines HTTY::CLI::Commands::HeaderSet.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/headers_set")
5
+
6
+ module HTTY; end
7
+
8
+ class HTTY::CLI; end
9
+
10
+ module HTTY::CLI::Commands; end
11
+
12
+ # Encapsulates the _header-set_ command.
13
+ class HTTY::CLI::Commands::HeaderSet < HTTY::CLI::Command
14
+
15
+ # Returns the command that the _header-set_ command is an alias for.
16
+ def self.alias_for
17
+ HTTY::CLI::Commands::HeadersSet
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ # Defines HTTY::CLI::Commands::HeaderUnset.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/headers_unset")
5
+
6
+ module HTTY; end
7
+
8
+ class HTTY::CLI; end
9
+
10
+ module HTTY::CLI::Commands; end
11
+
12
+ # Encapsulates the _header-unset_ command.
13
+ class HTTY::CLI::Commands::HeaderUnset < HTTY::CLI::Command
14
+
15
+ # Returns the command that the _header-unset_ command is an alias for.
16
+ def self.alias_for
17
+ HTTY::CLI::Commands::HeadersUnset
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ # Defines HTTY::CLI::Commands::HeadersClear.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/headers_unset_all")
5
+
6
+ module HTTY; end
7
+
8
+ class HTTY::CLI; end
9
+
10
+ module HTTY::CLI::Commands; end
11
+
12
+ # Encapsulates the _headers-clear_ command.
13
+ class HTTY::CLI::Commands::HeadersClear < HTTY::CLI::Command
14
+
15
+ # Returns the command that the _headers-clear_ command is an alias for.
16
+ def self.alias_for
17
+ HTTY::CLI::Commands::HeadersUnsetAll
18
+ end
19
+
20
+ end
@@ -0,0 +1,70 @@
1
+ # Defines HTTY::CLI::Commands::HeadersRequest.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../../request")
4
+ require File.expand_path("#{File.dirname __FILE__}/../command")
5
+ require File.expand_path("#{File.dirname __FILE__}/../display")
6
+ require File.expand_path("#{File.dirname __FILE__}/body_request")
7
+ require File.expand_path("#{File.dirname __FILE__}/cookies")
8
+ require File.expand_path("#{File.dirname __FILE__}/headers_response")
9
+ require File.expand_path("#{File.dirname __FILE__}/headers_set")
10
+ require File.expand_path("#{File.dirname __FILE__}/headers_unset")
11
+ require File.expand_path("#{File.dirname __FILE__}/headers_unset_all")
12
+
13
+ module HTTY; end
14
+
15
+ class HTTY::CLI; end
16
+
17
+ module HTTY::CLI::Commands; end
18
+
19
+ # Encapsulates the _headers-request_ command.
20
+ class HTTY::CLI::Commands::HeadersRequest < HTTY::CLI::Command
21
+
22
+ include HTTY::CLI::Display
23
+
24
+ # Returns the name of a category under which help for the _headers-request_
25
+ # command should appear.
26
+ def self.category
27
+ 'Building Requests'
28
+ end
29
+
30
+ # Returns the help text for the _headers-request_ command.
31
+ def self.help
32
+ 'Displays the headers of the request'
33
+ end
34
+
35
+ # Returns the extended help text for the _headers-request_ command.
36
+ def self.help_extended
37
+ 'Displays the headers used for the request. Does not communicate with ' +
38
+ "the endpoint.\n" +
39
+ "\n" +
40
+ 'Headers must have unique names. When you set a header that already ' +
41
+ 'exists, its value will be changed.'
42
+ end
43
+
44
+ # Returns related command classes for the _headers-request_ command.
45
+ def self.see_also_commands
46
+ [HTTY::CLI::Commands::HeadersSet,
47
+ HTTY::CLI::Commands::HeadersUnset,
48
+ HTTY::CLI::Commands::HeadersUnsetAll,
49
+ HTTY::CLI::Commands::BodyRequest,
50
+ HTTY::CLI::Commands::Cookies,
51
+ HTTY::CLI::Commands::HeadersResponse]
52
+ end
53
+
54
+ # Performs the _headers-request_ command.
55
+ def perform
56
+ request = session.requests.last
57
+ headers = if request.request_method.nil?
58
+ if request.body.to_s.length.zero?
59
+ request.headers false
60
+ else
61
+ request.headers true
62
+ end
63
+ else
64
+ request.headers
65
+ end
66
+ show_headers headers, HTTY::Request::COOKIES_HEADER_NAME
67
+ self
68
+ end
69
+
70
+ end
@@ -0,0 +1,65 @@
1
+ # Defines HTTY::CLI::Commands::HeadersResponse.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../../response")
4
+ require File.expand_path("#{File.dirname __FILE__}/../../no_response_error")
5
+ require File.expand_path("#{File.dirname __FILE__}/../command")
6
+ require File.expand_path("#{File.dirname __FILE__}/../display")
7
+ require File.expand_path("#{File.dirname __FILE__}/body_response")
8
+ require File.expand_path("#{File.dirname __FILE__}/cookies")
9
+ require File.expand_path("#{File.dirname __FILE__}/cookies_use")
10
+ require File.expand_path("#{File.dirname __FILE__}/headers_request")
11
+ require File.expand_path("#{File.dirname __FILE__}/status")
12
+
13
+ module HTTY; end
14
+
15
+ class HTTY::CLI; end
16
+
17
+ module HTTY::CLI::Commands; end
18
+
19
+ # Encapsulates the _headers-response_ command.
20
+ class HTTY::CLI::Commands::HeadersResponse < HTTY::CLI::Command
21
+
22
+ include HTTY::CLI::Display
23
+
24
+ # Returns the name of a category under which help for the _headers-response_
25
+ # command should appear.
26
+ def self.category
27
+ 'Inspecting Responses'
28
+ end
29
+
30
+ # Returns the string used to invoke the _headers-response_ command from the
31
+ # command line.
32
+ def self.command_line
33
+ 'headers[-response]'
34
+ end
35
+
36
+ # Returns the help text for the _headers-response_ command.
37
+ def self.help
38
+ 'Displays the headers of the response'
39
+ end
40
+
41
+ # Returns the extended help text for the _headers-response_ command.
42
+ def self.help_extended
43
+ 'Displays the headers received in the response. Does not communicate ' +
44
+ 'with the endpoint.'
45
+ end
46
+
47
+ # Returns related command classes for the _headers-response_ command.
48
+ def self.see_also_commands
49
+ [HTTY::CLI::Commands::BodyResponse,
50
+ HTTY::CLI::Commands::Cookies,
51
+ HTTY::CLI::Commands::CookiesUse,
52
+ HTTY::CLI::Commands::Status,
53
+ HTTY::CLI::Commands::HeadersRequest]
54
+ end
55
+
56
+ # Performs the _headers-response_ command.
57
+ def perform
58
+ unless (response = session.last_response)
59
+ raise HTTY::NoResponseError
60
+ end
61
+ show_headers response.headers, HTTY::Response::COOKIES_HEADER_NAME
62
+ self
63
+ end
64
+
65
+ end
@@ -0,0 +1,57 @@
1
+ # Defines HTTY::CLI::Commands::HeadersSet.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/headers_request")
5
+ require File.expand_path("#{File.dirname __FILE__}/headers_unset")
6
+ require File.expand_path("#{File.dirname __FILE__}/headers_unset_all")
7
+
8
+ module HTTY; end
9
+
10
+ class HTTY::CLI; end
11
+
12
+ module HTTY::CLI::Commands; end
13
+
14
+ # Encapsulates the _headers-set_ command.
15
+ class HTTY::CLI::Commands::HeadersSet < HTTY::CLI::Command
16
+
17
+ # Returns the name of a category under which help for the _headers-set_
18
+ # command should appear.
19
+ def self.category
20
+ 'Building Requests'
21
+ end
22
+
23
+ # Returns the arguments for the command-line usage of the _headers-set_
24
+ # command.
25
+ def self.command_line_arguments
26
+ 'name value'
27
+ end
28
+
29
+ # Returns the help text for the _headers-set_ command.
30
+ def self.help
31
+ 'Sets a header of the request'
32
+ end
33
+
34
+ # Returns the extended help text for the _headers-set_ command.
35
+ def self.help_extended
36
+ 'Sets a header used for the request. Does not communicate with the ' +
37
+ "endpoint.\n" +
38
+ "\n" +
39
+ 'Headers must have unique names. When you set a header that already ' +
40
+ 'exists, its value will be changed.'
41
+ end
42
+
43
+ # Returns related command classes for the _headers-set_ command.
44
+ def self.see_also_commands
45
+ [HTTY::CLI::Commands::HeadersRequest,
46
+ HTTY::CLI::Commands::HeadersUnset,
47
+ HTTY::CLI::Commands::HeadersUnsetAll]
48
+ end
49
+
50
+ # Performs the _headers-set_ command.
51
+ def perform
52
+ add_request_if_has_response do |request|
53
+ request.header_set(*arguments)
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,54 @@
1
+ # Defines HTTY::CLI::Commands::HeadersUnset.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/headers_request")
5
+ require File.expand_path("#{File.dirname __FILE__}/headers_set")
6
+ require File.expand_path("#{File.dirname __FILE__}/headers_unset_all")
7
+
8
+ module HTTY; end
9
+
10
+ class HTTY::CLI; end
11
+
12
+ module HTTY::CLI::Commands; end
13
+
14
+ # Encapsulates the _headers-unset_ command.
15
+ class HTTY::CLI::Commands::HeadersUnset < HTTY::CLI::Command
16
+
17
+ # Returns the name of a category under which help for the _headers-unset_
18
+ # command should appear.
19
+ def self.category
20
+ 'Building Requests'
21
+ end
22
+
23
+ # Returns the arguments for the command-line usage of the _headers-unset_
24
+ # command.
25
+ def self.command_line_arguments
26
+ 'name'
27
+ end
28
+
29
+ # Returns the help text for the _headers-unset_ command.
30
+ def self.help
31
+ 'Removes a header of the request'
32
+ end
33
+
34
+ # Returns the extended help text for the _headers-unset_ command.
35
+ def self.help_extended
36
+ 'Removes a header used for the request. Does not communicate with the ' +
37
+ 'endpoint.'
38
+ end
39
+
40
+ # Returns related command classes for the _headers-unset_ command.
41
+ def self.see_also_commands
42
+ [HTTY::CLI::Commands::HeadersRequest,
43
+ HTTY::CLI::Commands::HeadersSet,
44
+ HTTY::CLI::Commands::HeadersUnsetAll]
45
+ end
46
+
47
+ # Performs the _headers-unset_ command.
48
+ def perform
49
+ add_request_if_has_response do |request|
50
+ request.header_unset(*arguments)
51
+ end
52
+ end
53
+
54
+ end