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

そろそろPerlでのHTTP/2について触れたい

 そろそろPerlでのHTTP/2について触れたい

YAPC::Okinawa 2018 ONNASON
Mar 03, 2018

Yuji Shimada

March 03, 2018
Tweet

More Decks by Yuji Shimada

Other Decks in Programming

Transcript

  1. ͦΖͦΖPerlͰͷ
    HTTP/2ʹ͍ͭͯ
    ৮Ε͍ͨ
    Yuji Shimada @xaicron
    YAPC::Okinawa 2018 ONNASON
    Mar 03, 2018

    View full-size slide

  2. Έͳ͞Μԭೄ
    ͨͷ͠ΜͰ·͔͢ʂʁ

    View full-size slide

  3. ΦϦΦϯ࠷ߴͰ͢Ͷʂʂ

    View full-size slide

  4. ࣗ෼͸ւͿͲ͏͕େ޷͖Ͱ͢

    View full-size slide

  5. ே͔ΒւͿͲ͏৯΂ΒΕͯ
    ࠷ߴͰ͢Ͷ

    View full-size slide

  6. ͖ͬ͞ @kazuho ͞Μͷ
    τʔΫฉ͍ͨਓʙʁ

    View full-size slide

  7. ్த·Ͱ৸ͯͯେৎ෉Ͱ͢

    View full-size slide

  8. HTTP/2ʹ͍ͭͯΘ͔Βͳ͍͜
    ͱ͕͋Δਓ͸ @kazuho ͞Μ
    ʹฉ͜͏ʂʂ

    View full-size slide

  9. Perlʹ͍ͭͯΘ͔Βͳ͍͜ͱ
    ͕͋Δਓ͸࠙਌ձͰ༗ࣝऀʹ
    ฉ͜͏ʂʂ

    View full-size slide

  10. HTTP/1.1ͱHTTP/2Ͳ͕ͬͪ
    ଎͍ͱࢥ͍·͔͢ʁ

    View full-size slide

  11. H1ͱH2Ͳ͕ͬͪ͸΍͍ʁ
    • H1͕͸΍͍
    • H2͕͸΍͍
    • ৔߹ʹΑΔ
    • Θ͔Βͳ͍

    View full-size slide

  12. H1ͱH2Ͳ͕ͬͪ͸΍͍ʁ
    • H1͕͸΍͍
    • H2͕͸΍͍
    • ৔߹ʹΑΔ
    • Θ͔Βͳ͍

    View full-size slide

  13. ΞδΣϯμ
    • HTTP/2ʹ͍ͭͯ
    • PerlͰHTTP/2Λѻ͓͏
    • ͓·͚: gRPCͱPerl
    • ·ͱΊ

    View full-size slide

  14. HTTP/2ʹ͍ͭͯ

    View full-size slide

  15. HTTP/2஀ੜ·ͰͷܦҢ

    View full-size slide

  16. ͸͡ΊʹSPDY͕͋ͬͨ

    View full-size slide

  17. ͸͡ΊʹSPDY͕͋ͬͨ
    • 2009೥11݄ʹGoogle͕SPDYͷυϥϑτ࢓༷
    Λެ։
    • 2010೥6݄ʹϦϦʔε͞ΕͨChrome 6͔Βσ
    ϑΥϧτͰ༗ޮʹͳͬͨ

    View full-size slide

  18. SPDYྑͦ͞͏ͩ͠
    ඪ४Խ͠Α͏ʂʂ

    View full-size slide

  19. ͷͪͷHTTP/2Ͱ͋Δ

    View full-size slide

  20. ͷͪͷHTTP/2Ͱ͋Δ
    • ࠷ॳ͸HTTP/2.0ͱ͍͏໊લͩͬͨ
    • HTTP/2͕ਖ਼໊ࣜশʹ
    • 2015೥5݄ʹHTTP/2͕RFC 7540ͱͯ͠ެ։
    • ಉ࣌ʹHPACK͕RFC 7541ͱͯ͠ެ։

    View full-size slide

  21. ໿16೥ͿΓʹHTTP͕
    Ξοϓσʔτ͞Εͨʂʂ
    (ͦΕ·Ͱʹ΋ͪΐͪ͘ΐ͘มߋ͸͚͋ͬͨͲ΋)

    View full-size slide

  22. SPDY͸Ͳ͏ͳͬͨʁ

    View full-size slide

  23. SPDY͸Ͳ͏ͳͬͨʁ
    • SPDY͸όʔδϣϯ3.1Ͱऴྃ
    • SPDY4͸࠷ऴతʹHTTP/2ͷυϥϑτ14ͷΤ
    ΠϦΞεʹͳͬͨ
    • 2016/5/15ʹChrome͸SPDYͷαϙʔτΛऴ

    View full-size slide

  24. SPDY͸HTTP/2ʹ
    ஔ͖׵Θͬͨʂ

    View full-size slide

  25. ͳͥHTTP/2(SPDY)
    ͕ඞཁʹͳͬͨʁ

    View full-size slide

  26. ͳͥHTTP/2͕ඞཁʹͳͬͨʁ
    • HTTP/1.1ͷެ։ʢ1999೥ʣ͔Β10೥ܦͬͯɺ
    Webίϯςϯπͷ༰ྔ͕ग़དྷతʹ૿Ճ
    • ੩తϖʔδ͚ͩͰͳ͘ಈతϖʔδ͕૿͖͑ͯ
    ͨ
    • 1ϖʔδදࣔ͢ΔͨΊʹ਺ेճҎ্ͷϦΫΤ
    ετ͕ൃߦ͞ΕΔ͜ͱ΋βϥʹ

    View full-size slide

  27. Web͕஗͘ͳ͖ͬͯͨʂʁ

    View full-size slide

  28. Web͕஗͍͍͔ͭ͘ͷཧ༝(1)
    • ωοτϫʔΫͷଳҬ͕ڱ͍ʢ·ͩ·ͩ3Gճઢ΋ଟ͍ʣ
    • ղܾࡦͷྫ
    • ૹ৴͢ΔσʔλΛѹॖͯ͠ݮΒ͢
    • ΑΓૣ͍ճઢΛීٴͤ͞Δ
    • 10GbpsͷݻఆճઢΛීٴͤ͞Δ
    • 5Gͷొ৔Ͱ௿஗Ԇ͔ͭ20Gbpsඈ͹ͤΔͧ
    • 120TbpsͷւఈέʔϒϧʹҾ͖௚͢ʢPLCNʣ

    View full-size slide

  29. Web͕஗͍͍͔ͭ͘ͷཧ༝(2)
    • TCPʹແବ͕ଟ͍
    • ղܾࡦͷྫ
    • ᫔᫓΢Οϯυ΢αΠζͷॳظ஋Λେ͖͘͢Δ
    • Google͕৽͍͠᫔᫓੍ޚΞϧΰϦζϜBBRΛ։ൃ
    • ͨͱ͑͹TCPΛ΍ΊͯUDPϕʔεͷQUICʹ͢Δ

    View full-size slide

  30. Web͕஗͍͍͔ͭ͘ͷཧ༝(3)
    • HTTP/1.1ͷϓϩτίϧ্ͷ໰୊ʹىҼ
    • HTTP/2͸͜͜ʹΞϓϩʔνʂ

    View full-size slide

  31. HTTP/1.1ͷ໰୊఺

    View full-size slide

  32. HTTP/1.1ͷ໰୊఺
    • 1ͭͷϦΫΤετ͕׬ྃ͢Δ·Ͱ࣍ͷϦΫΤετ
    Λૹ৴͢Δ͜ͱ͕Ͱ͖ͳ͍
    • ଴͕ͪ࣌ؒແବ
    • ಉ͡HTTP HeaderΛԿ౓΋Կ౓΋ૹड৴͍ͯ͠Δ
    • ύέοτ͕ແବ

    View full-size slide

  33. 1ͭͷϦΫΤετ͕׬ྃ͢Δ
    ·Ͱ࣍ͷϦΫΤετΛૹ৴͢
    Δ͜ͱ͕Ͱ͖ͳ͍

    ϦΫΤετ͕௚ྻ

    View full-size slide

  34. ϦΫΤετ͕௚ྻ
    • HTTP/1.1Ͱ͸1ͭͷTCPίωΫγϣϯʹରͯ͠ɺ1
    ϦΫΤετ͕ऴΘΔ·Ͱ଴ͨͳͯ͘͸͍͚ͳ͍
    • ChromeͰ͸1ͭͷυϝΠϯʹରͯ͠࠷େ6ͭ·
    ͰTCPίωΫγϣϯΛషΔ͜ͱͰߴ଎ԽΛ࣮ݱ
    ʢ౰ࣾൺ6ഒʣ
    • ͨͩ͠ɺHTTP/1.1ͷ࢓༷Ͱ͸2ͭ·Ͱʹ੍ݶ

    View full-size slide

  35. ͦ͜Ͱ
    HTTPύΠϓϥΠϯ
    Ͱ͢Αʂ

    View full-size slide

  36. HTTPύΠϓϥΠϯͱ͸
    • 1ͭͷTCP্ͰϨεϙϯεΛ଴ͭ͜ͱͳ͘ϦΫ
    ΤετΛૹ৴͢Δ͜ͱ͕Ͱ͖Δ࢓༷

    View full-size slide

  37. HTTPύΠϓϥΠϯ
    • ႈ౳ͳϦΫΤετͰ͔͠ར༻Ͱ͖ͳ͍
    • GET΍HEAD͕࿈ଓ͢ΔϦΫΤετͰ͸ར༻Մೳ
    • PUT΍DELETEͰ΋ར༻Ͱ͖Δ৔߹͕͋Δ
    • Ϩεϙϯε͸ϦΫΤετΛૹͬͨॱ൪Ͱड৴͠ͳ͚Ε͹ͳΒͳ͍
    • Head of Line (HOL) Blocking ͸݁ہൃੜ͢Δ
    • ຆͲͷϒϥ΢βͰ࣮૷͞Ε͍ͯͳ͍͔σϑΥϧτͰແޮ
    • ΫϥΠΞϯτଆ͸ߟྀ͢Δ͜ͱ͕ଟ࣮͘૷͕೉͍͠

    View full-size slide

  38. ͦͷଞͷ༷ʑͳ࠷దԽ
    • Ϧιʔεͷ݁߹
    • JavaScriptϑΝΠϧͷ݁߹΍ը૾ͷCSSεϓϥΠτʹΑΔϦΫΤετ
    ਺ͷ࡟ݮ
    • ը૾ͷΠϯϥΠϯԽ
    • base64ܗࣜͰը૾ΛHTMLʹຒΊࠐΉ͜ͱʹΑΔϦΫΤετ਺ͷ࡟ݮ
    • υϝΠϯγϟʔσΟϯά
    • ෳ਺ͷυϝΠϯΛར༻͢Δ͜ͱͰTCPͷಉ࣌઀ଓ਺Λ૿΍͢

    View full-size slide

  39. ಉ͡HTTP HeaderΛԿ౓΋Կ
    ౓΋ૹ৴͍ͯ͠Δ

    View full-size slide

  40. ͕Μ͹ͬͯෆཁͳϔομʔΛ
    ৬ਓ͕࡟Δ͔͠ແ͍ʂʂ

    View full-size slide

  41. HTTP/1.1Ͱ͸
    ύϑΥʔϚϯεΛ্͛ΔͨΊ
    ʹϓϩτίϧҎ֎ͷͱ͜ΖͰ
    ͳΜͱ͔͠ͳ͚Ε͹͍͚ͳ͔ͬ
    ͨ

    View full-size slide

  42. HTTP/2Ͱ͸ϓϩτίϧΛ
    վྑ͢Δ͜ͱͰղܾ͠Α͏ͱ
    ͨ͠

    View full-size slide

  43. ͱ͍͏Θ͚Ͱ

    View full-size slide

  44. HTTP/2ͷಛ௃

    View full-size slide

  45. HTTP/2ͷಛ௃
    • HTTP/1.1ͷηϚϯςΟΫεͱޓ׵ੑ͕͋Δ
    • ετϦʔϜ
    • όΠφϦϓϩτίϧ
    • HTTPϔομʔѹॖ
    • αʔόʔϓογϡ

    View full-size slide

  46. HTTP/1.1ͷηϚϯςΟΫεͱ
    ޓ׵ੑ͕͋Δ
    • εΩʔϚ͸”http://“ٴͼ”https://“Λͦͷ··ར༻
    • ϙʔτ͸80ͱ443Λͦͷ··ར༻
    • HTTPϔομʔ΋΄΅ͦͷ··ར༻
    • શͯখจࣈʹͳͬͨΓར༻ෆՄͷΩʔ͕͋ͬ
    ͨΓ͸͢Δ

    View full-size slide

  47. ετϦʔϜ(1)
    • ༏ઌ౓෇͖શೋॏଟॏԽ௨৴
    • ̍ͭͷTCPίωΫγϣϯ্Ͱෳ਺ͷετϦʔϜΛฒྻ
    ʹѻ͏͜ͱ͕Ͱ͖Δ
    • SETTINGS_MAX_CONCURRENT_STREAMSͰ࠷
    େ஋Λઃఆ
    • ͦΕͧΕͷετϦʔϜ͸ಠཱ͍ͯͯ͠ϒϩοΫ͠ͳ͍

    View full-size slide

  48. ετϦʔϜ(2)
    • ΫϥΠΞϯτɺαʔόʔͲͪΒ͔ΒͰ΋։࢝͢Δ͜ͱ͕Ͱ
    ͖Δ
    • ετϦʔϜIDͰ֤ετϦʔϜΛ؅ཧ͢Δ
    • ΫϥΠΞϯτ͸ح਺ɺαʔόʔ͸ۮ਺͔Β࢝ΊΔ͜ͱͰ
    ڝ߹Λճආ
    • ૹड৴͢Δσʔλ͸όΠφϦܗࣜ
    • ૹड৴͢Δσʔλ͸ϑϨʔϜͱ͍͏୯ҐͰૹड৴͢Δ

    View full-size slide

  49. όΠφϦϓϩτίϧ
    • HTTP/2͸ϦΫΤετ/ϨεϙϯεʹϑϨʔϜͱ
    ͍͏όΠφϦϑΥʔϚοτͰσʔλͷ΍Γऔ
    ΓΛߦ͏
    • ͍··ͰςΩετϓϩτίϧͰύʔε΍ղऍ͕
    ͕ᐆດͩͬͨͱ͜Ζ͕ݫ֨ʹͳͬͨ

    View full-size slide

  50. ϑϨʔϜͷϑΥʔϚοτ
    # 9ΦΫςοτͷϔομʔͱՄม௕ͷϖΠϩʔυ͔Β੒Δ
    # ͔ͬ͜ͷதͷ਺ࣈ͸1Ϗοτ
    +-----------------------------------------------+
    | Length (24) |
    +---------------+---------------+---------------+
    | Type (8) | Flags (8) |
    +-+-+-----------+---------------+-------------------------------+
    |R| Stream Identifier (31) |
    +=+=============================================================+
    | Frame Payload (0...) ...
    +———————————————————————————————+

    View full-size slide

  51. ϑϨʔϜͷछྨ
    5ZQF छྨ ໾ׂ
    %"5" ϦΫΤετϨεϙϯεͷϘσΟʔ
    )&"%&34 ϦΫΤετϨεϙϯεͷϔομʔ
    13*03*5: ετϦʔϜͷ༏ઌॱҐΛࢦఆʢΫϥΠΞϯτͷΈʣ
    345@453&". ΤϥʔͳͲͰετϦʔϜΛऴྃ͢Δͱ͖ʹ࢖༻
    4&55*/(4 ઀ଓઃఆΛมߋ͢Δ
    164)@130.*4& αʔόʔϓογϡΛ༧ࠂ͢ΔʢαʔόʔͷΈʣ
    1*/( ઀ଓͷੜଘ֬ೝ
    (0"8": ΤϥʔͳͲͰ઀ଓΛऴྃ͢Δͱ͖ʹ࢖༻
    8*/%08@61%"5& ΢Οϯυ΢αΠζΛมߋ͢Δ
    $0/5*/6"5*0/ αΠζͷେ͖ͳ)&"%&34164)@130.*4&ͷஅย

    View full-size slide

  52. HTTPϔομʔѹॖ
    • “HPACK”ͱ͍͏ܗࣜͰϔομΛѹॖ͢Δ
    • SPDYͰ͸gzipΛ༻͍͍͕ͯͨʮCRIMEʯͱ͍
    ͏߈ܸํ๏͕ݟ͔ͭͬͨͨΊผͷํ๏Ͱ࢓༷
    ࡦఆ

    View full-size slide

  53. HPACKͷಛ௃
    • όΠφϦܗࣜ
    • ΩʔΛখจࣈʹ౷Ұ
    • Α͘࢖ΘΕΔϔομʔͷΩʔͱ஋Λ૊Έʹͨࣙ͠ॻΛ࣋ͭ
    • ಈతʹࣙॻΛߋ৽͠ɺ2ճ໨Ҏ߱͸ΠϯσοΫεΛ༻͍Δ
    • Ωʔ΍஋ͷจࣈྻΛϋϑϚϯූ߸Ͱѹॖ͢Δ͜ͱ΋Ͱ͖Δ

    View full-size slide

  54. αʔόʔϓογϡ
    • HTTP/2Ͱ͸ΫϥΠΞϯτ͔ΒͷϦΫΤετ͕ͳ
    ͯ͘΋αʔόʔ͔ΒσʔλΛૹ৴͢Δ͜ͱ͕Ͱ
    ͖Δ
    • HTMLʹؔ࿈෇͚ΒΕ͍ͯΔCSS΍JavaScriptɺ
    ը૾ͳͲΛΫϥΠΞϯτͷϦΫΤετΛ଴ͨͣ
    ʹૹΓ͚ͭΒΕΔͷͰɺϖʔδදࣔ·Ͱͷ࣌ؒ
    ୹ॖ͕ݟࠐΊΔ

    View full-size slide

  55. αʔόʔϓογϡͷྲྀΕ
    • ΫϥΠΞϯτ͕ετϦʔϜ1Ͱindex.htmlΛཁٻ
    • αʔόʔ͸index.htmlʹ͸style.css͕ؔ࿈͍͍ͮͯΔ͜ͱΛ஌͍ͬͯ
    ΔͷͰstyle.cssΛετϦʔϜ2Ͱϓογϡ͢ΔʢPUSH_PROMISEʣ
    • ετϦʔϜ1Ͱindex.htmlΛड͚औͬͨΫϥΠΞϯτ͸ϦΫΤετΛ
    ߦ͏͜ͱͳ͘style.cssͷ౸ணΛ଴ͭ
    • αʔόʔ͔ΒετϦʔϜ2ʹΑͬͯstyle.css͕ಧ͖ɺϨϯμϦϯάΛ
    ։࢝͢Δ

    View full-size slide

  56. αʔόʔϓογϡͷ஫ҙ఺
    • HTTP/2Λಋೖ͚ͨͩ͠Ͱࣗಈతʹ͜ͷΑ͏ͳڍಈʹͳΔΘ͚Ͱ
    ͸ͳ͍
    • ΞϓϦέʔγϣϯଆͰઃఆ΍ϩδοΫΛ࣮૷͢Δඞཁ͕͋Δ
    • ϓογϡ͢Δίϯςϯπ͕ΫϥΠΞϯτͰΩϟογϡ͞Ε͍ͯ
    Δ͔Ͳ͏͔Θ͔Βͳ͍ͷͰແବͳϦΫΤετ͕ൃੜ͢ΔՄೳੑ
    ͕͋Δ
    • 103 Early HintsͳͲΛར༻͢Δ͜ͱͰΑΓޮ཰తʹͰ͖ΔՄ
    ೳੑ͕͋Δ

    View full-size slide

  57. HTTP/2Ͱ઀ଓΛߦ͏ํ๏

    View full-size slide

  58. HTTP/2Ͱ઀ଓΛߦ͏ํ๏
    (http઀ଓͷ৔߹)
    • HTTP/1.1ͱޓ׵ੑ͕͋ΔͨΊɺΫϥΠΞϯτ͸HTTP/
    2ͰΞΫηεͰ͖Δ͔Ͳ͏͔Λ൑ఆ͠ͳͯ͘͸͍͚ͳ͍
    • URL΍ϙʔτ൪߸͚ͩͰ͸൑அ͕Ͱ͖ͳ͍
    • ΫϥΠΞϯτ͸HTTP/1.1ͰಛఆͷHTTPϔομʔΛૹ
    ৴͢Δ͜ͱͰαʔόʔ͕HTTP/2ʹରԠ͍ͯ͠Δ͔Ͳ͏
    ͔൑அ͢Δ

    View full-size slide

  59. HTTP/2Ͱ઀ଓΛߦ͏ํ๏
    (http઀ଓͷ৔߹)
    • ϦΫΤετ࣌ʹ·ͣҎԼͷϔομʔΛ෇͚ͯ
    HTTP/1.1ϦΫΤετΛߦ͏
    • Connection: Upgrade, HTTP2-Settings
    • Upgrade: h2c
    • HTTP2-Settings: υͷ base64url Τϯίʔυ>

    View full-size slide

  60. ॳճϦΫΤετͷྫ
    # http://www.example.com/ ʹϦΫΤετͨ͠৔߹
    > GET / HTTP/1.1
    > Host: www.example.com
    > Connection: Upgrade, HTTP2-Settings
    > Upgrade: h2c
    > HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA

    View full-size slide

  61. ॳճϦΫΤετͷྫ
    # http://www.example.com/ ʹϦΫΤετͨ͠৔߹
    > GET / HTTP/1.1
    > Host: www.example.com
    > Connection: Upgrade, HTTP2-Settings
    > Upgrade: h2c
    > HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
    < HTTP/1.1 101 Switching Protocols
    < Connection: Upgrade
    < Upgrade: h2c
    # ͔͜͜ΒHTTP/2઀ଓ
    < server: perl-Protocol-HTTP2/1.08
    < content-length: 13
    < cache-control: max-age=3600
    < date: Thu, 01 Mar 2018 14:30:15 GMT
    < last-modified: Thu, 01 Mar 2018 14:30:15 GMT
    <
    hello, world!

    View full-size slide

  62. HTTP/2Ͱ઀ଓΛߦ͏ํ๏
    (http઀ଓͷ৔߹)
    • 101 Switching Protocol͕ฦ͖ͬͯͨΒ੒ޭ
    • ্هͷ͋ͱʹϦΫΤετΛૹΒͣʹHTTP/2
    Ϩεϙϯε͕ฦ͖͍ͬͯͯΔͱ͜Ζ͕ϛι
    • ͍͍ͩͨWebSocketͱҰॹ

    View full-size slide

  63. HTTP/2Ͱ઀ଓΛߦ͏ํ๏
    (https઀ଓͷ৔߹)
    • HTTP/2͸TLS1.2Ҏ্͕ඞਢ
    • application-layer protocol negotiation (ALPN) extension ͕ར
    ༻Ͱ͖Δඞཁ͕͋Δ
    • ҉߸εΠʔτ͸
    TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256Ҏ্͕ඞਢ
    • TLSϋϯυγΣΠΫ͕ऴΘͬͨޙʹʮHTTP/2ίωΫγϣϯϓϦ
    ϑΣΠεʯͱ͍͏24ΦΫςοτͷσʔλΛૹ৴͢Δ

    View full-size slide

  64. ίωΫγϣϯϓϦϑΣΠε
    • “PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n” Λૹ৴
    • ͜Ε͸HTTP/1.1ͷαʔόʔͩͱ PRI ͱ͍͏
    METHOD ͱͯ͠ղऍ͞Εͯ౴͑ΒΕͳ͍ͷͰ
    HTTP/2ʹରԠ͍ͯ͠ͳ͍ͱ൑அͰ͖Δ
    • ௚ޙʹαʔόʔ͔Β SETTINGS ϑϨʔϜʢޙड़ʣ
    ͕ฦͬͯ͘Ε͹੒ޭ

    View full-size slide

  65. ͜͜·Ͱ؆୯ʹͰ͕͢
    HTTP/2ͷ֓ཁʹ͍ͭͯ৮Εͯ
    ͖·ͨ͠

    View full-size slide

  66. ·ͩ·ͩແݶʹ࿩୊͸͋Γ·
    ͢

    View full-size slide

  67. ͨͱ͑͹
    • ετϦʔϜͷ༏ઌ౓
    • ϑϩʔ੍ޚ
    • HTTP/2࣌୅ͷυϝΠϯγϟʔσΟϯά
    • Smart Shadingͷݕ౼
    • ίωΫγϣϯ࠶ར༻ͱϫΠϧυΧʔυূ໌ॻ
    • 421 Misdirected Requestͷར༻΍OriginϑϨʔϜͷݕ౼
    • αʔόʔϓογϡͱϦόʔεϓϩΩγʔ
    • 103 Early Hintsͷར༻

    View full-size slide

  68. ࣮ࡍʹӡ༻͢ΔͱͳΔͱߟྀ
    ͢Δ͜ͱ͕͍ͬͺ͍

    View full-size slide

  69. ͕͍࣌ؒ͘Β͋ͬͯ΋ͨΓͳ
    ͍ͷͰࠓ೔͸Ұ୴͜͜·Ͱ

    View full-size slide

  70. ͜͜·Ͱͷ·ͱΊ
    • HTTP/1.1ͷϓϩτίϧΛվྑ͠ɺ͍͔ͭ͘ͷ
    େ͖ͳϘτϧωοΫΛղফ͢Δ͜ͱ͕Ͱ͖Δ
    Α͏ͳͬͨ
    • όΠφϦʹͳͬͨΓɺετϦʔϜ΍HPACKͳ
    Ͳ৽͍֓͠೦͕૿͑ͯͪΐͬͱෳࡶʹͳͬͨ

    View full-size slide

  71. PerlͰHTTP/2Λѻ͓͏

    View full-size slide

  72. PerlͰͷHTTP/2ͷରԠঢ়گ
    • http-perlͱProtocol::HTTP2 ͱ͍͏ϥΠϒϥ
    Ϧʔ͕͋Δ
    • http-perl͸h2-04ʢυϥϑτ4ʣͰ։ൃ͕ധ
    ·͍ͬͯΔ
    • Protocol::HTTP2 Ұ୒

    View full-size slide

  73. https://github.com/http2/http2-spec/wiki/Implementations

    View full-size slide

  74. ΄΅શͯͷػೳ͕
    ࣮૷͞Ε͍ͯΔʂʂ

    View full-size slide

  75. Protocol::HTTP2ͷಛ௃
    • TPCίωΫγϣϯͷ؅ཧ͸΍ͬͯ͘Εͳ͍ͷͰࣗ෼
    Ͱ΍Δඞཁ͕͋Δ
    • ετϦʔϜͷ؅ཧΛ΍ͬͯ͘ΕΔ
    • ϑϨʔϜ΍HTTPϔομʔͷencode/decode΋΍ͬ
    ͯ͘ΕΔ
    • LWP΍Furl΄Ͳ؆୯Ͱ͸ͳ͍ʂ

    View full-size slide

  76. ͱ͍͏Θ͚Ͱ࣮ࡍʹ࢖ͬͯΈ
    ·͠ΐ͏

    View full-size slide

  77. Protocol::HTTP2Λ࢖ͬͯΈΔ
    • Protocol::HTTP2::ClientͰHTTP/2ͳαʔόʔʹΞΫηεͯ͠ΈΔ
    • Protocol::HTTP2::ServerͰαʔόʔΛͨͯΔ
    • ฒྻϦΫΤετΛࢼ͢
    • αʔόʔϓογϡΛࢼ͢
    • PSGIͰHTTP/2
    • TLSͰૹड৴͢Δ

    View full-size slide

  78. Protocol::HTTP2::ClientͰ
    HTTP/2ͳαʔόʔʹΞΫηε
    ͯ͠ΈΔ

    View full-size slide

  79. ࠓճ͸
    ͏·͘ಈ͔ͳ͔ͬͨͷͰ
    ࠷ॳ͔ΒHTTP/2ͩͱΘ͔ͬͯ
    ͍ΔͷͰUpgradeͷॲཧ͸ε
    Ωοϓ͠·͢

    View full-size slide

  80. HTTP/2 ClientΛࢼ͢
    • ͱΓ͋͑ͣαʔόʔ͸ϩʔΧϧʹ nghttpd ͱ
    ͍͏΍ͭΛ —no_tls Ͱཱͯ·͢
    • ΧϨϯτσΟϨΫτϦͷϑΝΠϧΛදࣔͯ͘͠
    ΕΔͷͰద౰ʹ index.html ΛͰ্ͬͪ͛·͢
    • Protocol::HTTP2::ClientͰΞΫηεͯ͠Έ·͢

    View full-size slide

  81. nghttpdΛىಈ͢Δ
    $ echo 'Hello, HTTP/2!!' >! index.html # index.html Λ࡞͓ͬͯ͘
    $ nghttpd —no-tls -v 8080
    IPv6: listen :::8080
    IPv4: listen 0.0.0.0:8080

    View full-size slide

  82. ClientΦϒδΣΫτͷ࡞੒
    use Protocol::HTTP2::Client;
    use Protocol::HTTP2::Constant qw(constant_name);
    my $client = Protocol::HTTP2::Client->new(
    on_change_state => sub {
    my ($stream_id, $previous_state, $current_state) = @_;
    printf(
    "Stream %i changed state from %s to %s\n",
    $stream_id,
    const_name(states => $previous_state),
    const_name(states => $current_state),
    );
    },
    on_error => sub {
    my $error = shift;
    printf "Error occurred: %s\n", const_name(errors => $error);
    },
    );

    View full-size slide

  83. ϦΫΤετͷ࡞੒
    (͜ͷ࣌఺Ͱ͸·ͩϦΫΤετ͸ඈ͹ͳ͍)
    my $port = 80;
    my $host = ‘example.com';
    $client->request(
    # HTTP/2 headers
    ':scheme' => 'http',
    ':authority' => "$host:$port",
    ':path' => '/',
    ':method' => 'GET',
    # HTTP/1.1 headers
    headers => [
    'accept' => '*/*',
    'user-agent' => "perl-Protocol-HTTP2/$Protocol::HTTP2::VERSION",
    ],
    on_done => sub {
    my ($headers, $data) = @_;
    use Data::Dumper; warn Dumper [ $headers, $data ];
    },
    );

    View full-size slide

  84. tcpίωΫγϣϯΛுΔ
    use AnyEvent;
    use AnyEvent::Socket;
    use AnyEvent::Handler;
    my $w = AnyEvent->condvar;
    tcp_connect $host, $port, sub {
    my ($fh) = @_ or die “connection failed: $!”;
    my $handle; $handle = AnyEvent::Handle->new(
    fh => $fh,
    autocork => 1,
    on_error => sub {
    $_[0]->destroy;
    warn "connection error\n”
    $w->send;
    },
    on_eof => sub {
    $handle->destroy;
    $w->send;
    },
    );
    # ࣍ͷεϥΠυʹͭͮ͘
    };
    $w->recv;

    View full-size slide

  85. ϦΫΤετΛૹड৴͢Δ
    tcp_connect $host, $port, sub {

    # ϦΫΤετΛૹ৴
    while (my $frame = $client->next_frame) {
    $handle->push_write($frame);
    }
    # ϨεϙϯεΛॲཧ
    $handle->on_read(sub {
    my $handle = shift;
    $client->feed(delete $handle->{rbuf});
    while (my $frame = $client->next_frame) {
    $handle->push_write($frame);
    }
    $handle->push_shutdown if $client->shutdown;
    });
    };
    $w->recv;

    View full-size slide

  86. ΰϦΰϦͷAnyEventʂʂ

    View full-size slide

  87. ࣮ߦͯ͠Έ·͢
    $ perl no_tls_client.pl
    Stream 1 changed state from IDLE to HALF_CLOSED
    Stream 1 changed state from HALF_CLOSED to CLOSED
    [
    [
    ":status",
    "200",
    "server",
    "nghttpd nghttp2/1.30.0",
    "cache-control",
    "max-age=3600",
    "date",
    "Fri, 02 Mar 2018 11:03:24 GMT",
    "content-length",
    "16",
    "last-modified",
    "Fri, 02 Mar 2018 11:02:50 GMT"
    ],
    "Hello, HTTP/2!!\n"
    ]

    View full-size slide

  88. ͏·͍ͬͨͧ͘ʂʂʂ

    View full-size slide

  89. ϓϩάϥϜʹ౉ͬͯ͘Δϔο
    μʔ͸ͪΌΜͱಡΊΔײ͡Ͱ
    ͕͢ɺϦΫΤετத͸HPACK
    Ͱѹॖ͞Ε͍ͯ·͢

    View full-size slide

  90. ࣍͸
    Protocol::HTTP2::ServerͰ
    αʔόʔΛཱͯͯΈ·͠ΐ͏

    View full-size slide

  91. αʔόʔͷ࣮૷
    my $w = AnyEvent->condvar;
    tcp_server '127.0.0.1', 8080, sub {
    my ($fh, $peer_host, $peer_port) = @_;
    my $handle;
    $handle = AnyEvent::Handle->new(
    fh => $fh,
    autocork => 1,
    on_error => sub {
    my ($handle, $fatal, $message) = @_;
    $handle->destroy;
    say "connection error (fatal: $fatal, message: $message)";
    },
    on_eof => sub {
    $handle->destroy;
    },
    );
    # ࣍ͷεϥΠυ΁
    };
    $w->recv;

    View full-size slide

  92. αʔόʔͷ࣮૷
    tcp_server '127.0.0.1', 8080, sub {

    my $server;
    $server = Protocol::HTTP2::Server->new(
    on_request => sub {
    my ($stream_id, $headers, $data) = @_;
    my $message = "hello, world!";
    $server->response(
    ':status' => 200,
    stream_id => $stream_id,
    headers => [
    'server' => 'perl-Protocol-HTTP2/1.08',
    'content-length' => length($message),
    ],
    data => $message,
    );
    },
    );
    # ࣍ͷεϥΠυʹଓ͘
    };
    $w->recv;

    View full-size slide

  93. αʔόʔͷ࣮૷
    tcp_server '127.0.0.1', 8080, sub {

    while (my $frame = $server->next_frame) {
    $handle->push_write($frame);
    }
    $handle->on_read(sub {
    my $handle = shift;
    $server->feed($handle->{rbuf});
    $handle->{rbuf} = undef;
    while (my $frame = $server->next_frame) {
    $handle->push_write($frame);
    }
    $handle->push_shutdown if $server->shutdown;
    });
    };
    $w->recv;

    View full-size slide

  94. αʔόʔΛىಈͯ͠
    ϦΫΤετૹͬͯΈΔ
    $ perl no_tls_server.pl
    $ perl no_tls_client.pl
    Stream 1 changed state from IDLE to HALF_CLOSED
    Stream 1 changed state from HALF_CLOSED to CLOSED
    [
    [
    ":status",
    "200",
    "server",
    "perl-Protocol-HTTP2/1.08"
    ],
    "hello, world!"
    ]

    View full-size slide

  95. ΍ͬͨʔʂಈ͍ͨͧʂʂ

    View full-size slide

  96. HTTP/2Ͱ͸1ͭͷTCP্Ͱෳ
    ਺ͷετϦʔϜΛѻ͑ΔΜͰ
    ͨ͠

    View full-size slide

  97. ฒྻϦΫΤετΛࢼ͢
    • ΫϥΠΞϯτଆͰ͸request()Λෳ਺ճൃߦ͢Δ͜ͱͰෳ਺ͷ
    ετϦʔϜΛੜ੒͠ɺฒྻͰϦΫΤετΛૹ৴͢Δ͜ͱ͕Մೳ
    ʹͳΔ
    • ࠓճ͸ετϦʔϜ1Ͱ”dummy.iso”ͱ͍͏ͦΕͳΓͷαΠζͷ
    ϑΝΠϧΛऔಘ͠ɺετϦʔϜ3ͷ΄͏͕ૣ͘Ϩεϙϯε͕
    ฦͬͯ͘Δ͜ͱΛ֬ೝ͢Δ
    • ϦΫΤετͷετϦʔϜID͸ح਺ͳͷͰ1ͷ࣍͸3ʹͳΓ·
    ͢

    View full-size slide

  98. ฒྻϦΫΤετΛࢼ͢
    ʢΫϥΠΞϯτଆൈਮʣ
    $client->request( # ετϦʔϜ1
    # HTTP/2 headers
    ':scheme' => 'http',
    ':authority' => "$host:$port",
    ':path' => “/dummy.iso", # ڊେͳϑΝΠϧͷऔಘ
    ':method' => 'GET',

    )->request( # ετϦʔϜ3
    # HTTP/2 headers
    ':scheme' => 'http',
    ':authority' => "$host:$port",
    ':path' => "/",
    ':method' => 'GET',

    );

    View full-size slide

  99. ฒྻϦΫΤετΛࢼ͢
    ʢαʔόʔଆൈਮʣ
    on_request => sub {
    my ($stream_id, $headers, $data) = @_;
    my $header_map = { @$headers };
    if ($header_map->{':path'} eq '/') { # path ͰॲཧΛৼΓ෼͚Δ
    # લͱҰॹ
    }
    elsif ($header_map->{':path'} eq '/dummy.iso') {
    aio_load './dummy.iso', sub { # ಡΈࠐΈͰϒϩοΫ͠ͳ͍Α͏ʹ aio_load Λ࢖༻
    my ($data) = @_;
    $server->response(
    ':status' => 200,
    stream_id => $stream_id,
    headers => [
    'server' => 'perl-Protocol-HTTP2/1.08',
    'content-length' => length($data),
    ],
    data => $data,
    );
    };
    }
    },

    View full-size slide

  100. ࣮ࡍʹࢼͯ͠ΈΔ
    $ perl no_tls_server_multistream.pl
    $ perl no_tls_client_multistream.pl
    Stream 1 changed state from IDLE to HALF_CLOSED
    Stream 3 changed state from IDLE to HALF_CLOSED
    Stream 3 changed state from HALF_CLOSED to CLOSED
    [
    [
    ":status",
    "200",
    "server",
    "perl-Protocol-HTTP2/1.08",
    "content-length",
    "13"
    ]
    ]
    Stream 1 changed state from HALF_CLOSED to CLOSED
    [
    [
    ":status",
    "200",
    "server",
    "perl-Protocol-HTTP2/1.08",
    "content-length",
    "102400"
    ]
    ]

    View full-size slide

  101. ؆୯Ͱ͢Ͷʢʁʣ

    View full-size slide

  102. αʔόʔ࣮૷ͷ஫ҙ఺
    • αʔόʔʹؔͯ͠͸ී௨ʹHeaderΛνΣοΫͯͦ͠ΕͧΕͷॲཧΛॻ͍
    ͍ͯ͘͜ͱͰWebΞϓϦέʔγϣϯΛ͍··Ͱ௨Γʹ࣮૷ग़དྷ·͢Ͷ
    • ͨͩ͠ɺશͯͷϦΫΤετͰϒϩοΩϯά͠ͳ͍Α͏ʹࡉ৺ͷ஫ҙΛ෷
    ͏ඞཁ͕͋Δ
    • DB΍memcachedɺredisͳͲͷΞΫηε΍ϩάϑΝΠϧ΁ͷॻ͖ࠐ
    ΈͳͲ͢΂ͯAnyEvent΍CoroͳͲΛར༻ͯ͠ϒϩοΩϯά͠ͳ͍Α
    ͏ʹ͢Δ
    • ϛεΔͱશͯͷϦΫΤετ͕٧·Γ·͢

    View full-size slide

  103. ੈͷதͷϒϥ΢β͸h2Ͱ͔͠
    جຊతʹΞΫηεͯ͜͠ͳ͍
    ΜͰͨ͠

    View full-size slide

  104. ͳͷͰTLSʹରԠ͢Δඞཁ͕
    ͋Γ·͢

    View full-size slide

  105. TLSʹରԠ
    • ࠓճ͸Let’s EncryptͰ࡞੒ͨ͠ূ໌ॻΛར༻
    • ݸਓͰ͍࣋ͬͯΔυϝΠϯΛར༻͠ɺΠϯλʔωοτʹ
    ެ։ʂ
    • αʔόʔɺΫϥΠΞϯτͱ΋ʹίωΫγϣϯΛTLSʹରԠ
    ͤ͞Δ
    • ͲͪΒ΋AnyEvent::HandlerΛ࢖͍ͬͯΔͱ͜ΖΛվम

    View full-size slide

  106. TLSʹରԠ
    ʢαʔόʔฤʣ
    Net::SSLeay::initialize();
    tcp_server ‘127.0.0.1’, 443, sub {
    my ($fh, $peer_host, $peer_port) = @_;
    my $tls;
    eval {
    $tls = AnyEvent::TLS->new(
    method => 'TLSv1_2',
    cert_file => ‘/etc/letsencrypt/live/http2-test.api.moe/fullchain.pem’,
    key_file => ‘/etc/letsencrypt/live/http2-test.api.moe/privkey.pem’,
    );
    # ͜͜Ͱ҉߸εΠʔτΛબ୒͢Δ
    # ࣍ͷεϥΠυ΁
    };
    if ($@) {
    print "Some problem with SSL CTX: $@\n";
    $w->send;
    return;
    }

    View full-size slide

  107. TLSʹରԠ
    ʢαʔόʔฤʣ

    eval {

    # ECDH curve ( Net-SSLeay >= 1.56, openssl >= 1.0.0 )
    if (exists &Net::SSLeay::CTX_set_tmp_ecdh) {
    my $curve = Net::SSLeay::OBJ_txt2nid('prime256v1');
    my $ecdh = Net::SSLeay::EC_KEY_new_by_curve_name($curve);
    Net::SSLeay::CTX_set_tmp_ecdh( $tls->ctx, $ecdh );
    Net::SSLeay::EC_KEY_free($ecdh);
    }
    # ALPN (Net-SSLeay > 1.55, openssl >= 1.0.2)
    if (exists &Net::SSLeay::CTX_set_alpn_select_cb) {
    Net::SSLeay::CTX_set_alpn_select_cb( $tls->ctx,
    [Protocol::HTTP2::ident_tls] );
    }
    # NPN (Net-SSLeay > 1.45, openssl >= 1.0.1)
    elsif (exists &Net::SSLeay::CTX_set_next_protos_advertised_cb) {
    Net::SSLeay::CTX_set_next_protos_advertised_cb( $tls->ctx,
    [Protocol::HTTP2::ident_tls] );
    }
    };
    # ࣍ͷεϥΠυ΁

    View full-size slide

  108. TLSʹରԠ
    ʢαʔόʔฤʣ
    my $handle;
    $handle = AnyEvent::Handle->new(
    fh => $fh,
    tls => 'accept',
    tls_ctx => $tls,
    autocork => 1,
    on_error => sub {
    my ($handle, $fatal, $message) = @_;
    $handle->destroy;
    warn "connection error (fatal: $fatal, message: $message)";
    },
    on_eof => sub {
    $handle->destroy;
    },
    );

    View full-size slide

  109. ΊͪΌͪ͘Ό
    ढจͩΒ͚Ͱ͢Ͷʂʂ

    View full-size slide

  110. Ұ୴͜ΕͰىಈͯ͠Έͯcurl
    ͰΞΫηεͯ͠Έ·͠ΐ͏

    View full-size slide

  111. TLSʹରԠ͔ͨ֬͠ೝ
    $ curl -v —http2 https://http2-test.api.moe/
    தུ…
    * Using HTTP2, server supports multi-use
    * Connection state changed (HTTP/2 confirmed)
    * Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
    * Using Stream ID: 1 (easy handle 0x7ff59c00cc00)
    > GET / HTTP/2
    > Host: http2-test.api.moe
    > User-Agent: curl/7.54.0
    > Accept: */*
    >
    * Connection state changed (MAX_CONCURRENT_STREAMS updated)!
    < HTTP/2 200
    < server: perl-Protocol-HTTP2/1.08
    < content-length: 21
    < cache-control: max-age=3600
    < date: Fri, 02 Mar 2018 14:58:59 GMT
    < last-modified: Fri, 02 Mar 2018 14:58:59 GMT
    <
    * Connection #0 to host http2-test.api.moe left intact
    Hello, HTTP/2 World!!

    View full-size slide

  112. ͍͚ͨͬΆ͍Ͱ͢Ͷʂ

    View full-size slide

  113. ͭ͗͸ΫϥΠΞϯτଆ΋ରԠ
    ͠·͠ΐ͏

    View full-size slide

  114. TLSʹରԠ
    ʢΫϥΠΞϯτฤʣ
    Net::SSLeay::initialize();
    tcp_connect $host, $port, sub {
    my ($fh) = @_ or die "connection failed: $!";
    my $tls;
    eval {
    $tls = AnyEvent::TLS->new(method => ‘TLSv1_2’);
    # ALPN (Net-SSLeay > 1.55, openssl >= 1.0.2)
    if (exists &Net::SSLeay::CTX_set_alpn_protos) {
    Net::SSLeay::CTX_set_alpn_protos( $tls->ctx,
    [Protocol::HTTP2::ident_tls] );
    }
    # NPN (Net-SSLeay > 1.45, openssl >= 1.0.1)
    elsif (exists &Net::SSLeay::CTX_set_next_proto_select_cb) {
    Net::SSLeay::CTX_set_next_proto_select_cb( $tls->ctx,
    [Protocol::HTTP2::ident_tls] );
    }
    else {
    die "ALPN and NPN is not supported\n";
    }
    };
    # ࣍ͷεϥΠυ΁

    View full-size slide

  115. TLSʹରԠ
    ʢΫϥΠΞϯτฤʣ

    my $handle;
    $handle = AnyEvent::Handle->new(
    fh => $fh,
    tls => "connect",
    tls_ctx => $tls,
    autocork => 1,
    on_error => sub {
    $_[0]->destroy;
    print "connection error\n";
    $w->send;
    },
    on_eof => sub {
    $handle->destroy;
    $w->send;
    }
    );

    View full-size slide

  116. ΫϥΠΞϯτଆ΋΄΅αʔόʔ
    ͱҰॹͰ͢Ͷ

    View full-size slide

  117. ͜ΕͰΞΫηεͯ͠Έ·͢

    View full-size slide

  118. TLSʹରԠ͔ͨ֬͠ೝ
    $ perl tls_client.pl
    [/Users/shimada.yuji/misc/yapc-okinawa]
    Stream 1 changed state from IDLE to HALF_CLOSED
    Stream 1 changed state from HALF_CLOSED to CLOSED
    [
    [
    ":status",
    "200",
    "server",
    "perl-Protocol-HTTP2/1.08",
    "content-length",
    "21",
    "cache-control",
    "max-age=3600",
    "date",
    "Fri, 02 Mar 2018 15:24:03 GMT",
    "last-modified",
    "Fri, 02 Mar 2018 15:24:03 GMT"
    ],
    "Hello, HTTP/2 World!!"
    ]

    View full-size slide

  119. ͪΌΜͱΞΫηεͰ͖·ͨ͠
    Ͷʂʂ

    View full-size slide

  120. ͜ΕͰଞͷαΠτ΋ී௨ʹ
    HTTP/2ͰΞΫηεͰ͖ΔΑ͏
    ʹͳΓ·ͨ͠

    View full-size slide

  121. HTTP/2͔͠ରԠ͍ͯ͠ͳ͍α
    Πτ΋εΫϨΠϐϯά͠์୊
    Ͱ͢Ͷʁ

    View full-size slide

  122. ͜͜Ͱࣗ෼ͷ࡞ͬͨ
    Ϟδϡʔϧͷ঺հ

    View full-size slide

  123. Net::APNs::HTTP2

    View full-size slide

  124. Net::APNs::HTTP2
    • Appleͷϓογϡ௨஌Λαʔόʔ͔ΒૹΕΔ΍
    ͭ
    • ฒྻϦΫΤετΛ؆୯ʹߦ͏͜ͱ͕Ͱ͖Δ
    • ಺෦Ͱ͸Protocol::HTTP2::Clientͱ
    AnyEvent::TLSΛར༻

    View full-size slide

  125. ͜Μͳײ͡Ͱ࢖͑Δ(1)
    my $apns = Net::APNs::HTTP2->new(
    is_development => 1,
    auth_key => 'auth_key.p8',
    key_id => $key_id,
    team_id => $team_id,
    bundle_id => $bundle_id,
    );

    View full-size slide

  126. ͜Μͳײ͡Ͱ࢖͑Δ(2)
    while (1) { # ͜Ε͸ͳʹ͔͠Βͷαʔόʔͱ͔ϫʔΧʔͰӬଓతʹಈ࡞͍ͯ͠Δͱࢥ͍ͬͯͩ͘͞
    $apns->prepare($device_token, {
    aps => {
    alert => 'some message',
    badge => 1,
    },
    }, sub {
    my ($header, $content) = @_;
    # $header = [
    # ":status" => "200",
    # "apns-id" => "82B34E17-370A-DBF4-5046-FF56A4EA1FAF",
    # ];
    ...
    });
    # You can chainged
    $apns->prepare(...)->prepare(...)->prepare(...);
    # send all prepared requests in parallel
    $apns->send;
    # do something
    }
    # must call `close` when finished
    $apns->close;

    View full-size slide

  127. Net::APNs::HTTP2
    • version 0.01͚ͩͲී௨ʹϓϩμΫγϣϯͰಈ
    ͍ͯ·͢
    • ຖ೔਺ඦ݅Ҏ্ͷϓογϡ௨஌Λݩؾʹૹ৴த
    • ͥͻ࢖ͬͯΈ͍ͯͩ͘͞ʂʂ
    • ϑΟʔυόοΫ΋͓Ͷ͕͍͠·͢ʂʂ

    View full-size slide

  128. ͦΖͦΖαʔόʔϓογϡΛ
    ࣮૷ͯ͠Έ·͠ΐ͏

    View full-size slide

  129. αʔόʔϓογϡΛ࣮૷͢Δ
    • “/push.html”ʹϦΫΤετΛߦ͏ͱ”/style.css”͕αʔ
    όʔϓογϡ͞ΕΔΑ͏ʹ͢Δ
    • มߋ͢Δ৔ॴ͸ on_request() ͷதͷΈ
    • push() ͸ response() ΑΓ΋ઌʹهड़͠ͳ͚Ε͹ͳΒͳ͍
    • ChromeͰΞΫηε͠style.cssͷinitiatorʹ”Push”ͱग़ͯ
    ͍ͨΒ੒ޭ

    View full-size slide

  130. αʔόʔϓογϡͷ࣮૷
    if ($header_map->{':path'} eq '/push.html') {
    $server->push(
    ':authority' => $host . ':' . $port,
    ':method' => 'GET',
    ':path' => '/style.css',
    ':scheme' => 'https',
    stream_id => $stream_id,
    );
    aio_load './push.html', sub {
    my ($data) = @_;
    $server->response(
    ':status' => 200,
    stream_id => $stream_id,
    headers => [
    'server' => 'perl-Protocol-HTTP2/1.08',
    'content-length' => length($data),
    'content-type' => 'text/html',
    ],
    data => $data,
    );
    };
    }
    elsif ($header_map->{':path'} eq '/style.css') { # ࣍ͷεϥΠυ }

    View full-size slide

  131. αʔόʔϓογϡͷ࣮૷
    elsif ($header_map->{':path'} eq '/style.css') {
    aio_load './style.css', sub {
    my ($data) = @_;
    $server->response(
    ':status' => 200,
    stream_id => $stream_id,
    headers => [
    'server' => 'perl-Protocol-HTTP2/1.08',
    'content-length' => length($data),
    'content-type' => 'text/css',
    ],
    data => $data,
    );
    };
    }

    View full-size slide

  132. Time͕1msʹͳ͍ͬͯΔʂʂ
    ※ࠓճ͸cacheपΓͷϔομʔΛೖΕ͍ͯͳ͍ͷͰcss͕ڧ͘
    Ωϟογϡ͞Εͯ͠·͏ͨΊγʔΫϨοτϞʔυਪ঑

    View full-size slide

  133. ଓ͍ͯΫϥΠΞϯτଆΛ࣮૷
    ͠·͢

    View full-size slide

  134. αʔόʔϓογϡͷड৴
    • Protocol::HTTP2::ClientͷΠϯελϯε࡞੒࣌
    ʹ on_push() Λࢦఆ͢Δ͜ͱͰ
    PUSH_PROMISEΛड͚औΔ͜ͱ͕Ͱ͖Δ
    • ίʔϧόοΫΛฦ͢͜ͱͰσʔλΛड৴Ͱ͖Δ
    • undef Λฦͨ͠ΒΩϟϯηϧѻ͍

    View full-size slide

  135. αʔόʔϓογϡͷड৴
    my $client = Protocol::HTTP2::Client->new(
    on_push => sub {
    my ($push_headers) = @_;
    print "Server want to push some resource to us\n”;
    return sub {
    my ($headers, $data) = @_;
    print "Received promised resource\n";
    };
    },
    on_change_state => sub {
    },
    on_error => sub {
    },
    );

    View full-size slide

  136. ͨͬͨ͜Ε͚ͩʂ

    View full-size slide

  137. ࣮ࡍʹࢼͯ͠ΈΔ
    $ perl tls_client_server_push.pl
    Stream 1 changed state from IDLE to HALF_CLOSED
    Stream 2 changed state from IDLE to RESERVED
    Server want to push some resource to us
    Stream 1 changed state from HALF_CLOSED to CLOSED
    [
    [ தུ ],
    "\n \n HTTP/2 Server Push Test\n \n \n \n
    Server Push Test\n \n"
    ]
    Stream 2 changed state from RESERVED to HALF_CLOSED
    Stream 2 changed state from HALF_CLOSED to CLOSED
    Received promised resource
    $VAR1 = [
    [
    ':status',
    '200',
    'server',
    'perl-Protocol-HTTP2/1.08',
    'content-length',
    '26',
    'content-type',
    'text/css'
    ],
    '.push {
    color: red;
    }
    '
    ];

    View full-size slide

  138. ͪΌΜͱड৴Ͱ͖ͯ·͢Ͷʂʂ

    View full-size slide

  139. ࠷ޙʹPSGIͰHTTP/2ʹରԠ
    ͢Δํ๏Λ঺հ͠·͢

    View full-size slide

  140. ͱ͍ͬͯ΋ͱͬͯ΋؆୯

    View full-size slide

  141. Protocol::HTTP2ͱಉ͡࡞ऀ
    ͕࡞͍ͬͯΔ”Shuvgey”Λ࢖
    ͏͚ͩͰ͢

    View full-size slide

  142. Shuvgeyͷ࢖͍ํ
    $ shuvgey --listen :8000 --tls_key=cert.key --tls_crt=cert.crt
    app.psgi

    View full-size slide

  143. ͨͬͨ͜Ε͚ͩͰPSGIରԠͷ
    HTTP2αʔόʔ্ཱ͕͕ͪΔ
    ͧʂʂʂ

    View full-size slide

  144. ϦΫΤετͯ͠ΈΔ
    ʢࠓճ͸ —no_tls Ͱʣ
    $ shuvgey —listen 8080 —no_tls app.psgi
    $ perl no_tls_client.pl
    Stream 1 changed state from IDLE to HALF_CLOSED
    Stream 1 changed state from HALF_CLOSED to CLOSED
    [
    [
    ":status",
    "200",
    "content-type",
    "text/plain",
    "content-lenth",
    "13",
    "server",
    "Shuvgey/0.09"
    ],
    "hello, world!"
    ]

    View full-size slide

  145. ؆୯Ͱ͢Ͷʂʂ

    View full-size slide

  146. APIαʔόʔͱ͔ͩͬͨΒ͜
    ΕΛ࢖͏ͱָͪΜͰ͢Ͷ

    View full-size slide

  147. ͜͜·Ͱͷ·ͱΊ
    • Protocol::HTTP2Λ࢖͑͹PerlͰ΋όϦόϦ
    HTTP/2Λ஻Δ͜ͱ͕Ͱ͖Δ
    • ͱ͸͍͑AnyEventͳͲΛར༻ͨ͠Πϕϯτۦ
    ಈͳϓϩάϥϛϯάεΩϧ͕ඞਢ
    • ShuvgeyΛ࢖͑͹؆୯ʹPSGI͕஻ΕΔ

    View full-size slide

  148. ͓·͚: gRPCͱPerl

    View full-size slide

  149. ݱঢ়·ͱ΋ʹಈ࣮͘૷͸ͳ͍
    ͱ͓΋ΘΕΔ

    View full-size slide

  150. ࣮૷ࣗମ͸͋Δ
    • Grpc::XS
    • gRPCͷC++ͷόΠϯσΟϯά
    • Google::Protocol::Buffer::Dynamic
    • ϓϩτίϧόοϑΝʔͷC++ͷόΠϯσΟϯά
    • protoxs-perl
    • protocͰperlΛग़ྗͰ͖ΔΑ͏ʹ͢Δ΋ͷ

    View full-size slide

  151. ࣮૷ࣗମ͸͋Δ
    • Grpc::XS
    • ࠷৽ͷϓϩτίϧόοϑΝʔͰϏϧυͰ͖ͳ͍
    • ϏϧυͰ͖Δ؀ڥͱόʔδϣϯ͕ෆ໌
    • Google::Protocol::Buffer::Dynamic
    • ࠷৽ͷϓϩτίϧόοϑΝʔͰϏϧυͰ͖ͳ͍
    • ϏϧυͰ͖Δ؀ڥͱόʔδϣϯ͕ෆ໌
    • protoxs-perl
    • ߋ৽͕10೥લ͔Β͋Δྺ࢙͋ΔϞδϡʔϧ
    • proto2·Ͱ͔͠ରԠ͍ͯ͠ͳ͍

    View full-size slide

  152. ͱ͍͏Θ͚Ͱ

    View full-size slide

  153. ༗ࣝऀͷํɺ࢖͍ํڭ͑ͯ͘
    ͍ͩ͞ʂʂ

    View full-size slide

  154. ͨͩɺ࢓ࣄͰPerlͰgRPC࢖͏
    ؾ͕͠ͳ͍

    View full-size slide

  155. ·ͱΊ
    • HTTP/2͸HTTP/1.1ͷϓϩτίϧ্ͷϘτϧωοΫΛղ
    ফ͍͍ͯͬͯ͠Δ
    • ·ͩ·ͩ࠷దԽͷٞ࿦͸ଓ͍͍ͯΔ
    • PerlͰ΋HTTP/2͸όϦόϦ࢖͑Δ
    • ͨͩ͠ɺ͢΂ͯΠϕϯτۦಈͩ
    • gRPCϥΠϒϥϦʔɺGoogle͞Μग़͍ͯͩ͘͠͞

    View full-size slide

  156. ͝ਗ਼ௌ
    ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂʂ

    View full-size slide