[๐Ÿฅ ๋„คํŠธ์›Œํฌ] HTTP(HyperText Transfer Protocol, ์ดˆ๋ณธ ์ „์†ก ๊ทœ์•ฝ)

dsfasdยท2022๋…„ 10์›” 4์ผ
0

๋„คํŠธ์›Œํฌ

๋ชฉ๋ก ๋ณด๊ธฐ
2/4

HTTP๋ž€?

HTTP Messages

HTTP Messages๋Š” ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„ ์‚ฌ์ด์—์„œ ๋ฐ์ดํ„ฐ๊ฐ€ ๊ตํ™˜๋˜๋Š” ๋ฐฉ์‹์ด๋‹ค.
W3 ์ƒ์—์„œ ์ •๋ณด๋ฅผ ์ฃผ๊ณ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ํ”„๋กœํ† ์ฝœ์ด๋‹ค. ์ฃผ๋กœ HTML ๋ฌธ์„œ๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” ๋ฐ์— ์“ฐ์ธ๋‹ค.

  • ์š”์ฒญ(Requests) : ํด๋ผ์ด์–ธํŠธ -> ์„œ๋ฒ„์—๊ฒŒ ๋ณด๋‚ด๋Š” ๋ฉ”์‹œ์ง€
  • ์‘๋‹ต(Responses) : ์„œ๋ฒ„-> ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ณด๋‚ด๋Š” ๋ฉ”์‹œ์ง€

๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์ด ์žˆ๋‹ค.

ํŠน์ง• : Stateless(๋ฌด์ƒํƒœ์„ฑ)

HTTP๋Š” ์ƒํƒœ๋ฅผ ๊ฐ–์ง€ ์•Š๋Š”๋‹ค. HTTP๊ฐ€ ์„œ๋กœ ํ†ต์‹ ์„ ํ•˜๋Š” ๊ณผ์ •์—์„œ ํด๋ผ์ด์–ธํŠธ, ์„œ๋ฒ„์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•˜์ง€ ์•Š๋Š”๋‹ค. HTTP๋Š” ํ†ต์‹  ๊ทœ์•ฝ์ผ ๋ฟ์ด๋ฏ€๋กœ ์ƒํƒœ๋ฅผ ์ €์žฅํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
๋”ฐ๋ผ์„œ ์ƒํƒœ๋ฅผ ์ €์žฅํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์ฟ ํ‚ค-์„ธ์…˜, API ๋“ฑ์˜ ๋ฐฉ๋ฒ•์„ ์ด์šฉํ•ด์•ผ ํ•œ๋‹ค.


HTTP ๋ฉ”์‹œ์ง€ ๊ตฌ์กฐ

HTTP ๋ฉ”์‹œ์ง€์˜ ๊ตฌ์กฐ๋ฅผ ์‚ดํŽด๋ณด์ž.
์š”์ฒญ(Requests)๊ณผ ์‘๋‹ต(Responses)์€ ์œ ์‚ฌํ•œ ๊ตฌ์กฐ๋ฅผ ๊ฐ–๋Š”๋‹ค.

  • start line - ์š”์ฒญ/์‘๋‹ต ์ƒํƒœ๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค.
  • HTTP headers - ์š”์ฒญ์„ ์ง€์ •ํ•˜๊ฑฐ๋‚˜, ๋ฉ”์‹œ์ง€์— ํฌํ•จ๋œ ๋ณธ๋ฌธ์„ ์„ค๋ช…ํ•˜๋Š” ํ—ค๋”์˜ ์ง‘ํ•ฉ
  • empty line - ๊ตฌ๋ถ„ ์„ 
  • body - ๋ฐ์ดํ„ฐ๋‚˜ ์‘๋‹ต๊ณผ ๊ด€๋ จํ•œ ๋ฐ์ดํ„ฐ ํ˜น์€ ๋ฌธ์„œ๋ฅผ ํฌํ•จ

๐Ÿ’› HTTP Request(์š”์ฒญ) ๋ฉ”์‹œ์ง€ ๊ตฌ์กฐ

  • ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋ฒ„์—๊ฒŒ ๋ณด๋‚ด๋Š” ๋ฉ”์‹œ์ง€์ด๋‹ค.

(1) startline :

  • HTTP method:
    ์ˆ˜ํ–‰ํ•  ์ž‘์—…(GET, PUT, POST ๋“ฑ)์ด๋‚˜ ๋ฐฉ์‹(HEAD or OPTIONS)์„ ์„ค๋ช…ํ•œ๋‹ค.
  • ์š”์ฒญ ์ปจํ…์ŠคํŠธ:
    ์š”์ฒญ ๋Œ€์ƒ(์ผ๋ฐ˜์ ์œผ๋กœ URL์ด๋‚˜ URI) ๋˜๋Š” ํ”„๋กœํ† ์ฝœ, ํฌํŠธ, ๋„๋ฉ”์ธ์˜ ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋Š” ์š”์ฒญ ์ปจํ…์ŠคํŠธ์— ์ž‘์„ฑํ•œ๋‹ค.( ์ด ์š”์ฒญ ํ˜•์‹์€ HTTP method ๋งˆ๋‹ค ๋‹ค๋ฅด๋‹ค )
  • HTTP ๋ฒ„์ „:
    HTTP ๋ฒ„์ „์— ๋”ฐ๋ผ HTTP message ๊ตฌ์กฐ๊ฐ€ ๋‹ฌ๋ผ์ง€๋ฏ€๋กœ ๋ฒ„์ „์„ ํ•จ๊ป˜ ์ž…๋ ฅํ•œ๋‹ค.

์š”์ฒญ ์ปจํ…์ŠคํŠธ - ๋‹ค์–‘ํ•œ ์š”์ฒญ ํ˜•์‹

