Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Plug & WAF
Search
ohr486
February 27, 2022
Programming
570
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Plug & WAF
https://beam-lang.connpass.com/event/240399/
ohr486
February 27, 2022
More Decks by ohr486
See All by ohr486
負荷試験Night#1 負荷試験2023年トレンド
ohr486
17
4.9k
Elixir/PhoenixによるWeb開発の現場から
ohr486
1
670
Hacking Phoenix Performance
ohr486
1
430
elixirをプロダクションに導入する
ohr486
1
760
IEx maniacs
ohr486
4
700
Hack and Read Elixir
ohr486
2
830
Running App on AppRunner
ohr486
0
880
sponsor-talk-drecom-heisei-ruby-kaigi
ohr486
0
930
ex-app-on-k8s
ohr486
0
280
Other Decks in Programming
See All in Programming
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.4k
AI活用は、個人から組織へ|マルチプレイヤーエージェントハーネス「QM」の社内活用事例 / AI use is moving from individuals to orgs
rkaga
1
260
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
350
スマート反転とウェブアクセシビリティ
camiha
0
210
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
110
iOSDC2026登壇資料.pdf
riofujimon
0
190
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
360
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
300
The Rails Doctrine Decade
koic
2
390
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
140
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
320
速習iPhone Duo対応
yuukiw00w
2
830
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
530
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
540
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
The Cult of Friendly URLs
andyhume
79
7k
My Coaching Mixtape
mlcsv
0
330
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
3
4.3k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
Chasing Engaging Ingredients in Design
codingconduct
0
340
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
250
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
260
Transcript
Plug & WAF 2022-02-27 tokyo.ex #16
agenda • About Me • ゴール • WAFとは何か • Webアプリ(MVC)の構造
• 何故Plugが必要なのか • Plugの構造 • Plugのインターフェース • Plugのデータフロー • DEMO • まとめ
About Me • おーはら / Twitter: @ohrdev / Github: ohr486
• 株式会社ドリコム SRE部 部長 ◦ Work: ▪ エンジニアマネージャ • 技術戦略の策定/推進 • エンジニア採用/採用戦略策定 ▪ サーバー/インフラエンジニア • 開発現場でゲームのバックエンド (Rails/Phoenix/Go/HCL)のコード書いてます ▪ 新規事業/ディレクター • 負荷試験支援/DevOps推進支援/設計コンサル • Community ◦ tokyo.ex / Japan Elixir Association / Erlang&Elixir Fest • Hobby ◦ 仏像制作 ◦ 自転車
ゴール • ターゲット ◦ Plugが何をしているか理解したい人 ◦ 何故Plugがあるかを理解したい人 ◦ PhoenixとPlugの関係について理解したい人 •
ゴール ◦ (Phoenixを含む)WAFの構造について理解する ◦ Plugの構造について理解する ◦ PhoenixとPlugの関係について理解する
WAFとは何か • WAF = Web Application Framework ◦ elixir ->
phoenix ◦ ruby -> rails ◦ python -> django • Webアプリを作るためのフレームワーク ◦ webアプリとは? ▪ インターネット/ネットワークを介して利用するアプリケーション ▪ ここでは、webブラウザ上で動作するという前提で進めます ◦ ex) wiki, blog, 掲示板, ECサイト, etc
Webアプリ(MVC)の構造 Webサーバー Webアプリ データベース Nginx Apache Cowboy etc プロトコル HTTP
WebSocket Phoenix Rails Django etc MySQL PostgreSQL Spanner etc DB I/F Ecto ActiveRecord etc WAF I/F Plug Rack WSGI etc cowboy Plug Phoenix Endpoint Router Pipeline Controller View Template Ecto DB View Controller Model
何故Plugが必要なのか • 歴史的背景 ◦ WAFの乱立とWebサーバーの多様化により、 WAFとWebサーバーの接続部分の組み合わせ爆発 が発生し、全ての接続を網羅するのが難しくなった ◦ この問題を解決する為、 WAFとWebサーバーの統一的な
I/Fを定めた仕様が策定された ◦ WAF,Webサーバー共に、この I/Fに対応すればどの組み合わせの接続も担保できる WAF1 WAF2 WAF3 フレームワーク Webサーバー Apache nginx lighttpd … … WAF1 WAF2 WAF3 フレームワーク Webサーバー Apache nginx lighttpd 共通のI/F Phoenix cowboy Plug Rails nginx Rack
Plugの構造 cowboy Plug(I/F) Phoenix Endpoint Router Pipeline Controller View Template
HTTPコネクションのリク エスト/レスポンスを抽象 化した構造体 %Plug.Conn %Plug.Conn Plug %Plug.Conn HTTP Request HTTP Response Plug Plug Plug Plug PhoenixではPlugとして実 装されている Plug Plug Conn Conn’ Conn’’ Plugとは Connを受け取り、Connの内 部情報を更新して返却するモ ジュール/関数 pipeline
Plugのインターフェース • Plugは以下の2つに分類される ◦ Function Plugs ◦ Module Plugs ◦
これらのPlugはplugマクロを使って、コントローラー層/Routerに差し込まれる ▪ https://github.com/ohr486/tokyoex_16_sample/blob/main/plug_sample/lib/plug_sample/router.ex#L8-L12 • Function Plugs ◦ Plug.Connとオプションを引数にとり、Plug.Connを返却する関数 ▪ (Plug.Conn.t, Plug.opts) :: Plug.Conn.t ◦ https://github.com/ohr486/tokyoex_16_sample/blob/main/plug_sample/lib/plug_sample/router.ex#L31 • Module Plugs ◦ 以下の2つの関数をexportするモジュール ▪ init/1 : 引数のオプションを使って自身を初期化する関数、 コンパイル時に実行される ▪ call/2 : Plug.Connとオプションを引数にとり、Plug.Connの内部情報を更新して返却する関数 ◦ https://github.com/ohr486/tokyoex_16_sample/blob/main/plug_sample/lib/plug_sample/module_plug.ex
Plugのデータフロー Func Plug Module Plug Conn Conn’ Conn’’ HTTP Request
HTTP Response func_plug(conn, opts) ModulePlug.call(conn’, opts) ModulePlug.init(opts) compile時に呼出 defmodule MyAppMod.Router do use Plug.Router … plug :func_plug plug ModulePlug … end Plug.Routerによる定義 plugを通過する際に呼出 plugを通過する際に呼出
DEMO サンプルコード https://github.com/ohr486/tokyoex_16_sample/tree/main/plug_sample
まとめ • WAFとPlugの構造について紹介しました • 何故Plugが必要なのかについて紹介しました • PhoenixのRoutingやHTTP層の実装のCodeReadingをする際、%Plug.Connの データ構造を追っていくと理解しやすいです • 独自実装のカスタムPlugは簡単に作成できます、PlugはHTTPリクエスト/レスポン
スのデータ構造をダイレクトに操作できるので非常に強力で有用です