๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“– Protocol

HTTP Chunked Message๋ฅผ ์•Œ์•„๋ณด์ž

# if 0

๋‘๋‹ฌ๊ฐ„์˜ ๋…ธ์˜ˆ ์ผ์ƒ์„ ์ด์ œ์•ผ ๋๋‚˜๊ณ ,,

๋„ˆ๋ฌด ์˜ค๋žœ๋งŒ์— ๋“ค์—ฌ๋‹ค๋ณธ ๋ธ”๋กœ๊ทธ,, 

๊ฐœ๋ฐœ์ž๋กœ ์ง€๋‚ด๊ณ  ์žˆ์ง€๋งŒ,, ์ผํ•˜๊ณ  ์‹ถ์ง€๋Š” ์•Š์€ ๊ทธ๋Ÿฐ ์‚ถ,,

 

๊ฐ‘์ž‘์Šค๋Ÿฝ๊ฒŒ HTTP ํ”„๋กœํ† ์ฝœ์„ ๊ตฌํ˜„ํ•ด์•ผํ•  ์ผ์ด ์ƒ๊ฒจ์„œ,

๊ทœ๊ฒฉ ์ฐธ๊ณ ํ•˜๊ณ  ๊ตฌ๊ธ€๋ง ํ•˜๋ฉฐ ๊ณต๋ถ€ํ•œ ์ฃผ์ œ๋กœ ์˜ค๋Š˜์€,, ํ•ด๋ณผ๊นŒ ํ•ฉ๋‹ˆ๋‹ค,,

#endif


HTTP ๋ผ๋Š” ๋‹จ์–ด๋Š” ๋งŽ์ด ๋“ค์–ด๋ณด์…จ์„๊ฑฐ๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค 

๊ทธ ์ค‘์—์„œ, Chunked ๋ผ๋Š” ๋‹จ์–ด๋Š” ์กฐ๊ธˆ ์ƒ์†Œํ•  ์ˆ˜๋„ ์žˆ๋Š”๋ฐ

๊ทœ๊ฒฉ๋Œ€๋กœ๋งŒ ์ƒ๊ฐํ•œ๋‹ค๋ฉด ๊ทธ๋ฆฌ ์–ด๋ ต์ง€ ์•Š์€ (๊ตฌํ˜„์€ ๊นŒ๋‹ค๋กœ์šธ ๊ฒ๋‹ˆ๋‹ค..)

HTTP Chunked Message๋ฅผ ์•Œ์•„๋ณด๋„๋ก ํ• ๊ฒ๋‹ˆ๋‹ค,,

 

- ์•„์ฃผ์•„์ฃผ ๊ฐ„๋‹จํ•œ HTTP Protocol ์„ค๋ช…

- HTTP Header์™€ Body๋ฅผ ์ฝ๋Š” ๋ฐฉ๋ฒ•

- HTTP Chunked Message๋ž€ ๋ฌด์—‡์ธ๊ฐ€


1. HTTP(HyperText Transfer Protocol) Protocol 

Chunked Message(์ฒญํฌ ๋ฉ”์‹œ์ง€ใ…‹)๋ฅผ ์•Œ์•„๋ณด๊ธฐ ์ „์—, ๊ธฐ๋ณธ ๊ฐœ๋…์ธ HTTP๋ฅผ ๋‹ค๋ค„๋ณด๋ ค๊ณ  ํ•œ๋‹ค

์ธํ„ฐ๋„ท ์ฐฝ์„ ํ‚ค๊ณ , ์–ด๋–ค ์‚ฌ์ดํŠธ์— ๋“ค์–ด๊ฐˆ ๋•Œ ํ”ํžˆ ๋ณผ ์ˆ˜ ์žˆ๋Š” ํ˜•์‹์ด ์žˆ๋‹ค

 

์˜ˆ์‹œ) http://www.mutpp.tistory.com 

 

์—ฌ๊ธฐ์„œ ์‚ฌ์šฉํ•˜๋Š” http๊ฐ€ ๊ทธ HTTP ๋งž์Šต๋‹ˆ๋‹ค....

์•ฝ์ž๋ฅผ ํ’€์–ด๋ณด๋ฉด, HyperText๋ผ๋Š” ๊ฒƒ์„ ์ „์†กํ•˜๋Š” ํ”„๋กœํ† ์ฝœ์ธ๋ฐ,

Hyper Text๋Š”

 

๊ทธ๋ƒฅ Text๋ผ๊ณ ๋งŒ ์ดํ•ดํ•˜๊ณ  ๋„˜์–ด๊ฐ€์ž,, 

์‰ฝ๊ฒŒ ์ƒ๊ฐํ•˜๋ฉด, ํ…์ŠคํŠธ๋ฅผ ์ „์†กํ•˜๊ธฐ ์œ„ํ•œ ํ”„๋กœํ† ์ฝœ์ด๋‹ค~ ์ด๋ง์ด๋‹ค

 

์œ„ํ‚ค๋ฐฑ๊ณผ๋ฅผ ์ฐธ๊ณ ํ•˜๋ฉด, (ํ•œ๋ฒˆ ๋‹ค ์ฝ์–ด๋ณด๋Š”๊ฑธ ์ถ”์ฒœ)

