Posts ๐Ÿ’ป HTTP #6: HTTP ๋ฉ”์‹œ์ง€
Post
Cancel

๐Ÿ’ป HTTP #6: HTTP ๋ฉ”์‹œ์ง€

HTTP ๋ฉ”์‹œ์ง€

HTTP ๋ฉ”์‹œ์ง€

HTTP ๋ฉ”์‹œ์ง€๋Š” ์„œ๋ฒ„์™€ ํด๋ผ์ด์–ธํŠธ ๊ฐ„์— ๋ฐ์ดํ„ฐ๊ฐ€ ๊ตํ™˜๋˜๋Š” ๋ฐฉ์‹์ด๋‹ค. ๋ฉ”์‹œ์ง€์˜ ํƒ€์ž…์€ ์š”์ฒญ(request)์™€ ์‘๋‹ต(response)๋กœ ๋‚˜๋‰˜์–ด์ง„๋‹ค.

๋ฉ”์‹œ์ง€ ํŠน์ง•

  • ASCII๋กœ ์ธ์ฝ”๋”ฉ๋œ ํ…์ŠคํŠธ ์ •๋ณด์ด๋ฉฐ ์—ฌ๋Ÿฌ ์ค„๋กœ ๋˜์–ด ์žˆ๋‹ค.
  • HTTP ์ดˆ๊ธฐ์™€ HTTP1.1์˜ ๋ฉ”์‹œ์ง€๋Š” ์‚ฌ๋žŒ์ด ์ฝ์„ ์ˆ˜ ์žˆ์—ˆ์ง€๋งŒ, HTTP/2์—์„œ๋Š” ์ตœ์ ํ™”์™€ ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ์œ„ํ•ด HTTP ํ”„๋ ˆ์ž„์œผ๋กœ ๋‚˜๋ˆ„์–ด์กŒ๋‹ค.
  • HTTP ๋ฉ”์‹œ์ง€๋Š” ๊ฐœ๋ฐœ์ž ๋Œ€์‹  ์†Œํ”„ํŠธ์›จ์–ด, ๋ธŒ๋ผ์šฐ์ €, ํ”„๋ก์‹œ ํ˜น์€ ์›น ์„œ๋ฒ„๊ฐ€ ๋Œ€์‹  ์ž‘์„ฑํ•ด์ค€๋‹ค. ํ”„๋ก์‹œ, ์„œ๋ฒ„์˜ ๊ฒฝ์šฐ ์„ค์ • ํŒŒ์ผ์„ ํ†ตํ•ด, ๋ธŒ๋ผ์šฐ์ €์˜ ๊ฒฝ์šฐ API ํ˜น์€ ๋‹ค๋ฅธ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ์ œ๊ณต๋œ๋‹ค.

HTTP/2์˜ binary framing ๋งค์ปค๋‹ˆ์ฆ˜์€ ์‚ฌ์šฉ ์ค‘์ธ API๋‚˜ ์„ค์ • ํŒŒ์ผ์„ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š์•„๋„ ๋˜๋„๋ก ์„ค๊ณ„๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉ์ž๊ฐ€ ์ดํ•ดํ•˜๊ธฐ ์‰ฝ๋‹ค.

HTTP ์š”์ฒญ๊ณผ ์‘๋‹ต์˜ ๊ตฌ์กฐ

HTTPMessageStructure

  • start-line: ์‹คํ–‰๋˜์–ด์•ผ ํ•  ์š”์ฒญ, ์š”์ฒญ ์ˆ˜ํ–‰์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ
  • option: HTTP ํ—ค๋” ์„ธํŠธ: ์š”์ฒญ์— ๋Œ€ํ•œ ์„ค๋ช…, ๋ฉ”์‹œ์ง€ ๋ณธ๋ฌธ์— ๋Œ€ํ•œ ์„ค๋ช…
  • ๋นˆ ์ค„(blank line): ์š”์ฒญ์— ๋Œ€ํ•œ ๋ชจ๋“  ๋ฉ”ํƒ€ ์ •๋ณด๊ฐ€ ์ „์†ก๋˜์—ˆ์Œ์„ ์•Œ๋ฆฐ๋‹ค.
  • ์š”์ฒญ๊ณผ ๊ด€๋ จ๋œ ๋‚ด์šฉ, ์‘๋‹ต๊ณผ ๊ด€๋ จ๋œ ๋ฌธ์„œ ๋“ฑ์ด ์˜ต์…˜์œผ๋กœ ๋“ค์–ด๊ฐ„๋‹ค.
    • ๋ณธ๋ฌธ์˜ ์กด์žฌ ์œ ๋ฌด ๋ฐ ํฌ๊ธฐ๋Š” HTTP ํ—ค๋”์— ๋ช…์‹œ๋œ๋‹ค.

