Class: TDiary::Rack::ValidRequestPath

Inherits:
Object
  • Object
show all
Defined in:
lib/tdiary/rack/valid_request_path.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ValidRequestPath

Returns a new instance of ValidRequestPath.



4
5
6
# File 'lib/tdiary/rack/valid_request_path.rb', line 4

def initialize( app )
	@app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tdiary/rack/valid_request_path.rb', line 8

def call( env )
	valid_paths = [
		%r{^/$},
		%r{^/index\.(rb|cgi)$},
		%r{^/([0-9\-p]+)\.html$}
	]
	valid_paths.each do |path|
		return @app.call(env) if env['PATH_INFO'].match(path)
	end

	body = "Not Found: #{env['PATH_INFO']}"
	if env["REQUEST_METHOD"] == "HEAD"
		[404, {'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s}, []]
	else
		[404, {'Content-Type' => 'text/plain'}, [body]]
	end
end