์œ„ํ‚ค๋ฐฑ๊ณผ: HTTP(HyperText Transfer Protocol, ๋ฌธํ™”์–ด: ์ดˆ๋ณธ๋ฌธ์ „์†ก๊ทœ์•ฝ, ํ•˜์ดํผ๋ณธ๋ฌธ์ „์†ก๊ทœ์•ฝ)๋Š” W3 ์ƒ์—์„œ ์ •๋ณด๋ฅผ ์ฃผ๊ณ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ํ”„๋กœํ† ์ฝœ์ด๋‹ค. ์ฃผ๋กœ HTML ๋ฌธ์„œ๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” ๋ฐ์— ์“ฐ์ธ๋‹ค. ์ฃผ๋กœ TCP๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  HTTP/3 ๋ถ€ํ„ฐ๋Š” UDP๋ฅผ ์‚ฌ์šฉํ•˜๋ฉฐ, 80๋ฒˆ ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. 1996๋…„ ๋ฒ„์ „ 1.0, ๊ทธ๋ฆฌ๊ณ  1999๋…„ 1.1์ด ๊ฐ๊ฐ ๋ฐœํ‘œ๋˜์—ˆ๋‹ค.
HTTP๋Š” ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„ ์‚ฌ์ด์— ์ด๋ฃจ์–ด์ง€๋Š” ์š”์ฒญ/์‘๋‹ต(request/response) ํ”„๋กœํ† ์ฝœ์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด, ํด๋ผ์ด์–ธํŠธ์ธ ์›น ๋ธŒ๋ผ์šฐ์ €๊ฐ€ HTTP๋ฅผ ํ†ตํ•˜์—ฌ ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ์›นํŽ˜์ด์ง€(HTML)๋‚˜ ๊ทธ๋ฆผ ์ •๋ณด๋ฅผ ์š”์ฒญํ•˜๋ฉด, ์„œ๋ฒ„๋Š” ์ด ์š”์ฒญ์— ์‘๋‹ตํ•˜์—ฌ ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ํ•ด๋‹น ์‚ฌ์šฉ์ž์—๊ฒŒ ์ „๋‹ฌํ•˜๊ฒŒ ๋œ๋‹ค. ์ด ์ •๋ณด๊ฐ€ ๋ชจ๋‹ˆํ„ฐ์™€ ๊ฐ™์€ ์ถœ๋ ฅ ์žฅ์น˜๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ์ž์—๊ฒŒ ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒƒ์ด๋‹ค.
HTTP๋ฅผ ํ†ตํ•ด ์ „๋‹ฌ๋˜๋Š” ์ž๋ฃŒ๋Š” http:๋กœ ์‹œ์ž‘ํ•˜๋Š” URL(์ธํ„ฐ๋„ท ์ฃผ์†Œ)๋กœ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์œ„ํ‚ค๋ฐฑ๊ณผ๋ฅผ ์กฐ๊ธˆ๋งŒ ์ •๋ฆฌํ•ด๋ณด์ž๋ฉด,

- W3 (ํ”ํžˆ ์“ฐ๋Š” WWW) ์ƒ์—์„œ ์ •๋ณด๋ฅผ ์ฃผ๊ณ  ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ํ”„๋กœํ† ์ฝœ

   → ์ธํ„ฐ๋„ท์—์„œ ์šฐ๋ฆฌ๊ฐ€ ๋ณด๊ณ  ์žˆ๋Š”! ์ •๋ณด๋ฅผ ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ๊ณ 

- TCP ๋˜๋Š” UDP ์‚ฌ์šฉ, HTTP ํฌํŠธ๋Š” 80๋ฒˆ ํฌํŠธ ์‚ฌ์šฉ

- HTTP ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด๋Š” Server์™€ Client๊ฐ€ ์žˆ์Œ

- http:๋กœ ์‹œ์ž‘ํ•˜๋Š” ์ธํ„ฐ๋„ท ์ฃผ์†Œ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Œ

 

์—ฌ๊ธฐ๊นŒ์ง€๋งŒ ์•Œ๊ณ  ๋„˜์–ด๊ฐ€๋ฉด ์ฒญํฌ ๋ฉ”์‹œ์ง€๋„ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋‹ค

์›๋ž˜ ๊ทœ๊ฒฉ์ด๋‚˜ ํ”„๋กœํ† ์ฝœ์€ ์•„ ๊ทธ๋Ÿฐ๊ฒŒ ์žˆ๊ตฌ๋‚˜~ ๋ผ๊ณ  ๋ฐฐ๊ฒฝ์ง€์‹๋งŒ ๊ฐ€์ ธ๋„ 

์ด๋ฏธ ๋ฐ˜์€ ์ฝ์€๊ฑฐ๋‚˜ ๋‹ค๋ฆ„ ์—†๋‹ค ใ…‹

๋” ์ž์„ธํ•œ ๋‚ด์šฉ์€ RFC ๊ทœ๊ฒฉ์„ ์ฐธ๊ณ ํ•˜๋Š”๊ฒŒ ์ข‹๋‹ค (์ฒจ๋ถ€๋งํฌ ์ฐธ๊ณ )

 

2. HTTP Header์™€ Body๋ฅผ ์ฝ๋Š” ๋ฐฉ๋ฒ•

(1) ์™œ Header์™€ Body๋ฅผ ์‚ฌ์šฉํ• ๊นŒ?

HTTP ํ—ค๋”(header)์™€ ๋ฐ”๋””(body)๋ž€ ๊ทธ๋ ‡๋‹ค๋ฉด ๋ฌด์—‡์ธ๊ฐ€...