HTTP Request ๊ตฌ์กฐ

start line

  • HTTP ๋ฉ”์„œ๋“œ(GET, POST, PUT, HEAD, OPTIONS)
  • ์š”์ฒญ ํƒ€๊ฒŸ
    • origin ํ˜•์‹
      • ๋์— ?์™€ ๋ฌธ์ž์—ด์ด ๋ถ™๋Š” ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋กœ, ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์ธ ํ˜•์‹์ด๋‹ค.
      • GET, POST, HEAD, OPTIONS ๋ฉ”์„œ๋“œ์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•œ๋‹ค.
    • absolute ํ˜•์‹
      • ์™„์ „ํ•œ URL ํ˜•์‹
      • ํ”„๋ก์‹œ์— ์—ฐ๊ฒฐํ•˜๋Š” ๊ฒฝ์šฐ GET๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉ
    • authority ํ˜•์‹
      • ๋„๋ฉ”์ธ ์ด๋ฆ„ ๋ฐ ์˜ต์…˜ ํฌํŠธ๋กœ ์ด๋ฃจ์–ด์ง„ URL์˜ authority component
      • HTTP ํ„ฐ๋„์„ ๊ตฌ์ถ•ํ•˜๋Š” ๊ฒฝ์šฐ CONNECT์™€ ํ•จ๊ป˜ ์‚ฌ์šฉ
    • asterisk ํ˜•์‹
      • OPTIONS์™€ ํ•จ๊ป˜ *๋กœ ๊ฐ„๋‹จํ•˜๊ฒŒ ์„œ๋ฒ„ ์ „์ฒด๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค
      • OPTIONS * HTTP/1.1
  • HTTP ๋ฒ„์ „

HTTP-message-request-header

  • General Header
    • ๋ฉ”์‹œ์ง€ ์ „์ฒด์— ์ ์šฉ
    • Via
  • Request Header
    • User-Agent, Accept-Type๊ณผ ๊ฐ™์€ ํ—ค๋”๋Š” ์š”์ฒญ์˜ ๋‚ด์šฉ์„ ์ข€ ๋” ๊ตฌ์ฒดํ™”์‹œํ‚ค๊ณ (Accept-Language), ์ปจํ…์ŠคํŠธ๋ฅผ ์ œ๊ณตํ•˜๊ธฐ๋„ ํ•˜๋ฉฐ (Referer), ์กฐ๊ฑด์— ๋”ฐ๋ฅธ ์ œ์•ฝ ์‚ฌํ•ญ์„ ๊ฐ€ํ•˜๊ธฐ๋„ ํ•˜๋ฉด์„œ(If-None) ์š”์ฒญ ๋‚ด์šฉ์„ ์ˆ˜์ •
  • Entity Header
    • Content-Length์™€ ๊ฐ™์€ ํ—ค๋”๋Š” ์š”์ฒญ ๋ณธ๋ฌธ์— ์ ์šฉ๋œ๋‹ค.

Body

๋ณธ๋ฌธ(Body)๋Š” ์žˆ์„ ์ˆ˜๋„ ์žˆ๊ณ , ์—†์„ ์ˆ˜๋„ ์žˆ๋‹ค. ๋ฆฌ์†Œ์Šค๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์š”์ฒญ์€ ๋ณธ๋ฌธ์ด ํ•„์š” ์—†์ง€๋งŒ POST์ฒ˜๋Ÿผ ์„œ๋ฒ„์— ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ•˜๋Š” ์š”์ฒญ์€ ๋ณธ๋ฌธ์ด ์žˆ๋‹ค.

  • ๋‹จ์ผ-๋ฆฌ์†Œ์Šค ๋ณธ๋ฌธ(single-resource bodies)
  • ๋‹ค์ค‘-๋ฆฌ์†Œ์Šค ๋ณธ๋ฌธ(multiple-resource bodies)

HTTP ์‘๋‹ต

status line

  • ์˜ˆ) HTTP/1.1 404 Not Found

  • ํ”„๋กœํ† ์ฝœ ๋ฒ„์ „, ์ƒํƒœ ์ฝ”๋“œ, ์ƒํƒœ ํ…์ŠคํŠธ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

