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,62 @@
1
+ # Defines HTTY::CLI::Commands::CookiesAdd.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/cookies")
5
+ require File.expand_path("#{File.dirname __FILE__}/cookies_remove")
6
+ require File.expand_path("#{File.dirname __FILE__}/cookies_remove_all")
7
+ require File.expand_path("#{File.dirname __FILE__}/cookies_use")
8
+
9
+ module HTTY; end
10
+
11
+ class HTTY::CLI; end
12
+
13
+ module HTTY::CLI::Commands; end
14
+
15
+ # Encapsulates the _cookies-add_ command.
16
+ class HTTY::CLI::Commands::CookiesAdd < HTTY::CLI::Command
17
+
18
+ # Returns the name of a category under which help for the _cookies-add_
19
+ # command should appear.
20
+ def self.category
21
+ 'Building Requests'
22
+ end
23
+
24
+ # Returns the arguments for the command-line usage of the _cookies-add_
25
+ # command.
26
+ def self.command_line_arguments
27
+ 'name [value]'
28
+ end
29
+
30
+ # Returns the help text for the _cookies-add_ command.
31
+ def self.help
32
+ 'Adds a cookie to the request'
33
+ end
34
+
35
+ # Returns the extended help text for the _cookies-add_ command.
36
+ def self.help_extended
37
+ 'Adds a cookie used for the request. Does not communicate with the ' +
38
+ "endpoint.\n" +
39
+ "\n" +
40
+ 'Cookies are not required to have unique names. You can add multiple ' +
41
+ 'cookies with the same name, and they will be removed in ' +
42
+ "last-in-first-out order.\n" +
43
+ "\n" +
44
+ 'Cookies are not required to have values, either.'
45
+ end
46
+
47
+ # Returns related command classes for the _cookies-add_ command.
48
+ def self.see_also_commands
49
+ [HTTY::CLI::Commands::Cookies,
50
+ HTTY::CLI::Commands::CookiesRemove,
51
+ HTTY::CLI::Commands::CookiesRemoveAll,
52
+ HTTY::CLI::Commands::CookiesUse]
53
+ end
54
+
55
+ # Performs the _cookies-add_ command.
56
+ def perform
57
+ add_request_if_has_response do |request|
58
+ request.cookie_add(*arguments)
59
+ end
60
+ end
61
+
62
+ end
@@ -0,0 +1,20 @@
1
+ # Defines HTTY::CLI::Commands::CookiesClear.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/cookies_remove_all")
5
+
6
+ module HTTY; end
7
+
8
+ class HTTY::CLI; end
9
+
10
+ module HTTY::CLI::Commands; end
11
+
12
+ # Encapsulates the _cookies-clear_ command.
13
+ class HTTY::CLI::Commands::CookiesClear < HTTY::CLI::Command
14
+
15
+ # Returns the command that the _cookies-clear_ command is an alias for.
16
+ def self.alias_for
17
+ HTTY::CLI::Commands::CookiesRemoveAll
18
+ end
19
+
20
+ end
@@ -0,0 +1,60 @@
1
+ # Defines HTTY::CLI::Commands::CookiesRemove.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/cookies")
5
+ require File.expand_path("#{File.dirname __FILE__}/cookies_add")
6
+ require File.expand_path("#{File.dirname __FILE__}/cookies_remove_all")
7
+ require File.expand_path("#{File.dirname __FILE__}/cookies_use")
8
+
9
+ module HTTY; end
10
+
11
+ class HTTY::CLI; end
12
+
13
+ module HTTY::CLI::Commands; end
14
+
15
+ # Encapsulates the _cookies-remove_ command.
16
+ class HTTY::CLI::Commands::CookiesRemove < HTTY::CLI::Command
17
+
18
+ # Returns the name of a category under which help for the _cookies-remove_
19
+ # command should appear.
20
+ def self.category
21
+ 'Building Requests'
22
+ end
23
+
24
+ # Returns the arguments for the command-line usage of the _cookies-remove_
25
+ # command.
26
+ def self.command_line_arguments
27
+ 'name'
28
+ end
29
+
30
+ # Returns the help text for the _cookies-remove_ command.
31
+ def self.help
32
+ 'Removes from the request the last cookie having a particular name'
33
+ end
34
+
35
+ # Returns the extended help text for the _cookies-remove_ command.
36
+ def self.help_extended
37
+ 'Removes a cookie used for the request. Does not communicate with the ' +
38
+ "endpoint.\n" +
39
+ "\n" +
40
+ 'Cookies are not required to have unique names. You can add multiple ' +
41
+ 'cookies with the same name, and they will be removed in ' +
42
+ 'last-in-first-out order.'
43
+ end
44
+
45
+ # Returns related command classes for the _cookies-remove_ command.
46
+ def self.see_also_commands
47
+ [HTTY::CLI::Commands::Cookies,
48
+ HTTY::CLI::Commands::CookiesAdd,
49
+ HTTY::CLI::Commands::CookiesRemoveAll,
50
+ HTTY::CLI::Commands::CookiesUse]
51
+ end
52
+
53
+ # Performs the _cookies-remove_ command.
54
+ def perform
55
+ add_request_if_has_response do |request|
56
+ request.cookie_remove(*arguments)
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,50 @@
1
+ # Defines HTTY::CLI::Commands::CookiesRemoveAll.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/cookies")
5
+ require File.expand_path("#{File.dirname __FILE__}/cookies_add")
6
+ require File.expand_path("#{File.dirname __FILE__}/cookies_remove")
7
+ require File.expand_path("#{File.dirname __FILE__}/cookies_use")
8
+
9
+ module HTTY; end
10
+
11
+ class HTTY::CLI; end
12
+
13
+ module HTTY::CLI::Commands; end
14
+
15
+ # Encapsulates the _cookies-remove-all_ command.
16
+ class HTTY::CLI::Commands::CookiesRemoveAll < HTTY::CLI::Command
17
+
18
+ # Returns the name of a category under which help for the _cookies-remove-all_
19
+ # command should appear.
20
+ def self.category
21
+ 'Building Requests'
22
+ end
23
+
24
+ # Returns the help text for the _cookies-remove-all_ command.
25
+ def self.help
26
+ 'Removes all cookies from the request'
27
+ end
28
+
29
+ # Returns the extended help text for the _cookies-remove-all_ command.
30
+ def self.help_extended
31
+ 'Removes all cookies used for the request. Does not communicate with the ' +
32
+ 'endpoint.'
33
+ end
34
+
35
+ # Returns related command classes for the _cookies-remove-all_ command.
36
+ def self.see_also_commands
37
+ [HTTY::CLI::Commands::Cookies,
38
+ HTTY::CLI::Commands::CookiesRemove,
39
+ HTTY::CLI::Commands::CookiesAdd,
40
+ HTTY::CLI::Commands::CookiesUse]
41
+ end
42
+
43
+ # Performs the _cookies-remove-all_ command.
44
+ def perform
45
+ add_request_if_has_response do |request|
46
+ request.cookies_remove_all(*arguments)
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,57 @@
1
+ # Defines HTTY::CLI::Commands::CookiesUse.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/cookies")
5
+ require File.expand_path("#{File.dirname __FILE__}/cookies_add")
6
+ require File.expand_path("#{File.dirname __FILE__}/cookies_remove")
7
+ require File.expand_path("#{File.dirname __FILE__}/cookies_remove_all")
8
+ require File.expand_path("#{File.dirname __FILE__}/headers_response")
9
+
10
+ module HTTY; end
11
+
12
+ class HTTY::CLI; end
13
+
14
+ module HTTY::CLI::Commands; end
15
+
16
+ # Encapsulates the _cookies-use_ command.
17
+ class HTTY::CLI::Commands::CookiesUse < HTTY::CLI::Command
18
+
19
+ # Returns the name of a category under which help for the _cookies-use_
20
+ # command should appear.
21
+ def self.category
22
+ 'Building Requests'
23
+ end
24
+
25
+ # Returns the help text for the _cookies-use_ command.
26
+ def self.help
27
+ 'Uses cookies offered in the response'
28
+ end
29
+
30
+ # Returns the extended help text for the _cookies-use_ command.
31
+ def self.help_extended
32
+ 'Sets the cookies of the request to the cookies offered in the response ' +
33
+ "(the 'Set-Cookie' header). Does not communicate with the endpoint."
34
+ end
35
+
36
+ # Returns related command classes for the _cookies-use_ command.
37
+ def self.see_also_commands
38
+ [HTTY::CLI::Commands::Cookies,
39
+ HTTY::CLI::Commands::CookiesAdd,
40
+ HTTY::CLI::Commands::CookiesRemove,
41
+ HTTY::CLI::Commands::CookiesRemoveAll,
42
+ HTTY::CLI::Commands::HeadersResponse]
43
+ end
44
+
45
+ # Performs the _cookies-use_ command.
46
+ def perform
47
+ unless arguments.empty?
48
+ raise ArgumentError,
49
+ "wrong number of arguments (#{arguments.length} for 0)"
50
+ end
51
+
52
+ add_request_if_has_response do |request|
53
+ request.cookies_use session.last_response
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,20 @@
1
+ # Defines HTTY::CLI::Commands::Delete.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/http_delete")
5
+
6
+ module HTTY; end
7
+
8
+ class HTTY::CLI; end
9
+
10
+ module HTTY::CLI::Commands; end
11
+
12
+ # Encapsulates the _delete_ command.
13
+ class HTTY::CLI::Commands::Delete < HTTY::CLI::Command
14
+
15
+ # Returns the command that the _delete_ command is an alias for.
16
+ def self.alias_for
17
+ HTTY::CLI::Commands::HttpDelete
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ # Defines HTTY::CLI::Commands::Exit.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/quit")
5
+
6
+ module HTTY; end
7
+
8
+ class HTTY::CLI; end
9
+
10
+ module HTTY::CLI::Commands; end
11
+
12
+ # Encapsulates the _exit_ command.
13
+ class HTTY::CLI::Commands::Exit < HTTY::CLI::Command
14
+
15
+ # Returns the command that the _exit_ command is an alias for.
16
+ def self.alias_for
17
+ HTTY::CLI::Commands::Quit
18
+ end
19
+
20
+ end
@@ -0,0 +1,56 @@
1
+ # Defines HTTY::CLI::Commands::Follow.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/../cookie_clearing_command")
5
+ require File.expand_path("#{File.dirname __FILE__}/address")
6
+ require File.expand_path("#{File.dirname __FILE__}/http_get")
7
+
8
+ module HTTY; end
9
+
10
+ class HTTY::CLI; end
11
+
12
+ module HTTY::CLI::Commands; end
13
+
14
+ # Encapsulates the _follow_ command.
15
+ class HTTY::CLI::Commands::Follow < HTTY::CLI::Command
16
+
17
+ include HTTY::CLI::CookieClearingCommand
18
+
19
+ # Returns the name of a category under which help for the _follow_ command
20
+ # should appear.
21
+ def self.category
22
+ 'Navigation'
23
+ end
24
+
25
+ # Returns the help text for the _follow_ command.
26
+ def self.help
27
+ "Changes the address of the request to the value of the response's " +
28
+ "'Location' header"
29
+ end
30
+
31
+ # Returns the extended help text for the _follow_ command.
32
+ def self.help_extended
33
+ "Changes the address of the request to the value of the response's " +
34
+ "'Location' header. Does not communicate with the endpoint."
35
+ end
36
+
37
+ # Returns related command classes for the _follow_ command.
38
+ def self.see_also_commands
39
+ [HTTY::CLI::Commands::Address, HTTY::CLI::Commands::HttpGet]
40
+ end
41
+
42
+ # Performs the _follow_ command.
43
+ def perform
44
+ unless arguments.empty?
45
+ raise ArgumentError,
46
+ "wrong number of arguments (#{arguments.length} for 0)"
47
+ end
48
+
49
+ add_request_if_has_response do |request|
50
+ notify_if_cookies_cleared request do
51
+ request.follow session.last_response
52
+ end
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,20 @@
1
+ # Defines HTTY::CLI::Commands::Form.
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_ command.
12
+ class HTTY::CLI::Commands::Form < HTTY::CLI::Command
13
+
14
+ # Returns the name of a category under which help for the _form_ command
15
+ # should appear.
16
+ def self.category
17
+ 'Building Requests'
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ # Defines HTTY::CLI::Commands::FormAdd.
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-add_ command.
12
+ class HTTY::CLI::Commands::FormAdd < HTTY::CLI::Command
13
+
14
+ # Returns the name of a category under which help for the _form-add_ command
15
+ # should appear.
16
+ def self.category
17
+ 'Building Requests'
18
+ end
19
+
20
+ end
@@ -0,0 +1,26 @@
1
+ # Defines HTTY::CLI::Commands::FormClear.
2
+
3
+ require File.expand_path("#{File.dirname __FILE__}/../command")
4
+ require File.expand_path("#{File.dirname __FILE__}/form_remove_all")
5
+
6
+ module HTTY; end
7
+
8
+ class HTTY::CLI; end
9
+
10
+ module HTTY::CLI::Commands; end
11
+
12
+ # Encapsulates the _form-clear_ command.
13
+ class HTTY::CLI::Commands::FormClear < HTTY::CLI::Command
14
+
15
+ # Returns the command that the _form-clear_ command is an alias for.
16
+ def self.alias_for
17
+ HTTY::CLI::Commands::FormRemoveAll
18
+ end
19
+
20
+ # Returns the name of a category under which help for the _form-clear_ command
21
+ # should appear.
22
+ def self.category
23
+ 'Building Requests'
24
+ end
25
+
26
+ end
@@ -0,0 +1,20 @@
1
+ # Defines HTTY::CLI::Commands::FormRemove.
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_ command.
12
+ class HTTY::CLI::Commands::FormRemove < HTTY::CLI::Command
13
+
14
+ # Returns the name of a category under which help for the _form-remove_
15
+ # command should appear.
16
+ def self.category
17
+ 'Building Requests'
18
+ end
19
+
20
+ end