๋ง ๊ทธ๋Œ€๋กœ ๋จธ๋ฆฌ์™€ ๋ชธ์œผ๋กœ ๋ถ„๋ฆฌ ๋˜์–ด ์žˆ๋Š” ๊ตฌ์กฐ๋ฅผ ์˜๋ฏธํ•˜๋Š”๋ฐ,

์„œ๋ฒ„์™€ ํด๋ผ์ด์–ธํŠธ์˜ HTTP ํ†ต์‹  ๋ฉ”์‹œ์ง€๋ฅผ ์˜ˆ๋ฅผ ๋“ค์–ด๋ณด์ž๋ฉด,

 

HTTP ํ†ต์‹  ์˜ˆ์‹œ(์ด๋ ‡๊ฒŒ ๊น”๋”ํ•  ์ˆ˜๊ฐ€)

์œ„ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์€๋ฐ, ์ž์„ธํžˆ๋ณด๋ฉด ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„์˜ ๋ฉ”์‹œ์ง€ ํ˜•์‹์ด ์กฐ๊ธˆ ๋‹ค๋ฅธ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค

ํ•˜์ง€๋งŒ! ํ—ค๋”์™€ ๋ฐ”๋””์˜ ๊ตฌ์„ฑ์œผ๋กœ ๋˜์–ด์žˆ๋Š”๊ฑด ๋™์ผํ•˜๋‹ค

 

๊ทผ๋ฐ ๊ทธ๋ƒฅ ํ—ค๋”๋ž‘ ๋ฐ”๋”” ๋‚˜๋ˆŒ ํ•„์š” ์—†์ด ํ•œ๋ฒˆ์— ๋ณด๋‚ด๋ฉด ์•ˆ๋˜๋‚˜..?;;;; ๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค ์ˆ˜ ์žˆ๋Š”๋ฐ

์™œ ๊ตฌ๋ถ„ํ• ๊นŒ๋ฅผ TCP ์†Œ์ผ“ ํ†ต์‹ ์„ ์˜ˆ๋กœ ๋“ค์–ด์„œ ์„ค๋ช…ํ•˜์ž๋ฉด, ( ์ง€๊ทนํžˆ ๋‚˜์˜ ์ƒ๊ฐ์ด๋‹ค )

 

TCP ํ†ต์‹  Flow

์œ„ ๊ทธ๋ฆผ์€ ์•„๋งˆ ์–ด๋””์„œ ํ•œ๋ฒˆ์ฏค์€ ๋ดค์„ ๋ฒ•ํ•œ ๊ทธ๋ฆผ์ด๋‹ค

TCP ํ†ต์‹ ์‹œ์— ์‹ค์ œ ์šด์˜์ฒด์ œ๋ฅผ ํ†ตํ•ด ๋ฉ”์‹œ์ง€๋ฅผ ์ „์†กํ•  ๋•Œ, send() ( ๋˜๋Š” write() )๋ฅผ ํ†ตํ•ด ๋ณด๋‚ด๊ณ ,

recv() ( ๋˜๋Š” read() )๋ฅผ ํ†ตํ•ด ๋ฉ”์‹œ์ง€๋ฅผ ์ˆ˜์‹ ํ•˜๋Š”๋ฐ,

์ด ๋•Œ ๋ณด๋‚ผ/๋ฐ›์„ ๋ฉ”์‹œ์ง€์˜ ํฌ๊ธฐ๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„ฃ์–ด์ฃผ๊ฒŒ ๋˜์–ด ์žˆ๋‹ค

๋‚ด๊ฐ€ ๋ณด๋‚ผ ๋•Œ 8192๋งŒํผ ๋ณด๋‚ผ๋ž˜~~ ํ•ด๋„ ๋ฐ›๋Š” ์ชฝ์—์„œ๋Š” 9000๋งŒํผ, 2000๋งŒํผ ์ฝ์„ ์ˆ˜ ์žˆ๋‹ค

์ƒ๋Œ€๋ฐฉ์ด ์–ผ๋งŒํผ ๋ณด๋‚ด๊ณ  ๋ฐ›์„์ง€ ๋ชจ๋ฅธ๋‹ค๋Š” ์–˜๊ธฐ

 

ํฌ๊ธฐ๊ฐ€ ํฐ (ex. ๋™์˜์ƒ/์›นํŽ˜์ด์ง€ ๋“ฑ๋“ฑ) ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ผ ๋•Œ, ํ•œ๋ฒˆ์— ๋ฐ›์„ ์ˆ˜ ์—†์„ ์ˆ˜๋„ ์žˆ์„ํ…Œ๊ณ 

์–ผ๋งŒํผ ์ฝ์–ด์•ผํ•˜๋Š”์ง€๋„ ๋ชจ๋ฅธ๋‹ค! ๋ผ๋Š” ๊ฒƒ์ด๋‹ค

๊ทธ๋ž˜์„œ ํ—ค๋”์— ๋‚ด๊ฐ€ ๋ณด๋‚ผ ๋ฉ”์‹œ์ง€(๋ฐ”๋””)์˜ ํฌ๊ธฐ๋Š” ์ด๋งŒํผ์ด์•ผ~๋ฅผ ๋จผ์ € ์•Œ๋ ค์ฃผ๊ณ  (Content-Length)