Header

HTTP-message-response-header

์‘๋‹ต ๋ฉ”์‹œ์ง€ ํ—ค๋”์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ข…๋ฅ˜๊ฐ€ General Header, Response Header, Entity Header๋กœ ๋‚˜๋‰˜์–ด์ง„๋‹ค.

Body

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

  • ๊ธธ์ด๋ฅผ ์•„๋Š” ๋‹จ์ผ-๋ฆฌ์†Œ์Šค ๋ณธ๋ฌธ(single-resource bodies)
  • ๊ธธ์ด๋ฅผ ๋ชจ๋ฅด๋Š” ๋‹จ์ผ-๋ฆฌ์†Œ์Šค ๋ณธ๋ฌธ
    • Transfer-Encoding์ด chunked๋กœ ์„ค์ •๋˜์–ด ์žˆ์œผ๋ฉท, ํŒŒ์ผ์€ ์ฒญํฌ๋กœ ๋‚˜๋‰˜์–ด ์ธ์ฝ”๋”ฉ๋˜์–ด ์žˆ๋‹ค.
  • ๋‹ค์ค‘-๋ฆฌ์†Œ์Šค ๋ณธ๋ฌธ(multiple-resource bodies)

HTTP/2 ํ”„๋ ˆ์ž„

HTTP/1.x ๋ฉ”์‹œ์ง€์˜ ์„ฑ๋Šฅ์ƒ์˜ ๊ฒฐํ•จ

  • ๋ณธ๋ฌธ๊ณผ ๋‹ฌ๋ฆฌ header๋Š” ์••์ถ•์ด ๋˜์ง€ ์•Š๋Š”๋‹ค.
  • ์—ฐ์†๋œ ๋ฉ”์‹œ์ง€๋Š” ๋น„์Šทํ•œ header ๊ตฌ์กฐ๋ฅผ ๋„์ง€๋งŒ, ๋ฉ”์‹œ์ง€๋งˆ๋‹ค ๋ฐ˜๋ณต๋˜์–ด ์ „์†ก๋œ๋‹ค.
  • ๋‹ค์ค‘ ์ „์†ก(multiplexing)์ด ๋ถˆ๊ฐ€๋Šฅ
    • ๋น„ํšจ์œจ์ ์ธ codl TCP ์—ฐ๊ฒฐ ์‚ฌ์šฉ: ์„œ๋ฒ„ ํ•˜๋‚˜์— ์—ฐ๊ฒฐ์„ ์—ฌ๋Ÿฌ ๊ฐœ ์—ด์–ด์•ผ ํ•œ๋‹ค.

HTTP/2

http2BinaryFraming

  • HTTP/1.x ๋ฉ”์‹œ์ง€๋ฅผ ํ”„๋ ˆ์ž„์œผ๋กœ ๋‚˜๋ˆ„์–ด ์ŠคํŠธ๋ฆผ์— ๋ผ์›Œ ๋„ฃ๋Š”๋‹ค.

  • ๋ฐ์ดํ„ฐ์™€ ํ—ค๋” ํ”„๋ ˆ์ž„์ด ๋ถ„๋ฆฌ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ํ—ค๋”๋ฅผ ์••์ถ•ํ•  ์ˆ˜ ์žˆ๋‹ค.

  • ์ŠคํŠธ๋ฆผ ์—ฌ๋Ÿฌ๊ฐœ๋ฅผ ํ•˜๋‚˜๋กœ ๋ฌถ์„ ์ˆ˜ ์žˆ์–ด์„œ ๊ธฐ์ €์— ์ˆ˜ํ–‰๋˜๋Š” TCP ์—ฐ๊ฒฐ์ด ์ข€ ๋” ํšจ์œจ์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง„๋‹ค.

์ถœ์ฒ˜

https://developer.mozilla.org/ko/docs/Web/HTTP/Messages

This post is licensed under CC BY 4.0 by the author.

[JS] ์ฝ”์–ด ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ #1.1: ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ž€?

ํ•™์› #46์ผ์ฐจ: ๋ฏธ๋‹ˆ ํ”„๋กœ์ ํŠธ์™€ ํŒŒ์ผ ์ž…์ถœ๋ ฅ API: ๋ฐ”์ดํŠธ ์ŠคํŠธ๋ฆผ, ์ œ๋„ค๋ฆญ ๋ฉ”์„œ๋“œ

Loading comments from Disqus ...