Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
GoͰॻֶ͍ͯͿHTTP Server 2023 - 10 - 12 ൃදձ - Enablement Bootcamp for Gopherizing #1 noyan
Slide 2
Slide 2 text
ϥΠϒϥϦΛଟ༻͢Δݱͷ։ൃ ↓ ࣮ͨ͠ػೳ ≠ ٕज़ྗ ↓ গ͠ਂ͘જͬͯΈΑ͏ʂ
Slide 3
Slide 3 text
ࠓճ͕ࣗHTTPαʔόʔͰ ֶΜͩ͜ͱΛ͠·͢
Slide 4
Slide 4 text
ࣗݾհ • ໊લɿnoyan • ϑϩϯτΤϯυք۾ʹੜଉ • Zenn: https://zenn.dev/noyan
Slide 5
Slide 5 text
HTTP αʔόʔΛ࣮͠Α͏ • ΫϥΠΞϯταΠυͷ࣮Λ͢ΔதͰɺ HTTP ϓϩτίϧͷετϦʔϛϯάΩϟογϡ ͳͲΛΔඞཁΛײͨ͡ • ୯७ͳϦΫΤετΛड͚औͬͯݻఆͷϨεϙϯεΛฦ͢؆қతͳHTTPαʔόʔΛ࣮͢Δ • ඞཁͳ͜ͱ • ϦΫΤετͷύʔαʔΛॻ͘ • ϦΫΤετʹରͯ͠Ϩεϙϯε͕ฦͬͯ͘ΔΑ͏ʹ͢Δ
Slide 6
Slide 6 text
ύʔαʔ: ԿΛ͢Εྑ͍͔ • ؆୯ʹݴ͑ɺ͜ͷϦΫΤ ετΛύʔεͰ͖ΔΑ͏ͳ ύʔαʔΛ࣮͢Εྑ͍
Slide 7
Slide 7 text
ύʔαʔ: HTTPϦΫΤετͷߏจ • HTTP/1.1ͷߏจ- RFC 9112 sec 2.1 • ͭ·ΓɺϦΫΤετΛύʔε͢ΔʹɺελʔτϥΠϯɾϑΟʔ ϧυϥΠϯɾϘσΟͷॲཧΛ࣮͢Εྑ͍ɻ HTTP-message = start-line CRLF *( fi eld-line CRLF ) CRLF [ message-body ]
Slide 8
Slide 8 text
ύʔαʔ: HTTP/1.1 ϦΫΤετ • ϦΫΤετϥΠϯʢϝιο υɺύεɺHTTPόʔδϣ ϯʣ • ϑΟʔϧυϥΠϯʢϔο μʔɺτϨΠϥʔʣ • ϘσΟ HTTP-message = start-line CRLF *( fi eld-line CRLF ) CRLF [ message-body ]
Slide 9
Slide 9 text
ύʔαʔ: ࣮ํ 1. ࠷ॳͷߦΛ start-line ͱͯ͠ύʔ ε 2. ۭߦ͕ݱΕΔ·Ͱͷ֤ߦΛ ϑΟʔϧυϥΠϯͱͯ͠ύʔε 3. Γͷ෦ΛϘσΟͱͯ͠ύʔ ε
Slide 10
Slide 10 text
ύʔαʔ: ࣮ •
Slide 11
Slide 11 text
ύʔαʔ: ϦΫΤετϥΠϯͷߏจ • ϦΫΤετϥΠϯͷߏจ࣍ͷΑ͏ʹఆٛ͞Ε͍ͯΔ • request-line = method SP request-target SP HTTP-version • ref. RFC 9112 sec. 3 • ͕ͨͬͯ͠ඞཁͳॲཧ • ϦΫΤετͷ࠷ॳͷߦΛಡΈࠐΉ • ۭനͰׂ͢Δ • ॱʹϝιουɾλʔήοτɾHTTPόʔδϣϯͱ͢Δ
Slide 12
Slide 12 text
ύʔαʔ: ϦΫΤετϥΠϯ࣮
Slide 13
Slide 13 text
ύʔαʔ: ϑΟʔϧυͷߏจ • ϦΫΤετϥΠϯͷߏจ࣍ͷΑ͏ʹఆٛ͞Ε͍ͯΔ • fi eld-line = fi eld-name ":" OWS fi eld-value OWS • ref. RFC 9112 sec. 5 • ͕ͨͬͯ͠ඞཁͳॲཧ • ϦΫΤετϥΠϯҎ߱ɺۭߦ·ͰಡΈਐΊΔ • ίϩϯͰׂ͠ɺϑΟʔϧυ໊ɾϑΟʔϧυͱ͢Δ
Slide 14
Slide 14 text
ϦΫΤετɿ ϥΠϯͷߏจ
Slide 15
Slide 15 text
ϦΫΤετ: ϘσΟͷߏจ • ϦΫΤετʹϘσΟؚ͕·ΕΔ͔ɺ Content-Length ͔ Transfer- Encoding ϔομʔϑΟʔϧυͰࣔ͞ΕΔ (sec. 6) • ϦΫΤετϥΠϯͷߏจ࣍ͷΑ͏ʹఆٛ͞Ε͍ͯΔ • message-body = *OCTET • ࠓճ୯७ԽͷͨΊɺTransfer-EncodingѻΘͳ͍
Slide 16
Slide 16 text
ϦΫΤετɿϘσΟ࣮ίʔυ •
Slide 17
Slide 17 text
Ϩεϙϯε: 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 ]
Slide 18
Slide 18 text
Ϩεϙϯε: HTTPϨεϙϯε࣮
Slide 19
Slide 19 text
٧·ͬͨͱ͜Ζ • Body ͷύʔεΛ࣮ͨ͠Βɺϋϯά͢ΔΑ͏ʹͳͬͨ • ݪҼ: Body ͷऴʹ CRLF ؚ͕·Εͳ͍ • αʔόʔΫϥΠΞϯτ͔Βऴه߸͕ૹΒΕͯ͜ͳ͍͔ظ͠ ͯͬͯ͠·͍ͬͯͨ • ରࡦ: Reader Λ bu fi o ͷ Scanner ͔Β Reader ʹมߋ͠ɺContent- Length ͚ͩಡΉΑ͏ʹมߋ
Slide 20
Slide 20 text
࣮ࡍʹ࡞ͬͨͷ • no-yan/go-http • https://github.com/no-yan/go-http
Slide 21
Slide 21 text
GoͰॻ͍ͯࢥͬͨ͜ͱ • Goݴޠ͔ͩΒ͔ɺRFCͷ࣮ͦͷͷʹूத͢Δ͜ͱ͕Ͱ͖ͨ • ωοτϫʔΫ io.Reader ͩͱߟ͍͑ͯΕྑ͍ • net/http ͕͔ͳΓಡΈ͍͢ • ඪ४ϥΠϒϥϦ͕ಉ͡ݴޠͰॻ͔Ε͍ͯΔͱɺؾܰʹಡΈʹߦ͚Δʂ • ंྠͷ࠶ൃ໌ʹͱͬͯخ͍͠
Slide 22
Slide 22 text
·ͱΊ • HTTP/1.1 ͷ؆୯ͳ࣮Λߦͳͬͨ • RFC४ڌΛ͍ٻΊͳ͚ΕɺҊ֎ؾܰʹ࡞Δ͜ͱ͕Ͱ͖Δ • গ͠ਂ͘જΔ࣌ʹɺGoݴޠڧ͍ຯํʹͳͬͯ͘ΕΔ