HTTP

๊น€๋‚จ๊ฒฝยท2022๋…„ 12์›” 1์ผ
0

network

๋ชฉ๋ก ๋ณด๊ธฐ
3/27

HTTP Messages

๐Ÿ’ก ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„ ์‚ฌ์ด ๋ฐ์ดํ„ฐ๊ฐ€ ๊ตํ™˜๋˜๋Š” ๋ฐฉ์‹
๐Ÿ’ก ๊ตฌ์„ฑ ํŒŒ์ผ, API, ๊ธฐํƒ€ ์ธํ„ฐํŽ˜์ด์Šค์—์„œ HTTP Messages๋ฅผ ์ž๋™์œผ๋กœ ์™„์„ฑ
๐Ÿ’ก requests(์š”์ฒญ) / reponses(์‘๋‹ต)

๐Ÿ“— ๊ตฌ์กฐ
start line
์š”์ฒญ์ด๋‚˜ ์‘๋‹ต์˜ ์ƒํƒœ. responses์—์„œ๋Š” status line์ด๋ผ๊ณ  ํ•จ
HTTP headers
์š”์ฒญ์„ ์ง€์ •, ๋ณธ๋ฌธ์„ ์„ค๋ช…ํ•จ
empty line
ํ—ค๋”์™€ ๋ณธ๋ฌธ์„ ๊ตฌ๋ณ„
body
์š”์ฒญ๊ณผ ๊ด€๋ จ๋œ ๋ฐ์ดํ„ฐ๋‚˜ ์‘๋‹ต๊ณผ ๊ด€๋ จ๋œ ๋ฐ์ดํ„ฐ

์š”์ฒญ์ด๋‚˜ ์‘๋‹ต์˜ head start line & HTTP headers
์š”์ฒญ์ด๋‚˜ ์‘๋‹ต์˜ payload body

๐Ÿ“— ๋ฌด์ƒํƒœ์„ฑ(stateless)
HTTP๋กœ ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„๊ฐ€ ํ†ต์‹  ์ค‘, HTTP๊ฐ€ ํด๋ผ์ด์–ธํŠธ๋‚˜ ์„œ๋ฒ„์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•˜์ง€ ์•Š์Œ
ํด๋ผ์ด์–ธํŠธ์—์„œ ๋ฐœ์ƒํ•œ ๋ชจ๋“  ์ƒํƒœ๋ฅผ HTTP ํ†ต์‹ ์ด ์ถ”์ ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๋œป

HTTP Requests

๐Ÿ’ก ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋ฒ„์—๊ฒŒ ๋ณด๋‚ด๋Š” ๋ฉ”์‹œ์ง€

๐Ÿ“— start line

โ—พ๏ธ HTTP method
์ˆ˜ํ–‰ํ•  ์ž‘์—…(GET, POST), ๋ฐฉ์‹(HEAD or OPTIONS) ์„ค๋ช…

โ—พ๏ธ ์š”์ฒญ ๋Œ€์ƒ(URL, URI), ํ”„๋กœํ† ์ฝœ, ํฌํŠธ, ๋„๋ฉ”์ธ์˜ ์ ˆ๋Œ€ ๊ฒฝ๋กœ

ย ย ย ย ย ย -origin ํ˜•์‹ : '?'์™€ ์ฟผ๋ฆฌ ๋ฌธ์ž์—ด์ด ๋ถ™๋Š” ์ ˆ๋Œ€ ๊ฒฝ๋กœ
ย ย ย ย ย POST / HTTP 1.1
ย ย ย ย ย -absolute ํ˜•์‹ : URL ํ˜•์‹
ย ย ย ย ย ํ”„๋ก์‹œ์— ๋ถ™๋Š” ๊ฒฝ์šฐ GET ์‚ฌ์šฉ
ย ย ย ย ย GET http://developer.mozilla.org/en-US/docs/Web/HTTP/Messages HTTP/1.1
ย ย ย ย ย -authority ํ˜•์‹ : ๋ฉ”์ธ ์ด๋ฆ„๊ณผ ํฌํŠธ ๋ฒˆํ˜ธ๋กœ ์ด๋ฃจ์–ด์ง„ URL์˜ ์ผ๋ถ€๋ถ„
ย ย ย ย ย HTTP ํ„ฐ๋„์„ ๊ตฌ์ถ•ํ•˜๋Š” ๊ฒฝ์šฐ, CONNECT์™€ ํ•จ๊ป˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
ย ย ย ย ย CONNECT developer.mozilla.org:80 HTTP/1.1
ย ย ย ย ย -asterisk ํ˜•์‹ : OPTIONS ์™€ ํ•จ๊ป˜ ๋ณ„ํ‘œ()๋กœ ์„œ๋ฒ„ ์ „์ฒด๋ฅผ ํ‘œํ˜„
ย ย ย ย ย OPTIONS
HTTP/1.1

โ—พ๏ธ HTTP ๋ฒ„์ „

๐Ÿ“— header
ํ—ค๋” ์ด๋ฆ„(๋Œ€์†Œ๋ฌธ์ž ๊ตฌ๋ถ„์ด ์—†๋Š” ๋ฌธ์ž์—ด), ์ฝœ๋ก ( : ), ๊ฐ’์„ ์ž…๋ ฅ

