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ݴޠ͸ڧ͍ຯํʹͳͬͯ͘ΕΔ