2022/9/22 Rack3を読む
onk.icon 突発単独開催
code:sh
$ gem list "^rack$" -ra
Rack (2.0.0, 1.1.3, 1.1.2, 1.1.1)
rack (3.0.0, 2.2.4, 2.2.3.1, 2.2.3, 2.2.2, 2.2.1, 2.2.0, 2.1.4.1, 2.1.4, 2.1.3, 2.1.2, 2.1.1, 2.1.0, 2.0.9.1, 2.0.9, 2.0.8, 2.0.7, 2.0.6, 2.0.5, 2.0.4, 2.0.3, 2.0.2, 2.0.1, 1.6.13, 1.6.12, 1.6.11, 1.6.10, 1.6.9, 1.6.8, 1.6.7, 1.6.6, 1.6.5, 1.6.4, 1.6.3, 1.6.2, 1.6.1, 1.6.0, 1.5.5, 1.5.4, 1.5.3, 1.5.2, 1.5.1, 1.5.0, 1.4.7, 1.4.6, 1.4.5, 1.4.4, 1.4.3, 1.4.2, 1.4.1, 1.4.0, 1.3.10, 1.3.9, 1.3.8, 1.3.7, 1.3.6, 1.3.5, 1.3.4, 1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.8, 1.2.7, 1.2.6, 1.2.5, 1.2.4, 1.2.3, 1.2.2, 1.2.1, 1.2.0, 1.1.6, 1.1.5, 1.1.4, 1.1.3, 1.1.2, 1.1.1, 1.1.0, 1.0.1, 1.0.0, 0.9.1, 0.9.0, 0.4.0, 0.3.0, 0.2.0, 0.1.0)
たぶん 2.2.1 あたりでブランチ分かれてるけどまぁ 2.2.4 からの差分で見るか
とりあえず CHANGELOG
Extract rackup command, Rack::Server, Rack::Handler and related code into a separate gem. (#1937, @ioquatix)
へー
BREAKING CHANGE: Query parsing now treats parameters without = as having the empty string value instead of nil value, to conform to the URL spec. (#1696, @jeremyevans)
= 付きだと空文字を返すのは妥当 of 妥当
= なしでも空文字なのは、URI spec に書いてあるトノコト
ライブラリ間に差があって割と面白い
Removed antiquated handlers: FCGI, LSWS, SCGI, Thin. (#1658, @ioquatix)
diff 見て一瞬 CGI も消えたのかと思って焦った
Removed options from Rack::Builder.parse_file and Rack::Builder.load_file. (#1663, @ioquatix)
options 渡せたのをそもそも知らなかった
おや
Use lower case cookie attributes when creating cookies, and fold cookie attributes to lower case when reading cookies (specifically impacting secure and httponly attributes). (#1849, @ioquatix)
これアップグレード時に問題起きないのかな?
Set-Cookie 時に小文字で渡されるだけか。じゃあ大丈夫そう
Do not use semicolon as GET parameter separator. (#1733, @jeremyevans)
ワロス
proxy が ; 区切りに対応していないとキャッシュポイズニングになるよ、そして対応していない proxy は多いよトノコトだが、これ悪いの proxy 側じゃない???
この程度なら、なんかサクサク上げられそうな気がする
いいファイルあるじゃん
rackup gem が分かれた理由説明してある
Previously, the rackup executable was included with Rack.
Because WEBrick is no longer a default gem with Ruby, we had to make a decision: either rack should depend on webrick or we should move that functionality into a separate gem.
We chose the latter which will hopefully allow us to innovate more rapidly on the design and implementation of rackup separately from "rack the interface".
rackup、WEBrick に限らないはずなんだけどなぁ
けど結局 webrick は依存に追加されてるな
全体的に stream 対応が一番大きそうな雰囲気
each をいきなり回しちゃダメ (stream かもしれないから)
compare 見ていく
CircleCI => GitHub Actions
actions/dependency-review-action へぇ
permissions 指定必要なんだっけ
You can use permissions to modify the default permissions granted to the GITHUB_TOKEN, adding or removing access as required, so that you only allow the minimum required access. For more information, see "Authentication in a workflow." リンク先見るとそこそこ read/write なので減らすのは理解できる
If you specify the access for any of these scopes, all of those that are not specified are set to none.
まぁそうか
read-all じゃなくて contents: read な理由は分からんが、最小権限で困らないならその方が望ましそう
bake とは
え、面白い。依存先のリポジトリのテストを実行できる
ロゴ変わってる
:nocov: の指定は?
たぶんこの中よな
simplecov が実行される
あれ、simplecov いつの間にか org 化してるな
以前は colszowka のリポジトリだった
こういう diff 多いな
code:diff
-status, headers, body = @app.call(env)
+status, headers, body = response = @app.call(env)
そして response[2] = new_body している
Regarding performance, with a sever like Puma handling 8 simultaneous requests, this is not a big deal. But for a server like falcon handling 1000s of simultaneous requests, this can be an issue. So performance in this regard is context sensitive.
In my benchmarks, I've seen a single trivial request create tons of strings, arrays and hash instances per request which are ultimately garbage - so I think there is a valid case to be made here.
この影響で response (と headers) が non-frozen を要求することになったのか
sprintf 面白い
松田さん、どこでこういう問題見つけてくるんだろう
RFC 7239 対応
X-Forwarded-* じゃなく Forwarded
Forwarded: for=192.0.2.43,for="[2001:db8:cafe::17]",for=unknown
へぇ
2.4 未満対応のために refinements で Regexp.match? を実装していた
match? に置き換える PR 来て面倒だったんだろうな。。
warn の uplevel 引数知らなかった、便利!
なんかファイルのパーミッションが 755 になってるな
多分意図してないので PR チャンス
autoload になったり require_relative になったり
いい議論だな
rack.input が rewindable じゃなくなった背景
途中で @janko 出てくるのさすがだなって思った
Rack::RewindableInput::Middleware 誕生
レスポンスヘッダの key が lowercase になった背景
HTTP/2 ナルホドね
互換性のために自動で lowercase にしてくれる Hash のようなクラス Rack::Headers 誕生
レスポンスヘッダの value が配列になった
逆に言うと key は unique である
Set-Cookie のためにレスポンスヘッダそのものを配列にしてきた気がしたけど、気のせいなのかなぁ?
ココで value を複数行文字列に変えている
ヘッダ自体は hash であったかー
Plack が Array なのだった。記憶の混同
さすが Jeremy Evans だぜ
lib/rack/mime.rb 画像系が増えてる
webp はご存じのヤツ
heic, heif は iPhone のヤツ
flif なるほど?
ReDos 対応
lib/rack/multipart/* はゴリゴリリファクタされてる
ws, wss が追加されている
reverse proxy で wss の ssl 処理したときに x-forwarded-proto を上手く扱えていない、のかな
お、Exception#detailed_message だ
しかし ShowException 面白いな
code:ruby
# This double assignment is to prevent an "unused variable" warning.
# Yes, it is dumb, but I don't like Ruby yelling at me.
path = path = (req.script_name + req.path_info).squeeze("/")
この path はこの後 erb に binding を渡して使われるので、メソッド内では確かに未使用
TempfileReaper へえ
存在を知らなかったが、Rails にはデフォルトで入っていた
こんなところに pocke さん
Decrease default allowed parameter recursion level from 100 to 32. (#1640, @jeremyevans)
は stack level too deep 対策だった
実際 100 レベル絶対必要無い
OpenSSL の secure_compare が使える場合は使う
しかし :nocov: こういう書き方するんだ
if は :nocov: 対象で、いきなり else から始まるのだいぶ面白い
カバレッジの詳細ちゃんと知らないんだなぁ……
Module#deprecate_constant 知らなかった!