I love curl, curl is awesome to test many services like HTTP/HTTPS,
FTP, IMAP, etc. But, curl sometimes is hard to use for my customers. So, I
have recommended for them to use the httpie.
In my main job, I use curl/httpie to see HTTP headers and cache problems. Then, when I have show some evidence for him, I prefer show with httpie.
A simple example using only HTTP headers.
curl
1
2
3
4
5
6
7
8
9
10
11
12
| fike@klatoon:~/d$ curl -I http://fernandoike.com
HTTP/1.1 200 OK
Date: Tue, 22 Jul 2014 14:40:56 GMT
Server: Apache/2.2.22
Last-Modified: Thu, 31 May 2012 20:17:19 GMT
ETag: "c57c-b1-4c15ac12cd1c0"
Accept-Ranges: bytes
Content-Length: 177
Vary: Accept-Encoding
Content-Type: text/html
fike@klatoon:~/d$
|
httpie
1
2
3
4
5
6
7
8
9
10
11
12
13
| fike@klatoon:~/d$ http --headers http://fernandoike.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Encoding: gzip
Content-Length: 146
Content-Type: text/html
Date: Tue, 22 Jul 2014 14:20:57 GMT
ETag: "c57c-b1-4c15ac12cd1c0"
Last-Modified: Thu, 31 May 2012 20:17:19 GMT
Server: Apache/2.2.22
Vary: Accept-Encoding
fike@klatoon:~/d$
|
Easy and simple, right? But this isn’t the most cool feature. The most cool httpie feature is the STDOUT colorized.
However, curl and httpie has a little bit difference. The curl option “-I” use the
HEAD HTTP method and httpie use GET HTTP method. The HEAD HTTP method
can’t work in all scenarios because a firewall, IPS or WAF can block this method.
To the curl has the same behavior that httpie and using GET HTTP method, it must
use more options:
curl
1
2
3
4
5
6
7
8
9
10
11
12
13
| fike@klatoon:~/d$ curl -s -D - http://fernandoike.com -o /dev/null
HTTP/1.1 200 OK
Date: Tue, 22 Jul 2014 15:10:24 GMT
Server: Apache/2.2.22
Last-Modified: Thu, 31 May 2012 20:17:19 GMT
ETag: "c57c-b1-4c15ac12cd1c0"
Accept-Ranges: bytes
Content-Length: 177
Vary: Accept-Encoding
Content-Type: text/html
fike@klatoon:~/d$
|
To add HTTP headers using curl, have to use “-H” option. For example, adding
HTTP header to disable keep-alive connection.
curl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| fike@klatoon:~/d$ curl -H "Connection: close" -s -D - http://fernandoike.com -o /dev/null
HTTP/1.1 200 OK
Date: Tue, 22 Jul 2014 15:17:43 GMT
Server: Apache/2.2.22
Last-Modified: Thu, 31 May 2012 20:17:19 GMT
ETag: "c57c-b1-4c15ac12cd1c0"
Accept-Ranges: bytes
Content-Length: 177
Vary: Accept-Encoding
Connection: close
Content-Type: text/html
fike@klatoon:~/d$
|
And with httpie more simple…
httpie
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| fike@klatoon:~/d$ http --headers http://www.fernandoike.com "Connection: close"
HTTP/1.1 200 OK
Accept-Ranges: bytes
Connection: close
Content-Encoding: gzip
Content-Length: 16424
Content-Type: text/html
Date: Tue, 22 Jul 2014 15:22:58 GMT
ETag: "2010c-d3fb-4fdd68cfc0d40"
Last-Modified: Thu, 10 Jul 2014 13:10:37 GMT
Server: Apache/2.2.22
Vary: Accept-Encoding
fike@klatoon:~/d$
|
An another example is to add HTTP headers if need identify if a URI is cacheable a CDN.
This case was tested in site that use Akamai.
curl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| fike@klatoon:~/d$ curl -H "Pragma: akamai-x-cache-on" -s -D - http://www.bestbuy.com -o /dev/null
HTTP/1.1 200 OK
Server: Apache
Content-Length: 4663
Content-Type: text/html
ETag: "7a10c27a970af1daf4b526ed08cd28c0:1343841543"
Expires: Tue, 22 Jul 2014 15:25:00 GMT
Cache-Control: max-age=0, no-cache, no-store
Pragma: no-cache
Date: Tue, 22 Jul 2014 15:25:00 GMT
X-Cache: TCP_MEM_HIT from a201-20-244-37.deploy.akamaitechnologies.com (AkamaiGHost/6.16.2.1-13049459) (-)
Connection: keep-alive
fike@klatoon:~/d$
|
The same test but with httpie.
httpie
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| fike@klatoon:~/d$ http --headers http://www.bestbuy.com "Pragma: akamai-x-cache-on"
HTTP/1.1 200 OK
Cache-Control: max-age=0, no-cache, no-store
Connection: keep-alive
Content-Encoding: gzip
Content-Length: 1658
Content-Type: text/html
Date: Tue, 22 Jul 2014 15:23:55 GMT
ETag: "7a10c27a970af1daf4b526ed08cd28c0:1343841543"
Expires: Tue, 22 Jul 2014 15:23:55 GMT
Pragma: no-cache
Server: Apache
Vary: Accept-Encoding
X-Cache: TCP_HIT from a201-20-244-37.deploy.akamaitechnologies.com (AkamaiGHost/6.16.2.1-13049459) (-)
|
If you want search about Akamai HTTP headers, go to Stackoverflow link.
Conclusion is if need something more friendly, use httpie. But if you need run
tests more complex curl is the tool.
P.S. Install httpie is simple a Debian like. Debian has official package.
1
| #aptitude install httpie
|
0sem comentários ainda