-General headers : ๋ฉ”์‹œ์ง€ ์ „์ฒด์— ์ ์šฉ, body์˜ ๋ฐ์ดํ„ฐ์™€๋Š” ๊ด€๋ จ์ด ์—†์Œ
-Request headers : fetch๋กœ ๊ฐ€์ ธ์˜จ ๋ฆฌ์†Œ์Šค๋‚˜ ํด๋ผ์ด์–ธํŠธ ์ž์ฒด์— ๋Œ€ํ•œ ์ •๋ณด
User-Agent, Accept-Type, Accept-Language, Referer, If-None
-Representation headers : Entity headers, body์˜ ๋ฆฌ์†Œ์Šค์˜ ์ •๋ณด(์ฝ˜ํ…์ธ  ๊ธธ์ด, MIME ํƒ€์ž… ๋“ฑ)๋ฅผ ํฌํ•จ

๐Ÿ“— body
GET, HEAD, DELETE, OPTIONS์ฒ˜๋Ÿผ ์„œ๋ฒ„์— ๋ฆฌ์†Œ์Šค๋ฅผ ์š”์ฒญํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” ๋ถˆํ•„์š”

-Single-resource bodies : ๋‹จ์ผ-๋ฆฌ์†Œ์Šค ๋ณธ๋ฌธ, ํ—ค๋” ๋‘ ๊ฐœ(Content-Type๊ณผ Content-Length)๋กœ ์ •์˜๋œ ๋‹จ์ผ ํŒŒ์ผ
-Multiple-resource bodies : ๋‹ค์ค‘-๋ฆฌ์†Œ์Šค ๋ณธ๋ฌธ, ๊ฐ ํŒŒํŠธ๋งˆ๋‹ค ๋‹ค๋ฅธ ์ •๋ณด, HTML form๊ณผ ๊ด€๋ จ๋จ

HTTP Responses

๐Ÿ“— Status line
์„œ๋ฒ„๊ฐ€ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ณด๋‚ด๋Š” ๋ฉ”์‹œ์ง€
ํ˜„์žฌ ํ”„๋กœํ† ์ฝœ์˜ ๋ฒ„์ „, ์ƒํƒœ ์ฝ”๋“œ(์š”์ฒญ์˜ ๊ฒฐ๊ณผ), ์ƒํƒœ ํ…์ŠคํŠธ(์„ค๋ช…)

๐Ÿ“— Headers
-General headers : ๋ฉ”์‹œ์ง€ ์ „์ฒด ์ ์šฉ๋จ. body์˜ ๋ฐ์ดํ„ฐ์™€๋Š” ์ƒ๊ด€ ์—†์Œ
-Response headers : ์œ„์น˜ ๋˜๋Š” ์„œ๋ฒ„ ์ž์ฒด์— ๋Œ€ํ•œ ์ •๋ณด(์ด๋ฆ„, ๋ฒ„์ „ ๋“ฑ)์™€ ๊ฐ™์ด ์‘๋‹ต์— ๋Œ€ํ•œ ๋ถ€๊ฐ€์ ์ธ ์ •๋ณด
-Representation headers : body์— ๋‹ด๊ธด ๋ฆฌ์†Œ์Šค์˜ ์ •๋ณด(์ฝ˜ํ…์ธ  ๊ธธ์ด, MIME ํƒ€์ž… ๋“ฑ)๋ฅผ ํฌํ•จ

๐Ÿ“— Body
201, 204์™€ ๊ฐ™์€ ์ƒํƒœ ์ฝ”๋“œ๋ฅผ ๊ฐ€์ง€๋Š” ์‘๋‹ต์€ ๋ณธ๋ฌธ์ด ํ•„์š” ์—†์Œ

-Single-resource bodies : ๋‹จ์ผ-๋ฆฌ์†Œ์Šค ๋ณธ๋ฌธ, ๊ธธ์ด๋ฅผ ์•Œ ๊ฒฝ์šฐ ๋‘ ๊ฐœ์˜ ํ—ค๋”(Content-Type, Content-Length)๋กœ ์ •์˜, ๊ธธ์ด๋ฅผ ๋ชจ๋ฅผ ๊ฒฝ์šฐ Transfer-Encoding์ด chunked ๋กœ ์„ค์ •๋˜์–ด ์žˆ์œผ๋ฉฐ, ํŒŒ์ผ์€ chunk๋กœ ๋‚˜๋‰˜์–ด ์ธ์ฝ”๋”ฉ
-Multiple-resource bodies : ๋‹ค์ค‘-๋ฆฌ์†Œ์Šค ๋ณธ๋ฌธ, ์„œ๋กœ ๋‹ค๋ฅธ ์ •๋ณด๋ฅผ ๋‹ด์€ body

HTTP ์ƒํƒœ ์ฝ”๋“œ

profile
๊ธฐ๋ณธ์— ์ถฉ์‹คํ•˜๋ฉฐ ์•ž์œผ๋กœ ๋ฐœ์ „ํ•˜๋Š”

0๊ฐœ์˜ ๋Œ“๊ธ€