# = HTTP utilities collection # # Some older functionality is removed, use open-uri instead. # # code:: tml, drak, ekarak # # (c) 2004 Navel, all rights reserved. # $Id: http.rb 71 2004-10-18 10:50:22Z gmosx $ require "uri" require "cgi" require "net/http" module N module HTTP # HTTP protocol EOL constants CR = "\x0d" LF = "\x0a" CRLF = "\x0d\x0a" EOL = CRLF # Http protocol status codes maps. # constants for readable code STATUS_OK = 200 STATUS_PARTIAL_CONTENT = 206 STATUS_MOVED = 301 STATUS_REDIRECT = 302 STATUS_SEE_OTHER = 303 # gmosx: VERIFY THIS STATUS_SEE_OTHER_307 = 307 # gmosx: VERIFY THIS STATUS_NOT_MODIFIED = 304 STATUS_BAD_REQUEST = 400 STATUS_AUTH_REQUIRED = 401 STATUS_FORBIDDEN = 403 STATUS_NOT_FOUND = 404 STATUS_METHOD_NOT_ALLOWED = 405 STATUS_NOT_ACCEPTABLE = 406 STATUS_LENGTH_REQUIRED = 411 STATUS_PRECONDITION_FAILED = 412 STATUS_SERVER_ERROR = 500 STATUS_NOT_IMPLEMENTED = 501 STATUS_BAD_GATEWAY = 502 STATUS_VARIANT_ALSO_VARIES = 506 # hash to allow id to description maping. STATUS_STRINGS = { 200 => "OK", 206 => "Partial Content", 300 => "Multiple Choices", 301 => "Moved Permanently", 302 => "Found", 303 => "See other", # gmosx: VERIFY THIS 304 => "Not Modified", 307 => "See other 07", # gmosx: VERIFY THIS 400 => "Bad Request", 401 => "Authorization Required", 403 => "Forbidden", 404 => "Not Found", 405 => "Method Not Allowed", 406 => "Not Acceptable", 411 => "Length Required", 412 => "Rrecondition Failed", 500 => "Internal Server Error", 501 => "Method Not Implemented", 502 => "Bad Gateway", 506 => "Variant Also Negotiates" } end # = HttpUtils # module HttpUtils # Converts the given time object to an http time string. # Example: # Sat, 01 Jan 2000 00:00:00 GMT # def self.time_to_string(time) return CGI::rfc1123_date(time) end # NOT IMPLEMENTED # # Converts an http time string to a time object. # Example: # Sat, 01 Jan 2000 00:00:00 GMT # def self.string_to_time(string) raise "Not implemented" end end end # module