Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Goで書いて学ぶ HTTP Server / Write and learn HTTP Ser...

noyan
October 12, 2023
19

Goで書いて学ぶ HTTP Server / Write and learn HTTP Server in Go

noyan

October 12, 2023
Tweet

Transcript

  1. ύʔαʔ: HTTPϦΫΤετͷߏจ • HTTP/1.1ͷߏจ- RFC 9112 sec 2.1 • ͭ·ΓɺϦΫΤετΛύʔε͢Δʹ͸ɺελʔτϥΠϯɾϑΟʔ

    ϧυϥΠϯɾϘσΟͷॲཧΛ࣮૷͢Ε͹ྑ͍ɻ HTTP-message = start-line CRLF *( fi eld-line CRLF ) CRLF [ message-body ]
  2. ύʔαʔ: HTTP/1.1 ϦΫΤετ • ϦΫΤετϥΠϯʢϝιο υɺύεɺHTTPόʔδϣ ϯʣ • ϑΟʔϧυϥΠϯʢϔο μʔɺτϨΠϥʔʣ

    • ϘσΟ HTTP-message = start-line CRLF *( fi eld-line CRLF ) CRLF [ message-body ]
  3. ύʔαʔ: ϦΫΤετϥΠϯͷߏจ • ϦΫΤετϥΠϯͷߏจ͸࣍ͷΑ͏ʹఆٛ͞Ε͍ͯΔ • request-line = method SP request-target

    SP HTTP-version • ref. RFC 9112 sec. 3 • ͕ͨͬͯ͠ඞཁͳॲཧ͸ • ϦΫΤετͷ࠷ॳͷߦΛಡΈࠐΉ • ۭനͰ෼ׂ͢Δ • ॱʹϝιουɾλʔήοτɾHTTPόʔδϣϯͱ͢Δ
  4. ύʔαʔ: ϑΟʔϧυͷߏจ • ϦΫΤετϥΠϯͷߏจ͸࣍ͷΑ͏ʹఆٛ͞Ε͍ͯΔ • fi eld-line = fi eld-name

    ":" OWS fi eld-value OWS • ref. RFC 9112 sec. 5 • ͕ͨͬͯ͠ඞཁͳॲཧ͸ • ϦΫΤετϥΠϯҎ߱ɺۭߦ·ͰಡΈਐΊΔ • ίϩϯͰ෼ׂ͠ɺϑΟʔϧυ໊ɾϑΟʔϧυ஋ͱ͢Δ
  5. ϦΫΤετ: ϘσΟͷߏจ • ϦΫΤετʹϘσΟؚ͕·ΕΔ͔͸ɺ Content-Length ͔ Transfer- Encoding ϔομʔϑΟʔϧυͰࣔ͞ΕΔ (sec.

    6) • ϦΫΤετϥΠϯͷߏจ͸࣍ͷΑ͏ʹఆٛ͞Ε͍ͯΔ • message-body = *OCTET • ࠓճ͸୯७ԽͷͨΊɺTransfer-Encoding͸ѻΘͳ͍
  6. Ϩεϙϯε: HTTPϨεϙϯεͷߏจ • HTTP/1.1ͷߏจ- RFC 9112 sec. 2.1, sec. 4

    • ͭ·Γɺ͜ͷॱ൪Ͱॻ͖ग़ͤ͹͍͍ HTTP-message = start-line CRLF *( fi eld-line CRLF ) CRLF [ message-body ] status-line = HTTP-version SP status-code SP [ reason-phrase ]
  7. ٧·ͬͨͱ͜Ζ • Body ͷύʔεΛ࣮૷ͨ͠Βɺϋϯά͢ΔΑ͏ʹͳͬͨ • ݪҼ: Body ͷऴ୺ʹ CRLF ؚ͕·Εͳ͍

    • αʔόʔ͸ΫϥΠΞϯτ͔Βऴ୺ه߸͕ૹΒΕͯ͜ͳ͍͔ظ଴͠ ͯ଴ͬͯ͠·͍ͬͯͨ • ରࡦ: Reader Λ bu fi o ͷ Scanner ͔Β Reader ʹมߋ͠ɺContent- Length ͚ͩಡΉΑ͏ʹมߋ