htty 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.markdown +21 -0
- data/MIT-LICENSE.markdown +10 -0
- data/README.markdown +238 -0
- data/VERSION +1 -1
- data/bin/htty +1 -1
- data/{app → lib}/htty.rb +0 -2
- data/{app → lib}/htty/cli.rb +11 -4
- data/{app → lib}/htty/cli/command.rb +25 -3
- data/{app → lib}/htty/cli/commands.rb +0 -2
- data/{app → lib}/htty/cli/commands/address.rb +15 -9
- data/{app → lib}/htty/cli/commands/body_clear.rb +0 -2
- data/{app → lib}/htty/cli/commands/body_request.rb +1 -3
- data/{app → lib}/htty/cli/commands/body_response.rb +1 -3
- data/{app → lib}/htty/cli/commands/body_set.rb +9 -4
- data/{app → lib}/htty/cli/commands/body_unset.rb +1 -3
- data/{app → lib}/htty/cli/commands/cd.rb +0 -2
- data/{app → lib}/htty/cli/commands/cookie_add.rb +0 -2
- data/{app → lib}/htty/cli/commands/cookie_remove.rb +0 -2
- data/{app → lib}/htty/cli/commands/cookies.rb +9 -5
- data/{app → lib}/htty/cli/commands/cookies_add.rb +1 -3
- data/{app → lib}/htty/cli/commands/cookies_clear.rb +0 -2
- data/{app → lib}/htty/cli/commands/cookies_remove.rb +1 -3
- data/{app → lib}/htty/cli/commands/cookies_remove_all.rb +1 -3
- data/{app → lib}/htty/cli/commands/cookies_use.rb +11 -4
- data/{app → lib}/htty/cli/commands/delete.rb +0 -2
- data/{app → lib}/htty/cli/commands/exit.rb +0 -2
- data/{app → lib}/htty/cli/commands/follow.rb +6 -9
- data/{app → lib}/htty/cli/commands/form.rb +0 -2
- data/{app → lib}/htty/cli/commands/form_add.rb +0 -2
- data/{app → lib}/htty/cli/commands/form_clear.rb +0 -2
- data/{app → lib}/htty/cli/commands/form_remove.rb +0 -2
- data/{app → lib}/htty/cli/commands/form_remove_all.rb +0 -2
- data/{app → lib}/htty/cli/commands/fragment_clear.rb +0 -2
- data/{app → lib}/htty/cli/commands/fragment_set.rb +6 -4
- data/{app → lib}/htty/cli/commands/fragment_unset.rb +4 -4
- data/{app → lib}/htty/cli/commands/get.rb +0 -2
- data/{app → lib}/htty/cli/commands/header_set.rb +0 -2
- data/{app → lib}/htty/cli/commands/header_unset.rb +0 -2
- data/{app → lib}/htty/cli/commands/headers_clear.rb +0 -2
- data/{app → lib}/htty/cli/commands/headers_request.rb +13 -8
- data/{app → lib}/htty/cli/commands/headers_response.rb +6 -4
- data/{app → lib}/htty/cli/commands/headers_set.rb +1 -3
- data/{app → lib}/htty/cli/commands/headers_unset.rb +1 -4
- data/{app → lib}/htty/cli/commands/headers_unset_all.rb +1 -3
- data/{app → lib}/htty/cli/commands/help.rb +8 -4
- data/{app → lib}/htty/cli/commands/history.rb +5 -7
- data/{app → lib}/htty/cli/commands/history_verbose.rb +6 -5
- data/{app → lib}/htty/cli/commands/host_set.rb +2 -7
- data/{app → lib}/htty/cli/commands/http_delete.rb +0 -2
- data/{app → lib}/htty/cli/commands/http_get.rb +0 -2
- data/{app → lib}/htty/cli/commands/http_head.rb +0 -2
- data/{app → lib}/htty/cli/commands/http_options.rb +0 -2
- data/{app → lib}/htty/cli/commands/http_post.rb +0 -2
- data/{app → lib}/htty/cli/commands/http_put.rb +0 -2
- data/{app → lib}/htty/cli/commands/http_trace.rb +0 -2
- data/{app → lib}/htty/cli/commands/path_set.rb +6 -4
- data/{app → lib}/htty/cli/commands/port_set.rb +4 -4
- data/{app → lib}/htty/cli/commands/post.rb +0 -2
- data/{app → lib}/htty/cli/commands/put.rb +0 -2
- data/{app → lib}/htty/cli/commands/query_clear.rb +0 -2
- data/{app → lib}/htty/cli/commands/query_set.rb +10 -7
- data/{app → lib}/htty/cli/commands/query_unset.rb +12 -6
- data/{app → lib}/htty/cli/commands/query_unset_all.rb +4 -4
- data/{app → lib}/htty/cli/commands/quit.rb +0 -2
- data/{app → lib}/htty/cli/commands/reuse.rb +4 -3
- data/{app → lib}/htty/cli/commands/scheme_set.rb +4 -4
- data/{app → lib}/htty/cli/commands/status.rb +8 -5
- data/{app → lib}/htty/cli/commands/undo.rb +0 -2
- data/{app → lib}/htty/cli/commands/userinfo_clear.rb +0 -2
- data/{app → lib}/htty/cli/commands/userinfo_set.rb +30 -8
- data/{app → lib}/htty/cli/commands/userinfo_unset.rb +4 -4
- data/{app → lib}/htty/cli/display.rb +40 -19
- data/{app → lib}/htty/cli/http_method_command.rb +4 -8
- data/{app → lib}/htty/cli/url_escaping.rb +0 -2
- data/{app → lib}/htty/cookies_util.rb +0 -2
- data/{app → lib}/htty/no_location_header_error.rb +3 -2
- data/{app → lib}/htty/no_response_error.rb +0 -2
- data/{app → lib}/htty/no_set_cookie_header_error.rb +3 -2
- data/{app → lib}/htty/ordered_hash.rb +2 -3
- data/{app → lib}/htty/payload.rb +2 -3
- data/{app → lib}/htty/request.rb +25 -15
- data/{app → lib}/htty/requests_util.rb +2 -3
- data/{app → lib}/htty/response.rb +2 -3
- data/{app → lib}/htty/session.rb +0 -2
- data/spec/unit/htty/cli_spec.rb +9 -14
- data/spec/unit/htty/ordered_hash_spec.rb +13 -17
- data/spec/unit/htty/request_spec.rb +281 -127
- data/spec/unit/htty/session_spec.rb +4 -7
- metadata +152 -99
- data/MIT-LICENSE.rdoc +0 -9
- data/README.rdoc +0 -199
- data/app/htty/cli/cookie_clearing_command.rb +0 -26
data/History.markdown
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Version history for the _htty_ project
|
2
|
+
======================================
|
3
|
+
|
4
|
+
v1.1.0, Tue 9/28/2010
|
5
|
+
---------------------
|
6
|
+
|
7
|
+
* Added HTTP Secure support
|
8
|
+
* Added HTTP Basic Authentication support
|
9
|
+
* Added support for arrow keys and Emacs key bindings [[rbxbx](http://github.com/rbxbx "rbxbx at GitHub")]
|
10
|
+
* Added support for Ctrl-D for terminating input [[bofrede](http://github.com/bofrede "bofrede at GitHub")]
|
11
|
+
* Enhanced the _userinfo-set_ command to:
|
12
|
+
- Permit separate entry of username and (optional) password
|
13
|
+
- Permit colon-separated “username:password” entry
|
14
|
+
- Automatically URL-escape _@_ symbols to avoid invalid URLs
|
15
|
+
* Fixed various bugs
|
16
|
+
* Corrected and expanded built-in help content
|
17
|
+
|
18
|
+
v1.0.0, Mon 9/06/2010
|
19
|
+
---------------------
|
20
|
+
|
21
|
+
(First release)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
The MIT License
|
2
|
+
===============
|
3
|
+
|
4
|
+
Source code for _htty_ is Copyright © 2010 [Nils Jonsson](mailto:htty@nilsjonsson.com).
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
9
|
+
|
10
|
+
THE SOFTWARE IS PROVIDED “AS IS,” WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
|
2
|
+
s s
|
3
|
+
.uef^" :8 :8 ..
|
4
|
+
:d88E .88 .88 @L
|
5
|
+
`888E :888ooo :888ooo 9888i .dL
|
6
|
+
888E .z8k -*8888888 -*8888888 `Y888k:*888.
|
7
|
+
888E~?888L 8888 8888 888E 888I
|
8
|
+
888E 888E 8888 8888 888E 888I
|
9
|
+
888E 888E 8888 8888 888E 888I
|
10
|
+
888E 888E .8888Lu= .8888Lu= 888E 888I
|
11
|
+
888E 888E ^%888* ^%888* x888N><888'
|
12
|
+
m888N= 888> 'Y" 'Y" "88" 888
|
13
|
+
`Y" 888 __ .__ 88F
|
14
|
+
J88" _/ |_| |__ ____ 98"
|
15
|
+
@% \ __\ | \_/ __ \ ./"
|
16
|
+
:" | | | Y \ ___/ ~`
|
17
|
+
|__| |___| /\___ >
|
18
|
+
__________\/_____\/____________________
|
19
|
+
/ | \__ ___/\__ ___/\______ \
|
20
|
+
/ ~ \| | | | | ___/
|
21
|
+
\ Y /| | | | | |
|
22
|
+
\___|_ / |____| |____| |____|
|
23
|
+
______\/___________________.___.
|
24
|
+
\__ ___/\__ ___/\__ | |
|
25
|
+
| | | | / | |
|
26
|
+
| | | | \____ |
|
27
|
+
|____| |____| / ______|
|
28
|
+
\/
|
29
|
+
|
30
|
+
[htty](http://htty.github.com) is a console application for interacting with HTTP servers. It’s something of a cross between _curl_ and the Lynx browser.
|
31
|
+
|
32
|
+
See what’s changed lately by reading the [project history](file.History.html).
|
33
|
+
|
34
|
+
Installation
|
35
|
+
============
|
36
|
+
|
37
|
+
It couldn’t be much easier.
|
38
|
+
|
39
|
+
$ gem install htty
|
40
|
+
|
41
|
+
You’ll need Ruby and RubyGems. It’s known to work well under OS X against Ruby v1.8.7 and v1.9.2.
|
42
|
+
|
43
|
+
Features
|
44
|
+
========
|
45
|
+
|
46
|
+
* Intuitive commands and command aliases
|
47
|
+
* Support for familiar HTTP methods _GET_, _POST_, _PUT_, and _DELETE_, as well as _HEAD_, _OPTIONS_ and _TRACE_
|
48
|
+
* Support for HTTP Secure connections and HTTP Basic Authentication
|
49
|
+
* Automatic URL-encoding of userinfo, paths, query-string parameters, and page fragments
|
50
|
+
* Transcripts, both verbose and summary
|
51
|
+
* Scripting via _stdin_
|
52
|
+
* Dead-simple cookie handling and redirect following
|
53
|
+
* Built-in help
|
54
|
+
|
55
|
+
The things you can do with _htty_ are:
|
56
|
+
|
57
|
+
* **Build a request** — you can tweak the address, headers, cookies, and body at will
|
58
|
+
* **Send the request to the server** — after the request is sent, it remains unchanged in your session history
|
59
|
+
* **Inspect the server’s response** — you can look at the status, headers, cookies, and body in various ways
|
60
|
+
* **Review history** — a normal and a verbose transcript of your session are available at all times (destroyed when you quit _htty_)
|
61
|
+
* **Reuse previous requests** — you can refer to prior requests and copy them
|
62
|
+
|
63
|
+
Examples
|
64
|
+
========
|
65
|
+
|
66
|
+
Here are a few annotated _htty_ session transcripts to get you started.
|
67
|
+
|
68
|
+
Querying a web service
|
69
|
+
----------------------
|
70
|
+
|
71
|
+
This simple example shows how to explore a read-only web service with _htty_.
|
72
|
+
|
73
|
+
![ESV Bible Web Service example #1](http://htty.github.com/images/esvapi1.png)
|
74
|
+
|
75
|
+
You can point _htty_ at a complete or partial web URL. If you don’t supply a URL, http://0.0.0.0/ (port 80) will be used. You can vary the protocol scheme, userinfo, host, port, path, query string, and fragment as you wish.
|
76
|
+
|
77
|
+
The _htty_ shell prompt shows the address of the current request.
|
78
|
+
|
79
|
+
The `get` command is one of seven HTTP request methods supported. A concise summary of the response is shown when you issue a request.
|
80
|
+
|
81
|
+
You can follow redirects using the `follow` command. No request is made until you type a request command such as `get` or `post`.
|
82
|
+
|
83
|
+
![ESV Bible Web Service example #2](http://htty.github.com/images/esvapi2.png)
|
84
|
+
|
85
|
+
You can tweak segments of the address at will. Here we are navigating the site’s path hierarchy, which you can do with relative as well as absolute pathspecs.
|
86
|
+
|
87
|
+
![ESV Bible Web Service example #3](http://htty.github.com/images/esvapi3.png)
|
88
|
+
|
89
|
+
Here we add query-string parameters. Notice that characters that require URL encoding are automatically URL-encoded (unless they are part of a URL-encoded expression).
|
90
|
+
|
91
|
+
The `headers-response` and `body-response` commands reveal the details of a response.
|
92
|
+
|
93
|
+
![ESV Bible Web Service example #4](http://htty.github.com/images/esvapi4.png)
|
94
|
+
|
95
|
+
There was some cruft in the web service’s response (a horizontal line, a passage reference, verse numbers, a copyright stamp, and line breaks). We eliminate it by using API options provided by the web service we’re talking to.
|
96
|
+
|
97
|
+
We do a Julia Child maneuver and use the `address` command to change the entire URL, rather than add individual query-string parameters one by one.
|
98
|
+
|
99
|
+
Exit your session at any time by typing `quit`.
|
100
|
+
|
101
|
+
Working with cookies
|
102
|
+
--------------------
|
103
|
+
|
104
|
+
The next example demonstrates _htty_’s HTTP Secure support and cookies features, as well as how to review and revisit past requests.
|
105
|
+
|
106
|
+
![Google example #1](http://htty.github.com/images/google1.png)
|
107
|
+
|
108
|
+
The _https://_ scheme and port 443 imply each other, just as the _http://_ scheme and port 80 imply each other. If you omit the scheme or the port, it will default to the appropriate value.
|
109
|
+
|
110
|
+
Notice that when cookies are offered in a response, a bold asterisk (it looks like a cookie) appears in the response summary. The same cookie symbol appears next to the _Set-Cookie_ header when you display response headers.
|
111
|
+
|
112
|
+
![Google example #2](http://htty.github.com/images/google2.png)
|
113
|
+
|
114
|
+
The `cookies-use` command copies cookies out of the response into the next request. The cookie symbol appears next to the _Cookie_ header when you display request headers.
|
115
|
+
|
116
|
+
![Google example #3](http://htty.github.com/images/google3.png)
|
117
|
+
|
118
|
+
An abbreviated history is available through the `history` command. Information about requests in the history includes request method, URL, number of headers (and a cookie symbol, if cookies were sent), and the size of the body. Information about responses in the history includes response code, number of headers (and a cookie symbol, if cookies were received), and the size of the body.
|
119
|
+
|
120
|
+
Note that history contains only numbered HTTP request and response pairs, not a record of all the commands you enter.
|
121
|
+
|
122
|
+
The `reuse` command makes a copy of the headers and body of an earlier request for you to build on.
|
123
|
+
|
124
|
+
Understanding complex HTTP conversations at a glance using history
|
125
|
+
------------------------------------------------------------------
|
126
|
+
|
127
|
+
Now we’ll look at _htty_’s HTTP Basic Authentication support and learn how to display unabbreviated transcripts of _htty_ sessions.
|
128
|
+
|
129
|
+
Assume that we have the following Sinatra application listening on Sinatra’s default port, 4567.
|
130
|
+
|
131
|
+
require 'sinatra'
|
132
|
+
|
133
|
+
get '/all-good' do
|
134
|
+
[200, [['Set-Cookie', 'foo=bar; baz']], 'Hello World!']
|
135
|
+
end
|
136
|
+
|
137
|
+
put '/huh' do
|
138
|
+
[404, 'What?']
|
139
|
+
end
|
140
|
+
|
141
|
+
delete '/hurl' do
|
142
|
+
[500, 'Barf!']
|
143
|
+
end
|
144
|
+
|
145
|
+
post '/submit-novel' do
|
146
|
+
redirect '/all-good'
|
147
|
+
end
|
148
|
+
|
149
|
+
This application expects _GET_ and _POST_ requests and responds in various contrived ways.
|
150
|
+
|
151
|
+
![Sinatra application example #1](http://htty.github.com/images/sinatra1.png)
|
152
|
+
|
153
|
+
When you change the userinfo portion of the address, or the entire address, the appropriate HTTP Basic Authentication header is created for you automatically. Notice that characters that require URL encoding are automatically URL-encoded (unless they are part of a URL-encoded expression).
|
154
|
+
|
155
|
+
When userinfo is supplied in a request, a bold mercantile symbol (_@_) appears next to the resulting _Authorization_ header when you display request headers (see below).
|
156
|
+
|
157
|
+
Type `body-set` to enter body data, and terminate it by typing Return three times consecutively. The body will only be sent for _POST_ and _PUT_ requests. The appropriate _Content-Length_ header is created for you automatically (see below).
|
158
|
+
|
159
|
+
Different response codes are rendered with colors that suggest their meaning:
|
160
|
+
|
161
|
+
* Response codes between 200 and 299 appear <span style="background-color: green; color: black; font-weight: bold; padding: 0 0.25em 0 0.25em;">black on green</span> to indicate success
|
162
|
+
* Response codes between 300 and 399 appear <span style="background-color: blue; color: white; font-weight: bold; padding: 0 0.25em 0 0.25em;">white on blue</span> to indicate redirection
|
163
|
+
* Response codes between 400 and 499 appear <span style="background-color: red; color: white; font-weight: bold; padding: 0 0.25em 0 0.25em;">white on red</span> to indicate failure
|
164
|
+
* Response codes between 500 and 599 appear <span style="background-color: yellow; color: black; font-weight: bold; padding: 0 0.25em 0 0.25em; text-decoration: blink;">flashing black on yellow</span> to indicate a server error
|
165
|
+
|
166
|
+
![Sinatra application example #2](http://htty.github.com/images/sinatra2.png)
|
167
|
+
|
168
|
+
As with the abbreviated history demonstrated earlier, verbose history shows a numbered list of requests and the responses they elicited. All information exchanged between client and server is shown.
|
169
|
+
|
170
|
+
Getting help
|
171
|
+
------------
|
172
|
+
|
173
|
+
You can learn how to use _htty_ commands from within _htty_.
|
174
|
+
|
175
|
+
![htty’s built-in help](http://htty.github.com/images/help.png)
|
176
|
+
|
177
|
+
The `help` command takes an optional argument of the abbreviated or full name of a command.
|
178
|
+
|
179
|
+
Coming soon
|
180
|
+
===========
|
181
|
+
|
182
|
+
Here are some features that are coming down the pike.
|
183
|
+
|
184
|
+
Commands for streamlining web form submission
|
185
|
+
---------------------------------------------
|
186
|
+
|
187
|
+
These features will make _htty_ better at screen-scraping.
|
188
|
+
|
189
|
+
Using any of the forthcoming `form` commands will clear any non-form content in the body of the request. Adding at least one URL-encoded form parameter to the request will set the _Content-Type_ header to _application/x-www-form-urlencoded_. Removing all URL-encoded form parameters will remove this header.
|
190
|
+
|
191
|
+
* `form` — display all form parameters offered in the response
|
192
|
+
* `form-fill` — prompt in turn for a value for each of the form inputs in the response
|
193
|
+
* <code>form-add _name_ _value_</code> — add a URL-encoded form parameter for the request, using the specified name and value
|
194
|
+
* <code>form-remove _name_</code> — remove a URL-encoded form parameter from the request, using the specified name
|
195
|
+
* `form-remove-all` — remove all URL-encoded form parameters from the request
|
196
|
+
|
197
|
+
You will also be able to pop open a browser window containing request and response bodies.
|
198
|
+
|
199
|
+
Shiny autocomplete goodness
|
200
|
+
---------------------------
|
201
|
+
|
202
|
+
We’ll have command command autocompletion, and possibly also Tab key navigation of forms.
|
203
|
+
|
204
|
+
Custom command aliases and shell emulation of _http-console_
|
205
|
+
------------------------------------------------------------
|
206
|
+
|
207
|
+
You should be able to make your own command aliases.
|
208
|
+
|
209
|
+
_http-console_ has a nice command-line. We should have an _http-console_ skin for _htty_.
|
210
|
+
|
211
|
+
Contributing
|
212
|
+
============
|
213
|
+
|
214
|
+
Report defects and feature requests on [GitHub Issues](http://github.com/htty/htty/issues).
|
215
|
+
|
216
|
+
Your patches are welcome, and you will receive attribution here for good stuff. Fork [the official _htty_ repository](http://github.com/htty/htty "htty’s ‘htty’ repository at GitHub") and send a pull request.
|
217
|
+
|
218
|
+
News and information
|
219
|
+
====================
|
220
|
+
|
221
|
+
Stay in touch with the _htty_ project by following [@get_htty](http://twitter.com/get_htty "get_htty at Twitter") on Twitter.
|
222
|
+
|
223
|
+
You can also get help in the [#htty channel on Freenode](http://webchat.freenode.net/?channels=htty).
|
224
|
+
|
225
|
+
Credits
|
226
|
+
=======
|
227
|
+
|
228
|
+
The author, [Nils Jonsson](mailto:htty@nilsjonsson.com), owes a debt of inspiration to the [_http-console_](http://github.com/cloudhead/http-console) project.
|
229
|
+
|
230
|
+
Thanks to contributors:
|
231
|
+
|
232
|
+
* Bo Frederiksen ([bofrede](http://github.com/bofrede "bofrede at GitHub")) for work on the CLI
|
233
|
+
* Robert Pitts ([rbxbx](http://github.com/rbxbx "rbxbx at GitHub")) for work on the CLI and on RSpec specs
|
234
|
+
|
235
|
+
License
|
236
|
+
=======
|
237
|
+
|
238
|
+
Released under the [MIT License](file.MIT-LICENSE.html).
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/bin/htty
CHANGED
data/{app → lib}/htty.rb
RENAMED
data/{app → lib}/htty/cli.rb
RENAMED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'readline'
|
3
2
|
require File.expand_path("#{File.dirname __FILE__}/cli/commands")
|
4
3
|
require File.expand_path("#{File.dirname __FILE__}/cli/commands/help")
|
5
4
|
require File.expand_path("#{File.dirname __FILE__}/cli/commands/quit")
|
@@ -39,6 +38,10 @@ class HTTY::CLI
|
|
39
38
|
strong(HTTY::CLI::Commands::Help.command_line))
|
40
39
|
next
|
41
40
|
end
|
41
|
+
if command == :unclosed_quote
|
42
|
+
$stderr.puts notice('Unclosed quoted expression -- try again')
|
43
|
+
next
|
44
|
+
end
|
42
45
|
if ARGV.include?('--debug')
|
43
46
|
command.perform
|
44
47
|
else
|
@@ -63,8 +66,12 @@ private
|
|
63
66
|
def prompt_for_command
|
64
67
|
command_line = ''
|
65
68
|
while command_line.empty? do
|
66
|
-
|
67
|
-
command_line =
|
69
|
+
prompt = prompt(session.requests.last)
|
70
|
+
if (command_line = Readline.readline(prompt, true)).nil?
|
71
|
+
raise Interrupt
|
72
|
+
end
|
73
|
+
command_line.chomp!
|
74
|
+
command_line.strip!
|
68
75
|
end
|
69
76
|
HTTY::CLI::Commands.build_for command_line, :session => session
|
70
77
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# Defines HTTY::CLI::Command.
|
2
|
-
|
3
1
|
require 'abbrev'
|
4
2
|
require 'shellwords'
|
5
3
|
require File.expand_path("#{File.dirname __FILE__}/display")
|
@@ -31,7 +29,12 @@ class HTTY::CLI::Command
|
|
31
29
|
if (match = (command_line_regexp.match(command_line)))
|
32
30
|
all_attributes = attributes
|
33
31
|
if (arguments = match.captures[0])
|
34
|
-
|
32
|
+
begin
|
33
|
+
split_arguments = arguments.strip.shellsplit
|
34
|
+
rescue ArgumentError
|
35
|
+
return :unclosed_quote
|
36
|
+
end
|
37
|
+
return new(attributes.merge(:arguments => split_arguments))
|
35
38
|
end
|
36
39
|
return new(attributes)
|
37
40
|
end
|
@@ -119,6 +122,25 @@ class HTTY::CLI::Command
|
|
119
122
|
Array(alias_for)
|
120
123
|
end
|
121
124
|
|
125
|
+
protected
|
126
|
+
|
127
|
+
# Displays a notice if cookies are cleared on the specified _request_ in the
|
128
|
+
# course of the block.
|
129
|
+
def self.notify_if_cookies_cleared(request)
|
130
|
+
had_cookies = cookies?(request)
|
131
|
+
changed_request = yield
|
132
|
+
puts notice('Cookies cleared') if had_cookies && !cookies?(changed_request)
|
133
|
+
changed_request
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def self.cookies?(request)
|
139
|
+
!request.cookies.empty?
|
140
|
+
end
|
141
|
+
|
142
|
+
public
|
143
|
+
|
122
144
|
# Returns the arguments provided to the command.
|
123
145
|
attr_reader :arguments
|
124
146
|
|
@@ -1,9 +1,11 @@
|
|
1
|
-
# Defines HTTY::CLI::Commands::Address.
|
2
|
-
|
3
1
|
require File.expand_path("#{File.dirname __FILE__}/../command")
|
4
|
-
require File.expand_path("#{File.dirname __FILE__}
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/fragment_set")
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/host_set")
|
4
|
+
require File.expand_path("#{File.dirname __FILE__}/path_set")
|
5
5
|
require File.expand_path("#{File.dirname __FILE__}/port_set")
|
6
|
+
require File.expand_path("#{File.dirname __FILE__}/query_set")
|
6
7
|
require File.expand_path("#{File.dirname __FILE__}/scheme_set")
|
8
|
+
require File.expand_path("#{File.dirname __FILE__}/userinfo_set")
|
7
9
|
|
8
10
|
module HTTY; end
|
9
11
|
|
@@ -14,8 +16,6 @@ module HTTY::CLI::Commands; end
|
|
14
16
|
# Encapsulates the _address_ command.
|
15
17
|
class HTTY::CLI::Commands::Address < HTTY::CLI::Command
|
16
18
|
|
17
|
-
include HTTY::CLI::CookieClearingCommand
|
18
|
-
|
19
19
|
# Returns the name of a category under which help for the _address_ command
|
20
20
|
# should appear.
|
21
21
|
def self.category
|
@@ -35,7 +35,7 @@ class HTTY::CLI::Commands::Address < HTTY::CLI::Command
|
|
35
35
|
# Returns the extended help text for the _address_ command.
|
36
36
|
def self.help_extended
|
37
37
|
'Changes the address used for the request. Does not communicate with the ' +
|
38
|
-
"
|
38
|
+
"host.\n" +
|
39
39
|
"\n" +
|
40
40
|
'The URL you supply can be partial. At a minimum, you must specify a ' +
|
41
41
|
'host. The optional and required elements of an address are illustrated ' +
|
@@ -62,20 +62,26 @@ class HTTY::CLI::Commands::Address < HTTY::CLI::Command
|
|
62
62
|
'If (4) is omitted, port 80 is used, except if (1) is specified as ' +
|
63
63
|
"HTTPS, in which case port 443 is used.\n" +
|
64
64
|
"\n" +
|
65
|
-
"If (5) is omitted, the root path (i.e.,
|
65
|
+
"If (5) is omitted, the root path (i.e., '/') is used.\n" +
|
66
66
|
"\n" +
|
67
67
|
'The console prompt shows the address for the current request.'
|
68
68
|
end
|
69
69
|
|
70
70
|
# Returns related command classes for the _address_ command.
|
71
71
|
def self.see_also_commands
|
72
|
-
[HTTY::CLI::Commands::SchemeSet,
|
72
|
+
[HTTY::CLI::Commands::SchemeSet,
|
73
|
+
HTTY::CLI::Commands::UserinfoSet,
|
74
|
+
HTTY::CLI::Commands::HostSet,
|
75
|
+
HTTY::CLI::Commands::PortSet,
|
76
|
+
HTTY::CLI::Commands::PathSet,
|
77
|
+
HTTY::CLI::Commands::QuerySet,
|
78
|
+
HTTY::CLI::Commands::FragmentSet]
|
73
79
|
end
|
74
80
|
|
75
81
|
# Performs the _address_ command.
|
76
82
|
def perform
|
77
83
|
add_request_if_has_response do |request|
|
78
|
-
notify_if_cookies_cleared request do
|
84
|
+
self.class.notify_if_cookies_cleared request do
|
79
85
|
request.address(*arguments)
|
80
86
|
end
|
81
87
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# Defines HTTY::CLI::Commands::BodyRequest.
|
2
|
-
|
3
1
|
require File.expand_path("#{File.dirname __FILE__}/../command")
|
4
2
|
require File.expand_path("#{File.dirname __FILE__}/body_response")
|
5
3
|
require File.expand_path("#{File.dirname __FILE__}/body_set")
|
@@ -29,7 +27,7 @@ class HTTY::CLI::Commands::BodyRequest < HTTY::CLI::Command
|
|
29
27
|
# Returns the extended help text for the _body-request_ command.
|
30
28
|
def self.help_extended
|
31
29
|
'Displays the body content used for the request. Does not communicate ' +
|
32
|
-
'with the
|
30
|
+
'with the host.'
|
33
31
|
end
|
34
32
|
|
35
33
|
# Returns related command classes for the _body-request_ command.
|