Fake response for dealing with file:/// requests
# File lib/mechanize/file_response.rb, line 6 def initialize(file_path) @file_path = file_path @uri = nil end
# File lib/mechanize/file_response.rb, line 35 def [](key) return nil if key.casecmp('Content-Type') != 0 return 'text/html' if directory? return 'text/html' if ['.html', '.xhtml'].any? { |extn| @file_path.end_with?(extn) } nil end
# File lib/mechanize/file_response.rb, line 24 def code File.exist?(@file_path) ? 200 : 404 end
# File lib/mechanize/file_response.rb, line 28 def content_length return dir_body.length if directory? File.exist?(@file_path) ? File.stat(@file_path).size : 0 end
# File lib/mechanize/file_response.rb, line 44 def each end
# File lib/mechanize/file_response.rb, line 33 def each_header; end
# File lib/mechanize/file_response.rb, line 47 def get_fields(key) [] end
# File lib/mechanize/file_response.rb, line 51 def http_version '0' end
# File lib/mechanize/file_response.rb, line 55 def message File.exist?(@file_path) ? 'OK' : 'Not Found' end
# File lib/mechanize/file_response.rb, line 11 def read_body raise Mechanize::ResponseCodeError.new(self) unless File.exist? @file_path if directory? yield dir_body else open @file_path, 'rb' do |io| yield io.read end end end
# File lib/mechanize/file_response.rb, line 59 def uri @uri ||= URI "file://#{@file_path}" end