<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>HTTP on Cyrus Yip's blog</title><link>https://cyrusyip.org/en/tags/http/</link><description>Recent content in HTTP on Cyrus Yip's blog</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Tue, 29 Oct 2024 00:00:00 +0800</lastBuildDate><atom:link href="https://cyrusyip.org/en/tags/http/index.xml" rel="self" type="application/rss+xml"/><item><title>What Is HTTP</title><link>https://cyrusyip.org/en/posts/2024/10/29/http/</link><pubDate>Tue, 29 Oct 2024 00:00:00 +0800</pubDate><guid>https://cyrusyip.org/en/posts/2024/10/29/http/</guid><description>&lt;h2 class="heading" id="introduction"&gt;
 Introduction&lt;span class="heading__anchor"&gt; &lt;a href="#introduction"&gt;#&lt;/a&gt;&lt;/span&gt;
&lt;/h2&gt;&lt;p&gt;HTTP (&lt;strong&gt;H&lt;/strong&gt;yper&lt;strong&gt;t&lt;/strong&gt;ext &lt;strong&gt;T&lt;/strong&gt;ransfer &lt;strong&gt;P&lt;/strong&gt;rotocol) is a protocol for transferring information, such as HTML files. It&amp;rsquo;s the foundation of data communication for the World Wide Web. In a typical HTTP session, the client (such as a browser) sends a request to the server, which sends back a response.&lt;/p&gt;
&lt;h2 class="heading" id="http-request"&gt;
 HTTP Request&lt;span class="heading__anchor"&gt; &lt;a href="#http-request"&gt;#&lt;/a&gt;&lt;/span&gt;