๊ทธ ํ›„์— ๋ณด๋‚ผ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๋‚ด๋Š” ์šฉ๋„๋กœ ์‚ฌ์šฉ๋œ๋‹ค (๋จธ๋ฆฌ๋ถ€ํ„ฐ ๋“ค์ด๋ฏผ๋‹ค)

 

 

(2) Request ๋ฉ”์‹œ์ง€ 

 

* Request ๋ฉ”์‹œ์ง€ ํ˜•์‹

{HEADER} CRLF
CRLF
{BODY}

์œ„์—์„œ ์„ค๋ช…ํ•œ ํ—ค๋”์™€ Body๋Š” CRLF CRLF ๋ผ๋Š” ๊ฒƒ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด์žˆ๋‹ค

 

cf) CRLF ์˜๋ฏธ (์ƒˆ์ค„ ๋ฌธ์ž)

- CR: Carriage Return (\r)

- LF: Line Feed (\n)

HTTP ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋ฉด ๋์— ๊ณต๋ฐฑ์œผ๋กœ ๋ณด์ด๋Š” ๋ถ€๋ถ„์ด ์žˆ์„ ๊ฒƒ์ด๋‹ค ๋ฐ”๋กœ ๊ทธ๊ฒƒ์ด๋‹ค

 

ํ—ค๋”๋งŒ ์ข€๋” ์ž์„ธํžˆ ๋œฏ์–ด๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค

 

* Request ๋ฉ”์‹œ์ง€ - Header ๊ตฌ์„ฑ

/* Header ๊ตฌ์„ฑ์ž„ */
1. {METHOD ์ด๋ฆ„} SP {์š”์ฒญํ•˜๋Š” URI} SP {HTTP Version} CRLF
2. {Header 1๋ฒˆ์งธ} CRLF
N. {Header N๋ฒˆ์งธ} CRLF
CRLF
/* ~ Header ๊ตฌ์„ฑ์ž„ */
1. {BODY}

cf) SP ์˜๋ฏธ

SP: Space (" ")  ๋„์–ด์“ฐ๊ธฐ์ž„ใ…‹

 

cf) Request Line

1๋ฒˆ์งธ ์ค„์— ์žˆ๋Š” → method + " " + ์š”์ฒญํ•˜๋Š” URI + " " + HTTP ํ”„๋กœํ† ์ฝœ ๋ฒ„์ „ 

์š” ๊ตฌ์„ฑ์„ Request Line์ด๋ผ๊ณ  ํ•œ๋‹ค

 

HTTP ๋ฉ”์‹œ์ง€๋Š” ์˜ˆ์‹œ๋ฅผ ๋ณด๋ฉด ์ดํ•ด๊ฐ€ ์ž˜ ๋  ๊ฒƒ์ด๋‹ค

 

์„ธ์ƒ์—๋Š” ์ข‹์€ ์ž๋ฃŒ๊ฐ€ ์ฐธ ๋งŽ๋‹ค

( ์‚ฌ์‹ค Method์˜ ์ข…๋ฅ˜์—๋Š” ๋ญ๊ฐ€ ์žˆ๋Š”์ง€ (ex. POST, GET ๋“ฑ๋“ฑ), VESION์€ ๋ญ”์ง€ 

ํ—ค๋”์—๋Š” ์–ด๋–ค ์ข…๋ฅ˜๊ฐ€ ์žˆ๊ณ , ํ•„์ˆ˜๋กœ ๋“ค์–ด๊ฐ€์•ผํ•˜๋Š” ํ•ญ๋ชฉ (ex. Content-Length)  ๋“ฑ๋“ฑ์— ๋Œ€ํ•ด

HTTP์—์„œ๋Š” ์–˜๊ธฐํ• ๊ฒŒ ๋„ˆ~~~~๋ฌด ๋งŽ์œผ๋‹ˆ ์ƒ๋žตํ•œ๋‹ค.)

 

 

(3) Response ๋ฉ”์‹œ์ง€

 

* Response ๋ฉ”์‹œ์ง€ ํ˜•์‹

1. {HTTP ๋ฒ„์ „} SP {Status Code} SP {Status Message} CRLF
2. {Header 1๋ฒˆ์งธ} CRLF
N. {Header N๋ฒˆ์งธ} CRLF
CRLF
1. {Body ์žˆ๊ฑฐ๋‚˜ ์—†๊ฑฐ๋‚˜}

 

cf) Status Line

Request์˜ ์ฒซ๋ฒˆ์งธ ์ค„์— ์žˆ๋Š” Request Line์ด ์žˆ๋“ฏ์ด,

Response์˜ ์ฒซ๋ฒˆ์งธ ์ค„์€ Status Line์ด๋ผ๊ณ  ํ•œ๋‹ค

 

Response๋„ ์˜ˆ์‹œ๋ฅผ ๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค

Response ๋ฉ”์‹œ์ง€

Response๋ฅผ ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ์ˆ˜์‹ ํ•˜๋ฉด, Status Line์— ์žˆ๋Š” ์ƒํƒœ ๊ฐ’๊ณผ ์—๋Ÿฌ ์ฝ”๋“œ๋ฅผ ๋ณด๊ณ 

์ดํ›„ ๋กœ์ง์„ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค

(200 OK ์ด๋ฉด ์ž˜ ์ฒ˜๋ฆฌํ–ˆ๋‹ค๊ณ  ๋กœ๊ทธ๋ฅผ ๋‚จ๊ธด๋‹ค๋˜๊ฐ€,, 401 ์—๋Ÿฌ๋ฉด Digest ์ธ์ฆ ํ—ค๋”๋ฅผ ๋ถ™์—ฌ์„œ ๋‹ค์‹œ ๋ณด๋‚ธ๋‹ค๋˜๊ฐ€)

 

