Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

httpcat is a simple utility for constructing raw HTTP requests on the command line.

License

NotificationsYou must be signed in to change notification settings

httpie/httpcat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

httpcat is a simple utility for constructing raw HTTPrequests on the command line.

Why?

Sometimes it is useful to be able to create an actual rawHTTP requeston the command line:

  • To debug a server issue
  • To test the handling of invalid HTTP requests
  • To learn how HTTP works under the hood

In such cases, existing CLI HTTP clients—such ashttpie,curl,orwget—are too high-level as they providean abstraction layer and one doesn't have a complete control over theexact raw data that gets written to the HTTP socket connection.

Lower-level tools, such as the popularnetcat, are better suited for thisjob.

However, the syntax of HTTP requires headers to be separated with\r\n which makes it difficult to produce them on the command line.A typical solution involves the use ofecho:

$echo -ne'POST /post HTTP/1.1\r\nHost: httpbin.org\r\nContent-Length: 5\r\n\r\nHello'| \    nc localhost 8000

httpcat makes this easier:

How it works

  1. Reads command arguments as lines and then lines fromstdin
  2. Auto-completes them, if necessary
  3. Writes them tostdout

Features

  • Automatic\r\n completion
  • AutomaticMethod completion inRequest-Line
  • AutomaticHTTP-Version completion inRequest-Line

Usage

Interactively create a request and send it withnc:

$ httpcat -v| nc httpbin.org 80POST /post HTTP/1.1> POST /post HTTP/1.1\r\nHost: httpbin.org> Host: httpbin.org\r\nContent-Length: 6> Content-Length: 6\r\n>\r\nHello> Hello

Specify the whole request in the arguments. Here'' represents an emptyline which will be converted to\r\n\ separating the headers and thebody. Note also that the omittedHTTP-Version is auto-completed:

$ httpcat -v'POST /post''Host: httpbin.org''Content-Length: 5''''Hello'| nc httpbin.org 80> POST /post HTTP/1.1\r\n> Host: httpbin.org\r\n> Content-Length: 5\r\n>\r\n> Hello

OmittedMethod is set toGET andHTTP-Version is auto-completed:

$ httpcat -v /'Host: example.org'''| nc example.org 80> GET / HTTP/1.1\r\n> Host: example.org\r\n>\r\n

You can, for example, usestdin for data and arguments for headers:

$ cat file.txt| httpcat -v'POST /post''Host: httpbin.org''Content-Length: 16'''| nc httpbin.org 80> POST /post HTTP/1.1\r\n> Host: httpbin.org\r\n> Content-Length: 16\r\n>\r\n> Hello from file

See alsohttpcat --help:

usage: httpcat [-h] [-V, --version] [-v] [-n] [line [line ...]]Create raw HTTP requests on the command line.positional arguments:  line            input lines read before lines from stdinoptional arguments:  -h, --help      show this help message and exit  -V, --version   show program's version number and exit  -v, --verbose   print info about output lines to stderr  -n, --no-stdin  disable reading of lines from stdin

Dependencies

  • Python 3

Installation

pip3 install httpcat

Alternatively, you can just downloadhttpcat.py manually and invokeit as./httpcat.py instead ofhttpcat.

Tests

python3 setup.pytest

HTTPie offline mode

HTTPie CLI starting with version 2.0.0 also provides an--offline mode. This makes it a good alternative tohttpcat because it provides a convenient mechanism for crafting arbitrary HTTP requests without sending them using the user-friendly HTTPie syntax, for example:

echo -n'Hello'| http --offline POST httpbin.org/post

The above command generates the following output:

POST /post HTTP/1.1Accept: application/json, */*;q=0.5Accept-Encoding: gzip, deflateConnection: keep-aliveContent-Length: 5Content-Type: application/jsonHost: httpbin.orgUser-Agent: HTTPie/2.2.0Hello

The output is valid HTTP, so it can simply be sent usingnc:

$echo -n'Hello'| http --offline POST httpbin.org/post| nc httpbin.org 80

Changelog

  • 0.0.2 (2016-12-13)

    • Added-v, --verbose and the command is more quiet by default.
    • Added-n, --no-stdin
    • Added-h, --help
    • Added-V, --version
  • 0.0.1 (2016-12-12)

    • Initial release.

Contact

Jakub Roztocil

About

httpcat is a simple utility for constructing raw HTTP requests on the command line.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    Languages


    [8]ページ先頭

    ©2009-2025 Movatter.jp