origin ํ˜•์‹ :
'?'์™€ ์ฟผ๋ฆฌ ๋ฌธ์ž์—ด์ด ๋ถ™๋Š” ์ ˆ๋Œ€ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค. GET, POST, HEAD, OPTIONS ๋“ฑ์˜ method์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
POST / HTTP 1.1
GET /background.png HTTP/1.0
HEAD /test.html?query=alibaba HTTP/1.1
OPTIONS /anypage.html HTTP/1.0

absolute ํ˜•์‹ :
์™„์ „ํ•œ URL ํ˜•์‹์œผ๋กœ, ํ”„๋ก์‹œ์— ์—ฐ๊ฒฐํ•˜๋Š” ๊ฒฝ์šฐ ๋Œ€๋ถ€๋ถ„ GET method์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
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

(2) headers

[ํ—ค๋” ์ด๋ฆ„ : ๊ฐ’] ์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

ํฌ๊ฒŒ ์„ธ ๊ทธ๋ฃน์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋Š”๋ฐ,

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

(3) empty line - ์ƒ๋žต

(4) Body

-๋ชจ๋“  ์š”์ฒญ์— body๊ฐ€ ํ•„์š”ํ•œ ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค.
GET, HEAD, DELETE, OPTIONS์ฒ˜๋Ÿผ ์„œ๋ฒ„์— ๋ฆฌ์†Œ์Šค๋ฅผ ์š”์ฒญํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” ๋ณธ๋ฌธ์ด ํ•„์š”ํ•˜์ง€ ์•Š๋‹ค.
POST๋‚˜ PUT๊ณผ ๊ฐ™์€ ์ผ๋ถ€ ์š”์ฒญ์€ ๋ฐ์ดํ„ฐ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค.

-body๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‘ ์ข…๋ฅ˜๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋‹ค.

  • Single-resource bodies(๋‹จ์ผ-๋ฆฌ์†Œ์Šค ๋ณธ๋ฌธ) :
    ํ—ค๋” ๋‘ ๊ฐœ(Content-Type๊ณผ Content-Length)๋กœ ์ •์˜๋œ ๋‹จ์ผ ํŒŒ์ผ๋กœ ๊ตฌ์„ฑ

  • Multiple-resource bodies(๋‹ค์ค‘-๋ฆฌ์†Œ์Šค ๋ณธ๋ฌธ) :
    ์—ฌ๋Ÿฌ ํŒŒํŠธ๋กœ ๊ตฌ์„ฑ๋œ ๋ณธ๋ฌธ์—์„œ๋Š” ๊ฐ ํŒŒํŠธ๋งˆ๋‹ค ๋‹ค๋ฅธ ์ •๋ณด๋ฅผ ์ง€๋‹ˆ๋ฉฐ ๋ณดํ†ต HTML form๊ณผ ๊ด€๋ จ์ด ์žˆ๋‹ค.


๐Ÿ’› HTTP Response(์‘๋‹ต) ๋ฉ”์‹œ์ง€ ๊ตฌ์กฐ

-์„œ๋ฒ„๊ฐ€ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ณด๋‚ด๋Š” ๋ฉ”์‹œ์ง€์ด๋‹ค.

(1) startline :

  • ํ˜„์žฌ ํ”„๋กœํ† ์ฝœ์˜ ๋ฒ„์ „(HTTP/1.1)
  • ์ƒํƒœ ์ฝ”๋“œ - ์š”์ฒญ์˜ ๊ฒฐ๊ณผ๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. (ex. 200, 302, 404 ๋“ฑ)
  • ์ƒํƒœ ํ…์ŠคํŠธ - ์ƒํƒœ ์ฝ”๋“œ์— ๋Œ€ํ•œ ์„ค๋ช…

ex . HTTP/1.1 404 Not Found

(2) headers :

์š”์ฒญ ๋ฉ”์‹œ์ง€์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ [ํ—ค๋” ์ด๋ฆ„ : ๊ฐ’] ์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

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

(3) empty line - ์ƒ๋žต

(4) Body

-๋ชจ๋“  ์š”์ฒญ์— body๊ฐ€ ํ•„์š”ํ•œ ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค.
-201, 204์™€ ๊ฐ™์€ ์ƒํƒœ์ฝ”๋“œ๋ฅผ ๊ฐ–๋Š” ์‘๋‹ต์—๋Š” ๋ณธ๋ฌธ์ด ํ•„์š”ํ•˜์ง€ ์•Š๋‹ค.

-body๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‘ ์ข…๋ฅ˜๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋‹ค.

  • Single-resource bodies(๋‹จ์ผ-๋ฆฌ์†Œ์Šค ๋ณธ๋ฌธ) :
    ํ—ค๋” ๋‘ ๊ฐœ(Content-Type๊ณผ Content-Length)๋กœ ์ •์˜๋œ ๋‹จ์ผ ํŒŒ์ผ๋กœ ๊ตฌ์„ฑ

  • Multiple-resource bodies(๋‹ค์ค‘-๋ฆฌ์†Œ์Šค ๋ณธ๋ฌธ) :
    ์—ฌ๋Ÿฌ ํŒŒํŠธ๋กœ ๊ตฌ์„ฑ๋œ ๋ณธ๋ฌธ์—์„œ๋Š” ๊ฐ ํŒŒํŠธ๋งˆ๋‹ค ๋‹ค๋ฅธ ์ •๋ณด๋ฅผ ์ง€๋‹ˆ๋ฉฐ ๋ณดํ†ต HTML form๊ณผ ๊ด€๋ จ์ด ์žˆ๋‹ค.


profile
๊ธฐ๋ก์„ ์ •๋ฆฌํ•˜๋Š” ๊ณต๊ฐ„!

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