์„ธ์ƒ์— ์žˆ๋Š” HTTP error ์ฝ”๋“œ๋Š” ๊ทœ๊ฒฉ์— ์ •์˜๊ฐ€ ๋˜์–ด์žˆ์œผ๋‹ˆ, ๊ฑฑ์ •์•ˆํ•ด๋„ ๋œ๋‹ค

(์ฒจ๋ถ€ํŒŒ์ผ ์ฐธ๊ณ )

3. HTTP Chunked Message

ํฌ์ŠคํŒ… ์ฃผ์ œ์˜€๋Š”๋ฐ ์ด์ œ์•ผ ๋“ฑ์žฅํ•œ Chunked ๋ฉ”์‹œ์ง€..

 

์˜ˆ์“ฐ,,๋ฉ์–ด๋ฆฌ....

chunk๋ผ๋Š” ๋‹จ์–ด ์ž์ฒด์˜ ๋œป์€ "๋ฉ์–ด๋ฆฌ"๋ฅผ ๋œปํ•œ๋‹ค

HTTP Body๋กœ ์˜ค๋Š” ๋ฉ”์‹œ์ง€๋“ค์ด ๋ฉ์–ด๋ฆฌ๋œ ํ˜•ํƒœ๋กœ ์˜ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค

 

Body์— ์žˆ๋Š” ๋ฉ”์‹œ์ง€๊ฐ€ ์ง€์†์ ์œผ๋กœ ์™€์•ผํ•˜๋Š” ๊ฒฝ์šฐ๋‚˜ (ex. ์„ธ์…˜์„ ์œ ์ง€ํ•ด์•ผ ํ•  ๊ฒฝ์šฐ)

๋ฉ”์‹œ์ง€์˜ ํฌ๊ธฐ๊ฐ€ ๋งŽ์ด ํด ๊ฒฝ์šฐ์— ๋ณดํ†ต ์‚ฌ์šฉ๋œ๋‹ค๊ณ  ํ•œ๋‹ค

 

๋ฉ”์‹œ์ง€๊ฐ€ ํฌ๋ฉด ํด ์ˆ˜๋ก ํ•œ๋ฒˆ์— ๋ณด๋‚ด๊ธฐ์— ๋ถ€๋‹ด์Šค๋Ÿฌ์šธ ๊ฒƒ์ด๊ธฐ์—..

๋ถ„ํ• ํ•˜์—ฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด๋Š” ๊ฒƒ์ด๋‹ค

๊ทธ๋Ÿฌ๋ฉด ์–ด๋–ป๊ฒŒ! ๋‚˜๋ˆ ์„œ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด๊ณ  ๋ฐ›์„ ์ˆ˜ ์žˆ์„๊นŒ.

 

(1) Chunked Body ๋ฉ”์‹œ์ง€ ํ˜•์‹

 

์ฒญํฌ ๋ฉ”์‹œ์ง€๋Š” Header๋Š” ๋˜‘๊ฐ™์ด ์˜ค๊ณ , Body๊ฐ€ ๋‚˜๋ˆ ์ ธ์„œ ์˜ค๋Š” ๋ฉ”์‹œ์ง€์ธ๋ฐ

์ฐจ์ด์ ์€?

 

- ์ผ๋ฐ˜ Body ๋ฉ”์‹œ์ง€ ๊ธธ์ด: Header์— ์žˆ๋Š” Content-Length ํ—ค๋”์— ์ ํ˜€์žˆ์Œ

- ์ฒญํฌ Body ๋ฉ”์‹œ์ง€ ๊ธธ์ด: ๊ฐ ์ฒญํฌ๋งˆ๋‹ค ๊ธธ์ด๊ฐ€ ์ ํ˜€์žˆ์Œ

 

Boby์˜ ๊ธธ์ด๋ฅผ ์•Œ๋ ค์ฃผ๊ธฐ ์œ„ํ•ด, Content-Length๋ผ๋Š” ํ—ค๋”์— ๊ทธ ๊ฐ’์ด ์žˆ๋Š”๋ฐ,

์ฒญํฌ ๋ฉ”์‹œ์ง€๋Š” ๋ถ„ํ• ๋ผ์„œ ์˜ค๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ ๋ฉ์–ด๋ฆฌ(ใ…‹)๋งˆ๋‹ค ๊ธธ์ด๋ฅผ ํ‘œ๊ธฐ๋ฅผ ํ•ด์ค€๋‹ค

 

์•„๋ž˜๋Š” ์˜ˆ์‹œ์ด๋‹ค

 

์งœ์ž” (์ถœ์ฒ˜๋Š” ์ด๋ฏธ์ง€ ํด๋ฆญ)

์ƒ๊ฐ๋ณด๋‹ค ๊ฐ„๋‹จํ•˜์ฅฌ?

Chunk #1๋งŒ ๋ณด๋ฉด

Chunk #1 ์˜ˆ์‹œ (์ถœ์ฒ˜๋Š” ์ด๋ฏธ์ง€ ํด๋ฆญ)

"27 <CR><LF>"๋ฅผ ์ž์„ธํžˆ ๋ณด์ž.

