File: head.rb

package info (click to toggle)
ruby-rack 1.5.2-3%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 1,340 kB
  • ctags: 968
  • sloc: ruby: 12,617; sh: 12; makefile: 5
file content (22 lines) | stat: -rw-r--r-- 405 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module Rack

class Head
  # Rack::Head returns an empty body for all HEAD requests. It leaves
  # all other requests unchanged.
  def initialize(app)
    @app = app
  end

  def call(env)
    status, headers, body = @app.call(env)

    if env["REQUEST_METHOD"] == "HEAD"
      body.close if body.respond_to? :close
      [status, headers, []]
    else
      [status, headers, body]
    end
  end
end

end