Fake response for dealing with file:/// requests
# File lib/mechanize/file_response.rb, line 35 35: def [](key) 36: return nil if key.casecmp('Content-Type') != 0 37: return 'text/html' if directory? 38: return 'text/html' if ['.html', '.xhtml'].any? { |extn| 39: @file_path.end_with?(extn) 40: } 41: nil 42: end
# File lib/mechanize/file_response.rb, line 24 24: def code 25: File.exist?(@file_path) ? 200 : 404 26: end
# File lib/mechanize/file_response.rb, line 28 28: def content_length 29: return dir_body.length if directory? 30: File.exist?(@file_path) ? File.stat(@file_path).size : 0 31: end
# File lib/mechanize/file_response.rb, line 33 33: def each_header; end
# File lib/mechanize/file_response.rb, line 47 47: def get_fields(key) 48: [] 49: end
# File lib/mechanize/file_response.rb, line 51 51: def http_version 52: '0' 53: end
# File lib/mechanize/file_response.rb, line 55 55: def message 56: File.exist?(@file_path) ? 'OK' : 'Not Found' 57: end
# File lib/mechanize/file_response.rb, line 11 11: def read_body 12: raise Mechanize::ResponseCodeError.new(self) unless 13: File.exist? @file_path 14: 15: if directory? 16: yield dir_body 17: else 18: open @file_path, 'rb' do |io| 19: yield io.read 20: end 21: end 22: end
# File lib/mechanize/file_response.rb, line 65 65: def dir_body 66: body = ]<html><body>] 67: body.concat Dir[File.join(@file_path, '*')].map { |f| 68: "<a href=\"file://#{f}\">#{File.basename(f)}</a>" 69: } 70: body << ]</body></html>] 71: 72: body = body.join "\n" 73: body.force_encoding Encoding::BINARY if body.respond_to? :force_encoding 74: body 75: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.