์œ„์—์„œ ํ—ค๋”์™€ ๋ฐ”๋””๋ฅผ ๋ณด์•˜์„ ๋•Œ ๋‘ ๋ฒˆ์˜ CRLF๋กœ ๊ตฌ๋ถ„๋œ๋‹ค๋ผ๊ณ  ์„ค๋ช…ํ•˜์˜€๋Š”๋ฐ,

์ฒญํฌ ๋ฉ”์‹œ์ง€๋„ CRLF๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฒญํฌ ํ—ค๋”์™€ ์ฒญํฌ ๋ฐ”๋””๋ฅผ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ๋‹ค!

 

๊ทธ๋ฆฌ๊ณ , We hole these... ์–ด์ฉŒ๊ตฌ์— ์žˆ๋Š” ์ฒญํฌ ๋ฐ”๋””์˜ ๊ธ€์ž๋ฅผ ์„ธ์–ด๋ณด๋ฉด 27์ด ์•„๋‹ˆ์–ด์„œ ๋‹นํ™ฉํ• ํ…๋ฐ,

์ด์œ ๋Š” hex๋กœ ํ‘œ๊ธฐ ๋˜์–ด์„œ ๊ทธ๋Ÿฐ๊ฑฐ๋‹ˆ๊นŒ ๋‹นํ™ฉํ•˜์ง€ ๋ง์ž

(string ํ˜•์˜ hex ๋ฌธ์ž๋ฅผ intํ˜•์œผ๋กœ ๋ฐ”๊พธ๋Š” ๊ฒƒ์€ ์ฐธ๊ณ  ์ž๋ฃŒ์— ๋‹ฌ์•„๋†“๊ฒ ์Œ)

 

๋˜ํ•œ, ์ฒญํฌ ๋ฐ”๋”” ๊ธธ์ด๋Š” CRLF์˜ ๊ธธ์ด๋Š” ์ œ์™ธํ•œ ๊ธธ์ด๋‹ค..

 

๊ทธ๋ฆฌ๊ณ , Body ๋ถ€๋ถ„์— ๋ณด์ด๋Š” 

 

Transfer-encoding

 Transfer-encoding ํ—ค๋”๋Š” ์ด์ œ Chunked๋กœ ๋œ ๋ฉ”์‹œ์ง€๊ฐ€ ์˜ฌ๊ฑฐ์•ผ ~~ ๋ฅผ ์•Œ๋ ค์ฃผ๋Š” ํ—ค๋”๋กœ,

์ฒญํฌ ๋ฉ”์‹œ์ง€๊ฐ€ ์˜ค๊ธฐ ์ „์— ๋ณผ ์ˆ˜ ์žˆ๋‹ค

 

๊ทธ๋Ÿฌ๋ฉด ๋งˆ์ง€๋ง‰์œผ๋กœ ์˜ค๋Š” Chunk ๋ฉ”์‹œ์ง€๊ฐ€ ์–ธ์  ๊ฐ€๋Š” ์˜ฌํ…๋ฐ, (์•ˆ์˜ฌ ์ˆ˜๋„ ์žˆ๊ณ ^^7)

 

Last message

๋งˆ์ง€๋ง‰ ๋ฉ”์‹œ์ง€๋Š” 0 ์ž„์„ ํ‘œ์‹œํ•˜๊ณ  ์˜จ๋‹ค.

 

 

(2) Multipart Type๊ณผ Boundary Header

 

์•ž์„œ ์„ค๋ช…ํ–ˆ๋˜ HTTP ํ—ค๋”์—๋Š” ๋’ค์— ์˜ฌ ๋ฐ”๋”” ๋ฉ”์‹œ์ง€์˜ ๊ธธ์ด๋ฅผ ๋ช…์‹œํ•˜๋Š” ๊ฒƒ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ

๋’ค์— ์˜ฌ ๋ฉ”์‹œ์ง€์˜ ํƒ€์ž…์€ ์–ด๋–ค ๊ฒƒ์ด ์˜ค๋Š”์ง€์— ๋Œ€ํ•ด์„œ๋„ ๊ฐ–๊ณ  ์žˆ๋‹ค

๋ฉ”์‹œ์ง€์˜ ํƒ€์ž…์„ ๋‚˜ํƒ€๋‚ด๋Š” ํ—ค๋”๋Š” → Content-Type ํ—ค๋” ์ด๋‹ค

 

์™œ ์ด๋Ÿฐ๊ฒŒ ํ•„์š”ํ•œ์ง€๋Š” ์ธ์ฝ”๋”ฉ๊ณผ MIME ๊ฐœ๋… ์„ค๋ช…์ด ํ•„์š”ํ•˜๋‹ค

 

cf) Content-Type ํ—ค๋”๋Š” MIME Type์— ํฌํ•จ๋˜๋Š” ํ—ค๋”

* MIME(Multipurpose Internet Mail Extensions)

 

๋ณดํ†ต ๋งŽ์ด ๋ดค์„ Content-Type์€ application/json ๊ฐ™์€ ํƒ€์ž…์ด๋‹ค

(์•„์ฃผ์•„์ฃผ ์—ฌ๋Ÿฌ ์ข…๋ฅ˜๊ฐ€ ์žˆ์Œ, ์ฒจ๋ถ€๋งํฌ ์ฐธ๊ณ )

 

์ด Content-Type์˜ ์ข…๋ฅ˜ ์ค‘ ํ•˜๋‚˜๊ฐ€ multipart๋ผ๋Š” ๊ฒƒ์ธ๋ฐ,

