LoginSignup
1
1

More than 5 years have passed since last update.

mrubyがバンドルされたh2oで画像を表示する

Last updated at Posted at 2015-09-11

mrubyのAPIがRackベースに変更

にてAPIがRackに変更された。

任意のコンテンツタイプの指定が可能になっている

当初は、レスポンスを返す際の実装が

h2o_send_error

を使って行われており。コンテンツタイプがtext/html固定だった。

これが、Rack APIベースになって実装が変更され、任意のコンテンツタイプの
指定が可能になっている。

画像を表示する

hello.rb
Proc.new do |env|
  c=""
  File.open("test.jpg") {|f| c = f.read}

  [200, {"content-type" => "image/jpeg"}, [c]]
end

ちなみにカレントディレクトリはh2oを実行したディレクトリになる。

test.jpgをそこに置く。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1