Help us understand the problem. What is going on with this article?

Padrino アプリケーションに積まれた Rack Middleware を確認する

More than 5 years have passed since last update.
$ padrino -v
Padrino v. 0.11.1
$ padrino g project my_project

明示的に use で積んだミドルウェアはMyProject::App.middleware
で確認できますが、デフォルトで積まれるミドルウェアはそこには表示されません。

そこで、確認用のRakeタスクを作成してみました。

stacked_middlewares.rake

Usage:

$ pwd
/my_project
$ mkdir tasks
$ wget https://gist.github.com/tyabe/5518782/raw/9e2751b072b044e4b8ae6fa3acedf46f7c3d2221/stacked_middlewares.rake -P tasks/
$ rake middleware
Application: MyProject::App
    Rack::Session::Cookie
    Padrino::ShowExceptions
    Padrino::Logger::Rack
    Padrino::Reloader::Rack
    Rack::MethodOverride
    Rack::Head
    Rack::Protection::FrameOptions
    Rack::Protection::AuthenticityToken

なお、実際にどのような順番で call されていくかは、@udzura さんの書かれた[Rack Middleware たちがどのように呼ばれるかを見てみよう(e.g. Sinatra)]が参考になります。

これらを使って確認してみたところ、Padrino内でレシーバの異なる use は以下の順番で使われる様です。

  1. Padrino.use
  2. default middlewares
  3. Padrino::Application.use
  4. MyProject::App.use

例外が発生した場合はこの逆順で伝搬されるので、例外をキャッチするようなミドルウェアを書いた場合には、どのレシーバを使って積むのが良いかを気にする必要がありそうですね。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away