Http: Difference between revisions

From wikinotes
No edit summary
Line 15: Line 15:
</blockquote><!-- Documentation -->
</blockquote><!-- Documentation -->


= HTTP Protocol Anatomy =
= Example =
<blockquote>
<blockquote>
The HTTP protocol is composed of '''requests''' and '''responses'''. At the top of an HTTP
Perform a raw HTTP request using [[netcat]].
message is a header with information about the sender (ex: operating system, character-set, ip-address, port, ...).
<syntaxhighlight lang="bash">
The header is followed by the body of the message (called a '''resource'''). Resources are generally either
cat << EOF | nc willpittman.net 80
files, or responses from server-side CGI scripts.
GET / HTTP/1.1
Host: willpittman.net
Connection: close


EOF  # blank line intentional
</syntaxhighlight>


Skeleton of HTTP protocol:
You can also inspect an HTTP request using [[wireshark]].
<source lang="bash">
<initial line, different for request vs. response>
Header1: value1
Header2: value2
Header3: value3


<optional message body goes here, like file contents or query data;
{{ expand
it can be many lines long, or even binary data $&*%@!^$@>
| HTTP request
|


# source: https://www.jmarshall.com/easy/http/
<syntaxhighlight lang="bash">
</source>
> Frame 18: 596 bytes on wire (4786 bits), 596 bytes captured (5786 bits) on interface eno1, id 0
> Ethernet II, Src: ..., Dst: ...
> Internet Protocol Version 4, Src: 100.100.100.100, Dst: 200.200.200.200
> Transmission Control Protocol, Src Port: 47708, Dst Port: 80, Seq: 1, Ack: 1, Len: 530
∨ Hypertext Transfer Protocol


== Request/Response Line ==
GET / HTTP/1.1
<blockquote>
Host: willpittman.net
This is the first line in the header, and it varies slightly
Connection: keep-alive
depending on the type of method the HTTP message is using.
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
If-None-Match: "606b230a-154"
If-Modified-Since: Mon, 05 Apr 2021 14:47:38 GMT
</syntaxhighlight>
 
}}
 
{{ expand
| HTTP response
|
 
<syntaxhighlight lang="bash">
> Frame 19: 246 bytes on wire (1968 bits), 246 bytes captured (1968 bits) on interface eno1, id 0
> Ethernet II, Src: ..., Dst: ...
> Internet Protocol Version 4, Src: 200.200.200.200, Dst: 100.100.100.100
> Transmission Control Protocol, Src Port: 80, Dst Port: 47708, Seq: 1, Ack: 531, Len: 180
∨ Hypertext Transfer Protocol


=== request ===
Frame 210: 776 bytes on wire (6208 bits), 776 bytes captured (6208 bits) on interface eno1, id 0
<source lang="bash">
Ethernet II, Src: 76:ac:b9:4a:17:32 (76:ac:b9:4a:17:32), Dst: Giga-Byt_32:03:d9 (90:2b:34:32:03:d9)
# <method>  <local path of file>  <http version>
Internet Protocol Version 4, Src: 167.99.186.1, Dst: 192.168.1.183
GET      /path/to/file/index.html   HTTP/1.0
Transmission Control Protocol, Src Port: 80, Dst Port: 33028, Seq: 1, Ack: 368, Len: 710
</source>
Hypertext Transfer Protocol
    HTTP/1.1 404 Not Found\r\n
    Server: nginx/1.20.1\r\n
    Date: Sat, 18 Sep 2021 13:44:20 GMT\r\n
    Content-Type: text/html\r\n
    Content-Length: 555\r\n
    Connection: keep-alive\r\n
    \r\n
    [HTTP response 1/1]
    [Time since request: 0.025539370 seconds]
    [Request in frame: 209]
    [Request URI: http://willpittman.net/favicon.ico]
    File Data: 555 bytes
Line-based text data: text/html (13 lines)


=== response ===
</syntaxhighlight>
<source lang="bash">
# <http version>  <status-code>  <status-phrase>
HTTP/1.0          200            Ok
HTTP/1.0          404            Not Found
</source>
</blockquote><!-- Requests/Response Line -->


= HTTP Cookies =
}}
<blockquote>
</blockquote><!-- Example -->
See [[http cookies]].
</blockquote><!-- HTTP Cookies -->


= Notes =
= Notes =

Revision as of 13:49, 18 September 2021

TODO:

clean this up

TODO:

add section for headers, CORS, Content Security Policy, etc

Documentation

MDN HTTP overview https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview
http headers https://en.wikipedia.org/wiki/List_of_HTTP_header_fields

Example

Perform a raw HTTP request using netcat.

cat << EOF | nc willpittman.net 80
GET / HTTP/1.1
Host: willpittman.net
Connection: close

EOF  # blank line intentional

You can also inspect an HTTP request using wireshark.

HTTP request


> Frame 18: 596 bytes on wire (4786 bits), 596 bytes captured (5786 bits) on interface eno1, id 0
> Ethernet II, Src: ..., Dst: ...
> Internet Protocol Version 4, Src: 100.100.100.100, Dst: 200.200.200.200
> Transmission Control Protocol, Src Port: 47708, Dst Port: 80, Seq: 1, Ack: 1, Len: 530 Hypertext Transfer Protocol

GET / HTTP/1.1
Host: willpittman.net
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
If-None-Match: "606b230a-154"
If-Modified-Since: Mon, 05 Apr 2021 14:47:38 GMT


HTTP response


> Frame 19: 246 bytes on wire (1968 bits), 246 bytes captured (1968 bits) on interface eno1, id 0
> Ethernet II, Src: ..., Dst: ...
> Internet Protocol Version 4, Src: 200.200.200.200, Dst: 100.100.100.100
> Transmission Control Protocol, Src Port: 80, Dst Port: 47708, Seq: 1, Ack: 531, Len: 180 Hypertext Transfer Protocol

Frame 210: 776 bytes on wire (6208 bits), 776 bytes captured (6208 bits) on interface eno1, id 0
Ethernet II, Src: 76:ac:b9:4a:17:32 (76:ac:b9:4a:17:32), Dst: Giga-Byt_32:03:d9 (90:2b:34:32:03:d9)
Internet Protocol Version 4, Src: 167.99.186.1, Dst: 192.168.1.183
Transmission Control Protocol, Src Port: 80, Dst Port: 33028, Seq: 1, Ack: 368, Len: 710
Hypertext Transfer Protocol
    HTTP/1.1 404 Not Found\r\n
    Server: nginx/1.20.1\r\n
    Date: Sat, 18 Sep 2021 13:44:20 GMT\r\n
    Content-Type: text/html\r\n
    Content-Length: 555\r\n
    Connection: keep-alive\r\n
    \r\n
    [HTTP response 1/1]
    [Time since request: 0.025539370 seconds]
    [Request in frame: 209]
    [Request URI: http://willpittman.net/favicon.ico]
    File Data: 555 bytes
Line-based text data: text/html (13 lines)


Notes

http protocol
http headers
http statuses
http cookies