์–ด๋–ค ๋ฉ”์‹œ์ง€๋“ค์ด multi๋กœ ์˜ฌ ๊ฒƒ์ด๋‹ˆ ์ค€๋น„ํ•ด~~ ๋ผ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค

 

์—‡,,, ๊ทธ๋Ÿฌ๋ฉด ๋งŒ์•ฝ json ๋ฉ”์‹œ์ง€๋„ ์˜ค๊ณ .. XML ๋ฉ”์‹œ์ง€๋„ ์˜ค๊ณ .. ์ด๊ฑธ ์–ด๋–ป๊ฒŒ ๊ตฌ๋ถ„ํ• ๊นŒ? 

๋ผ๋Š” ์ƒ๊ฐ์ด ๋“คํ…๋ฐ, ๊ทธ๋ž˜์„œ Multipart ๋ฉ”์‹œ์ง€๋Š” ๋ฉ”์‹œ์ง€ part๋ฅผ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ๋Š”

"boundary"๋ผ๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ™์ด ๋ฐ๋ฆฌ๊ณ  ๋‹ค๋‹Œ๋‹ค

 

Content-type: multipart/mixed; boundary="simple boundary" 

 

์ด๋Ÿฐ ํ˜•ํƒœ๋กœ! boundary ํŒŒ๋ผ๋ฏธํ„ฐ์— ์žˆ๋Š” "simple boundary"๋กœ ๋ฉ”์‹œ์ง€๊ฐ€ ๊ตฌ๋ถ„๋ผ ~~ ๋ผ๋Š” ๋œป

๋˜ํ•œ, boundary๋Š” MIME ๊ทœ๊ฒฉ์— ๋”ฐ๋ฅด๋ฉด, "--" ์š” ํ•˜์ดํ”ˆ ๋ฌธ์ž์—ด์ด ๊ฐ™์ด ์˜จ๋‹ค

๋งˆ์ง€๋ง‰ boundary๋Š” ์–‘ ์˜†์— --์ด ์ถ”๊ฐ€๋˜์–ด, "--simple boundary--" ๋ชจ์–‘์ด๋‹ค

 

*MIME ๊ทœ๊ฒฉ 7.2.1 Multipart: The common syntax
The encapsulation boundary is defined as a line consisting entirely of two hyphen characters ("-", decimal code 45) followed by the boundary parameter value from the Content-Type header field.

๋˜ํ•œ Boundary ๊ฐ„์€ CRLF๋กœ ๊ตฌ๋ถ„ํ•˜๋ฉด ๋œ๋‹ค.. (CRLF ์ง„์งœ ์‹ซ๋‹ค)

์•„๋ž˜๋Š” ์˜ˆ์‹œ์ด๋‹ค

 

Content-type: multipart/{type}; boundary="simple boundary" 

11
--simple boundary 

43
--simple boundary
Content-type:application/json; charset=utf-8

{
	"test": "hi"
}
--simple boundary 

....

 


HTTP ํ”„๋กœํ† ์ฝœ์€ ๋„ˆ๋ฌด ๊ด‘๋ฒ”์œ„ํ•ด์„œ ๋‚ด๊ฐ€ ์ •๋ฆฌํ•˜๊ณ  ์‹ถ์€ ๋ถ€๋ถ„๋งŒ ์ •๋ฆฌํ•˜๊ธฐ๊ฐ€

๋„ˆ๋ฌด ํž˜๋“  ํ”„๋กœํ† ์ฝœ์ด๋‹ค

์•„ ๊ทธ๋ƒฅ ์ด๋Ÿฐ ๊ฐœ๋…๋„ ์žˆ๊ตฌ๋‚˜~ ์ •๋„๋งŒ ์•Œ๊ณ ๊ฐ€๋„ ์ถฉ๋ถ„ํ•œ ๋“ฏํ•˜๋‹ค

 

์ข€๋” ์ƒ์„ธํ•œ ๊ฐœ๋… ์„ค๋ช…์€ ๋‹ค์Œ์˜ ๋‚˜์—๊ฒŒ ๋งก๊ธฐ๋Š”๊ฑธ๋กœ

 

 


ko.wikipedia.org/wiki/HTTP

 

HTTP - ์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „

์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „. HTTP(HyperText Transfer Protocol, ๋ฌธํ™”์–ด: ์ดˆ๋ณธ๋ฌธ์ „์†ก๊ทœ์•ฝ, ํ•˜์ดํผ๋ณธ๋ฌธ์ „์†ก๊ทœ์•ฝ)๋Š” W3 ์ƒ์—์„œ ์ •๋ณด๋ฅผ ์ฃผ๊ณ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ํ”„๋กœํ† ์ฝœ์ด๋‹ค. ์ฃผ๋กœ HTML ๋ฌธ์„œ๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” ๋ฐ์—

ko.wikipedia.org

tools.ietf.org/html/rfc2616

 

RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1

[Docs] [txt|pdf] [draft-ietf-http...] [Tracker] [Diff1] [Diff2] [Errata] Obsoleted by: 7230, 7231, 7232, 7233, 7234, 7235 DRAFT STANDARD Updated by: 2817, 5785, 6266, 6585 Errata Exist Network Working Group R. Fielding Request for Comments: 2616 UC Irvine

tools.ietf.org

 

developer.mozilla.org/ko/docs/Web/HTTP/Overview

 