&lt;/h2&gt;&lt;p&gt;A typical HTTP request consists of:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;request line (request method, path, protocol version)&lt;/li&gt;
&lt;li&gt;request header&lt;/li&gt;
&lt;li&gt;empty line&lt;/li&gt;
&lt;li&gt;optional message body&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here is an example of HTTP request message (&lt;code&gt;curl --verbose https://cyrusyip.org/en/&lt;/code&gt;):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;GET /en/ HTTP/2
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Host: cyrusyip.org
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;User-Agent: curl/8.10.1
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Accept: */*
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h3 class="heading" id="http-request-methods"&gt;
 HTTP Request Methods&lt;span class="heading__anchor"&gt; &lt;a href="#http-request-methods"&gt;#&lt;/a&gt;&lt;/span&gt;
&lt;/h3&gt;&lt;p&gt;HTTP request methods (also called HTTP verbs) indicate the purpose of the request and what to expect. Here are the common request methods:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;GET&lt;/code&gt;: request the specified resource&lt;/li&gt;
&lt;li&gt;&lt;code&gt;POST&lt;/code&gt;: sends information to the server&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 class="heading" id="http-response"&gt;
 HTTP Response&lt;span class="heading__anchor"&gt; &lt;a href="#http-response"&gt;#&lt;/a&gt;&lt;/span&gt;
&lt;/h2&gt;&lt;p&gt;A typical HTTP response consists of:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;status line (protocol version, status code, optional explanation of status code)&lt;/li&gt;
&lt;li&gt;response header&lt;/li&gt;
&lt;li&gt;empty line&lt;/li&gt;
&lt;li&gt;optional message body&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here is an example of HTTP response message (&lt;code&gt;curl --verbose https://example.com/&lt;/code&gt;):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;span class="lnt"&gt;16
&lt;/span&gt;&lt;span class="lnt"&gt;17
&lt;/span&gt;&lt;span class="lnt"&gt;18
&lt;/span&gt;&lt;span class="lnt"&gt;19
&lt;/span&gt;&lt;span class="lnt"&gt;20
&lt;/span&gt;&lt;span class="lnt"&gt;21
&lt;/span&gt;&lt;span class="lnt"&gt;22
&lt;/span&gt;&lt;span class="lnt"&gt;23
&lt;/span&gt;&lt;span class="lnt"&gt;24
&lt;/span&gt;&lt;span class="lnt"&gt;25
&lt;/span&gt;&lt;span class="lnt"&gt;26
&lt;/span&gt;&lt;span class="lnt"&gt;27
&lt;/span&gt;&lt;span class="lnt"&gt;28
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;HTTP/2 200
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;age: 190635
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cache-control: max-age=604800
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;content-type: text/html; charset=UTF-8
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;date: Mon, 28 Oct 2024 09:39:38 GMT
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;etag: &amp;#34;3147526947+gzip+ident&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;expires: Mon, 04 Nov 2024 09:39:38 GMT
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;last-modified: Thu, 17 Oct 2019 07:18:26 GMT
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;server: ECAcc (sac/2571)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;vary: Accept-Encoding
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;x-cache: HIT
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;content-length: 1256
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&amp;lt;!doctype html&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&amp;lt;html&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&amp;lt;head&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;content is stripped...
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&amp;lt;/head&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&amp;lt;body&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&amp;lt;div&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &amp;lt;h1&amp;gt;Example Domain&amp;lt;/h1&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &amp;lt;p&amp;gt;This domain is for use in illustrative examples in documents. You may use this
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; domain in literature without prior coordination or asking for permission.&amp;lt;/p&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &amp;lt;p&amp;gt;&amp;lt;a href=&amp;#34;https://www.iana.org/domains/example&amp;#34;&amp;gt;More information...&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&amp;lt;/div&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&amp;lt;/body&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&amp;lt;/html&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h3 class="heading" id="http-status-codes"&gt;
 HTTP Status Codes&lt;span class="heading__anchor"&gt; &lt;a href="#http-status-codes"&gt;#&lt;/a&gt;&lt;/span&gt;
&lt;/h3&gt;&lt;p&gt;HTTP status codes are three-digit numbers that indicate whether an HTTP request has been successfully completed. They are grouped in five classes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://httpwg.org/specs/rfc9110.html#status.1xx"&gt;1xx (Informational)&lt;/a&gt;: The request was received, continuing process.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://httpwg.org/specs/rfc9110.html#status.2xx"&gt;2xx (Successful)&lt;/a&gt;: The request was successfully received, understood, and accepted.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://httpwg.org/specs/rfc9110.html#status.3xx"&gt;3xx (Redirection)&lt;/a&gt;: Further action needs to be taken in order to complete the request.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://httpwg.org/specs/rfc9110.html#status.4xx"&gt;4xx (Client Error)&lt;/a&gt;: The request contains bad syntax or cannot be fulfilled.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://httpwg.org/specs/rfc9110.html#status.5xx"&gt;5xx (Server Error)&lt;/a&gt;: The server failed to fulfill an apparently valid request.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here are some commonly used HTTP status codes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;103 Early Hints&lt;/code&gt;: This status code lets the user agent preload resources while the server prepares a response.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;200 OK&lt;/code&gt;: The request succeeded.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;301 Moved Permanently&lt;/code&gt;: The URL of the requested resource has been &lt;em&gt;permanently&lt;/em&gt; changed.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;302 Found&lt;/code&gt;: The URL of the requested resource has been &lt;em&gt;temporarily&lt;/em&gt; changed.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;403 Forbidden&lt;/code&gt;: The client does not have access permission to the resource.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;404 Not Found&lt;/code&gt;: The server cannot find the requested resource.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;500 Internal Server Error&lt;/code&gt;: The server has encountered an unexpected condition that prevented it from fulfilling the request.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;503 Service Unavailable&lt;/code&gt;: The server is not ready to handle the request. It may be down for maintenance, or it may be overloaded.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 class="heading" id="references"&gt;
 References&lt;span class="heading__anchor"&gt; &lt;a href="#references"&gt;#&lt;/a&gt;&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview"&gt;An overview of HTTP - HTTP | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cloudflare.com/learning/ddos/glossary/hypertext-transfer-protocol-http/"&gt;What is HTTP? | Cloudflare&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods"&gt;HTTP request methods - HTTP | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://httpwg.org/specs/rfc9110.html"&gt;RFC 9110 - HTTP Semantics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/HTTP"&gt;HTTP - Wikipedia&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>