HTTP ๊ฐœ์š” - HTTP | MDN

HTTP๋Š” HTML ๋ฌธ์„œ์™€ ๊ฐ™์€ ๋ฆฌ์†Œ์Šค๋“ค์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ๋Š” ํ”„๋กœํ† ์ฝœ์ž…๋‹ˆ๋‹ค. HTTP๋Š” ์›น์—์„œ ์ด๋ฃจ์–ด์ง€๋Š” ๋ชจ๋“  ๋ฐ์ดํ„ฐ ๊ตํ™˜์˜ ๊ธฐ์ดˆ์ด๋ฉฐ, ํด๋ผ์ด์–ธํŠธ-์„œ๋ฒ„ ํ”„๋กœํ† ์ฝœ์ด๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค. ํด๋ผ์ด์–ธํŠธ-์„œ๋ฒ„

developer.mozilla.org

* HTTP ์—๋Ÿฌ ์ฝ”๋“œ

developer.mozilla.org/ko/docs/Web/HTTP/Status

 

HTTP ์ƒํƒœ ์ฝ”๋“œ - HTTP | MDN

BCD tables only load in the browser HTTP ์‘๋‹ต ์ƒํƒœ ์ฝ”๋“œ๋Š” ํŠน์ • HTTP ์š”์ฒญ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋˜์—ˆ๋Š”์ง€ ์•Œ๋ ค์ค๋‹ˆ๋‹ค. ์‘๋‹ต์€ 5๊ฐœ์˜ ๊ทธ๋ฃน์œผ๋กœ ๋‚˜๋ˆ„์–ด์ง‘๋‹ˆ๋‹ค: ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๋Š” ์‘๋‹ต, ์„ฑ๊ณต์ ์ธ ์‘๋‹ต, ๋ฆฌ๋‹ค์ด๋ ‰

developer.mozilla.org

* HTTP Chunked ๋ฉ”์‹œ์ง€ ์ฐธ๊ณ  ์ž๋ฃŒ

flylib.com/books/en/1.2.1.149/1/

 

Transfer Encoding and Chunked Encoding | HTTP: The Definitive Guide

flylib.com © 2008-2017. If you may any questions please contact us: flylib@qtcs.net

flylib.com

* String hex to Int

viiiin.tistory.com/66

 

[C++] String to Hex ๋ณ€ํ™˜

ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ค‘์— ํ…์ŠคํŠธ ํŒŒ์ผ์—์„œ 16์ง„์ˆ˜ ํ˜•ํƒœ์˜ ๋ฌธ์ž์—ด์„ ์ฝ์–ด์™€์„œ ์ •์ˆ˜ํ˜•์œผ๋กœ ๋ณ€ํ™˜ํ•ด ์ค˜์•ผ ํ•  ๊ฒฝ์šฐ๊ฐ€ ์ข…์ข… ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๊ฒฝ์šฐ์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ stringstream ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋งค์šฐ ๊ฐ„๋‹จํ•˜

viiiin.tistory.com

 

* HTTP Multipart ์ฐธ๊ณ ๊ธ€

qssdev.tistory.com/47

 

HTTP Multipart์™€ MIME

HTTP multipart request.md HTTP Multipart Multipart๋Š” HTTP๋ฅผ ํ†ตํ•ด File์„ SERVER๋กœ ์ „์†กํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” Content-type์ž…๋‹ˆ๋‹ค. ๊ฐ„๋‹จํ•˜๊ฒŒ HTTP(request์™€ response ๋‘˜ ๋‹ค)๋Š” 4๊ฐœ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ..

qssdev.tistory.com

 

* HTTP Content-Type ์ข…๋ฅ˜ ์ฐธ๊ณ 

juyoung-1008.tistory.com/4

 

MIME-Type,Content-Type์ด๋ž€?

MIME์ด๋ž€? MIME์ด๋ž€? Multipurpose Internet Mail Extensions์˜ ์•ฝ์ž๋กœ ๊ฐ„๋žตํžˆ ๋ง์”€์„ ๋“œ๋ฆฌ๋ฉด ํŒŒ์ผ ๋ณ€ํ™˜์„ ๋œปํ•œ๋‹ค. MIME๋Š” ์ด๋ฉ”์ผ๊ณผ ํ•จ๊ป˜ ๋™๋ด‰ํ•  ํŒŒ์ผ์„ ํ…์ŠคํŠธ ๋ฌธ์ž๋กœ ์ „ํ™˜ํ•ด์„œ ์ด๋ฉ”์ผ ์‹œ์Šคํ…œ์„ ํ†ตํ•ด ์ „๋‹ฌํ•˜๊ธฐ

juyoung-1008.tistory.com

 

* MIME ๊ทœ๊ฒฉ

www.w3.org/Protocols/rfc1341/7_2_Multipart.html

 

RFC1341(MIME) : 7 The Multipart content type

7.2 The Multipart Content-Type In the case of multiple part messages, in which one or more different sets of data are combined in a single body, a "multipart" Content-Type field must appear in the entity's header. The body must then contain one or more "bo

www.w3.org

 

'๐Ÿ“– Protocol' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

UDP๋ฅผ ์•Œ์•„๋ณด์ž  (0) 2021.07.08
SOAP์„ ์•Œ์•„๋ณด์ž  (0) 2021.06.10
SMTP๋ฅผ ์•Œ์•„๋ณด์ž  (0) 2020.12.16