Addition to "http" library, separated constants into

- HTTP_MIME_TYPES
 - HTTP_HEADER_NAMES
 - HTTP_REQUEST_METHODS
 - HTTP_STATUS_CODE   (already exists)

Do not set the "Status" header when using WGI_RESPONSE_BUFFER.write_header (...)
Cosmetic
This commit is contained in:
Jocelyn Fiat
2011-10-12 11:51:49 +02:00
parent 0144e97d69
commit 035a133b5b
13 changed files with 695 additions and 219 deletions

View File

@@ -1,5 +1,7 @@
note
description: "Summary description for {HTTP_CONSTANTS}."
description: "[
Constants class providing most common constants used in HTTP communication
]"
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
@@ -8,83 +10,29 @@ note
class
HTTP_CONSTANTS
inherit
HTTP_MIME_TYPES
HTTP_HEADER_NAMES
HTTP_STATUS_CODE
HTTP_REQUEST_METHODS
feature -- Ports
default_http_port: INTEGER = 80
default_https_port: INTEGER = 443
feature -- Method
method_get: STRING = "GET"
method_post: STRING = "POST"
method_put: STRING = "PUT"
method_delete: STRING = "DELETE"
method_head: STRING = "HEAD"
method_download: STRING = "DOWNLOAD"
feature -- Content type
octet_stream: STRING = "application/octet-stream"
-- Octet stream content-type header
multipart_form: STRING = "multipart/form-data"
-- Starting chars of multipart form data content-type header
form_encoded: STRING = "application/x-www-form-urlencoded"
-- Starting chars of form url-encoded data content-type header
xml_text: STRING = "text/xml"
-- XML text content-type header
html_text: STRING = "text/html"
-- HTML text content-type header
json_text: STRING = "text/json"
-- JSON text content-type header
json_app: STRING = "application/json"
-- JSON application content-type header
js_text: STRING = "text/javascript"
-- Javascript text content-type header
js_app: STRING = "application/javascript"
-- JavaScript application content-type header
plain_text: STRING = "text/plain"
-- Plain text content-type header
feature -- Server
feature -- Server, header
http_version_1_0: STRING = "HTTP/1.0"
http_version_1_1: STRING = "HTTP/1.1"
http_host_header: STRING = "Host"
http_authorization_header: STRING = "Authorization: "
http_end_of_header_line: STRING = "%R%N"
http_end_of_command: STRING = "%R%N%R%N"
http_content_length: STRING = "Content-Length: "
http_content_type: STRING = "Content-Type: "
http_content_location: STRING = "Content-Location: "
http_content_disposition: STRING = "Content-Disposition: "
http_path_translated: STRING = "Path-Translated: "
http_agent: STRING = "User-agent: "
http_from: STRING = "From: "
feature -- Server: header
header_host: STRING = "Host"
header_authorization: STRING = "Authorization"
header_content_length: STRING = "Content-Length"
header_content_type: STRING = "Content-Type"
header_content_location: STRING = "Content-Location"
header_content_disposition: STRING = "Content-Disposition"
header_cache_control: STRING = "Cache-Control"
header_path_translated: STRING = "Path-Translated"
header_agent: STRING = "User-Agent"
header_referer: STRING = "Referer" -- Officially mispelled in std
header_location: STRING = "Location"
header_from: STRING = "From"
header_status: STRING = "Status"
header_multipart_tag_value_separator: CHARACTER = ';'
feature -- Misc
http_status_ok: STRING = "200 OK"
default_bufsize: INTEGER = 16384 --| 16K
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -0,0 +1,257 @@
note
description: "[
See http://en.wikipedia.org/wiki/List_of_HTTP_headers
]"
date: "$Date$"
revision: "$Revision$"
class
HTTP_HEADER_NAMES
feature -- Request header name
header_accept: STRING = "Accept"
-- Content-Types that are acceptable
--| Example: Accept: text/plain
header_accept_charset: STRING = "Accept-Charset"
-- Character sets that are acceptable
--| Example: Accept-Charset: utf-8
header_accept_encoding: STRING = "Accept-Encoding"
-- Acceptable encodings. See HTTP compression.
--| Example: Accept-Encoding: <compress | gzip | deflate | sdch | identity>
header_accept_language: STRING = "Accept-Language"
-- Acceptable languages for response
--| Example: Accept-Language: en-US
header_authorization: STRING = "Authorization"
-- Authentication credentials for HTTP authentication
--| Example: Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
header_cookie: STRING = "Cookie"
-- an HTTP cookie previously sent by the server with Set-Cookie (below)
--| Example: Cookie: $Version=1; Skin=new;
header_expect: STRING = "Expect"
-- Indicates that particular server behaviors are required by the client
--| Example: Expect: 100-continue
header_from: STRING = "From"
-- The email address of the user making the request
--| Example: From: user@example.com
header_host: STRING = "Host"
-- The domain name of the server (for virtual hosting), mandatory since HTTP/1.1
--| Example: Host: en.wikipedia.org
header_if_match: STRING = "If-Match"
-- Only perform the action if the client supplied entity matches the same entity on the server. This is mainly for methods like PUT to only update a resource if it has not been modified since the user last updated it.
--| Example: If-Match: "737060cd8c284d8af7ad3082f209582d"
header_if_modified_since: STRING = "If-Modified-Since"
-- Allows a 304 Not Modified to be returned if content is unchanged
--| Example: If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
header_if_none_match: STRING = "If-None-Match"
-- Allows a 304 Not Modified to be returned if content is unchanged, see HTTP ETag
--| Example: If-None-Match: "737060cd8c284d8af7ad3082f209582d"
header_if_range: STRING = "If-Range"
-- If the entity is unchanged, send me the part(s) that I am missing; otherwise, send me the entire new entity
--| Example: If-Range: "737060cd8c284d8af7ad3082f209582d"
header_if_unmodified_since: STRING = "If-Unmodified-Since"
-- Only send the response if the entity has not been modified since a specific time.
--| Example: If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT
header_max_forwards: STRING = "Max-Forwards"
-- Limit the number of times the message can be forwarded through proxies or gateways.
--| Example: Max-Forwards: 10
header_proxy_authorization: STRING = "Proxy-Authorization"
-- Authorization credentials for connecting to a proxy.
--| Example: Proxy-Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
header_range: STRING = "Range"
-- Request only part of an entity. Bytes are numbered from 0.
--| Example: Range: bytes=500-999
header_referer: STRING = "Referer[sic]"
-- This is the address of the previous web page from which a link to the currently requested page was followed. (The word “referrer” is misspelled in the RFC as well as in most implementations.)
--| Example: Referer: http://en.wikipedia.org/wiki/Main_Page
header_te: STRING = "TE"
-- The transfer encodings the user agent is willing to accept: the same values as for the response header Transfer-Encoding can be used, plus the "trailers" value (related to the "chunked" transfer method) to notify the server it accepts to receive additional headers (the trailers) after the last, zero-sized, chunk.
--| Example: TE: trailers, deflate
header_upgrade: STRING = "Upgrade"
-- Ask the server to upgrade to another protocol.
--| Example: Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11
header_user_agent: STRING = "User-Agent"
-- The user agent string of the user agent
--| Example: User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
feature -- Response header name
header_accept_ranges: STRING = "Accept-Ranges"
-- "Accept-Ranges" What partial content range types this server supports
--| Example: Accept-Ranges: bytes
header_age: STRING = "Age"
-- The age the object has been in a proxy cache in seconds
--| Example: Age: 12
header_allow: STRING = "Allow"
-- Valid actions for a specified resource. To be used for a 405 Method not allowed
--| Example: Allow: GET, HEAD
header_content_encoding: STRING = "Content-Encoding"
-- The type of encoding used on the data. See HTTP compression.
--| Example: Content-Encoding: gzip
header_content_language: STRING = "Content-Language"
-- The language the content is in
--| Example: Content-Language: da
header_content_location: STRING = "Content-Location"
-- An alternate location for the returned data
--| Example: Content-Location: /index.htm
header_content_disposition: STRING = "Content-Disposition"
-- An opportunity to raise a "File Download" dialogue box for a known MIME type
--| Example: Content-Disposition: attachment; filename=fname.ext
header_content_range: STRING = "Content-Range"
-- Where in a full body message this partial message belongs
--| Example: Content-Range: bytes 21010-47021/47022
header_etag: STRING = "ETag"
-- An identifier for a specific version of a resource, often a message digest
--| Example: ETag: "737060cd8c284d8af7ad3082f209582d"
header_expires: STRING = "Expires"
-- Gives the date/time after which the response is considered stale
--| Example: Expires: Thu, 01 Dec 1994 16:00:00 GMT
header_last_modified: STRING = "Last-Modified"
-- The last modified date for the requested object, in RFC 2822 format
--| Example: Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT
header_link: STRING = "Link"
-- Used to express a typed relationship with another resource, where the relation type is defined by RFC 5988
--| Example: Link: </feed>; rel="alternate"
header_location: STRING = "Location"
-- Used in redirection, or when a new resource has been created.
--| Example: Location: http://www.w3.org/pub/WWW/People.html
header_p3p: STRING = "P3P"
-- This header is supposed to set P3P policy, in the form of P3P:CP="your_compact_policy". However, P3P did not take off,[5] most browsers have never fully implemented it, a lot of websites set this header with fake policy text, that was enough to fool browsers the existence of P3P policy and grant permissions for third party cookies.
--| Example: P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
header_proxy_authenticate: STRING = "Proxy-Authenticate"
-- Request authentication to access the proxy.
--| Example: Proxy-Authenticate: Basic
header_refresh: STRING = "Refresh"
-- Used in redirection, or when a new resource has been created. This refresh redirects after 5 seconds. This is a proprietary, non-standard header extension introduced by Netscape and supported by most web browsers.
--| Example: Refresh: 5; url=http://www.w3.org/pub/WWW/People.html
header_retry_after: STRING = "Retry-After"
-- If an entity is temporarily unavailable, this instructs the client to try again after a specified period of time.
--| Example: Retry-After: 120
header_server: STRING = "Server"
-- A name for the server
--| Example: Server: Apache/1.3.27 (Unix) (Red-Hat/Linux)
header_set_cookie: STRING = "Set-Cookie"
-- an HTTP cookie
--| Example: Set-Cookie: UserID=JohnDoe; Max-Age=3600; Version=1
header_strict_transport_security: STRING = "Strict-Transport-Security"
-- A HSTS Policy informing the HTTP client how long to cache the HTTPS only policy and whether this applies to subdomains.
--| Example: Strict-Transport-Security: max-age=16070400; includeSubDomains
header_trailer: STRING = "Trailer"
-- The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded with chunked transfer-coding.
--| Example: Trailer: Max-Forwards
header_transfer_encoding: STRING = "Transfer-Encoding"
-- The form of encoding used to safely transfer the entity to the user. Currently defined methods are: chunked, compress, deflate, gzip, identity.
--| Example: Transfer-Encoding: chunked
header_vary: STRING = "Vary"
-- Tells downstream proxies how to match future request headers to decide whether the cached response
-- can be used rather than requesting a fresh one from the origin server.
--| Example: Vary: *
header_www_authenticate: STRING = "WWW-Authenticate"
-- Indicates the authentication scheme that should be used to access the requested entity.
--| Example: WWW-Authenticate: Basic
feature -- Request or Response header name
header_cache_control: STRING = "Cache-Control"
-- Request: Used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain
-- Response: Tells all caching mechanisms from server to client whether they may cache this object. It is measured in seconds
--| Request example: Cache-Control: no-cache
--| Response example: Cache-Control: max-age=3600
header_connection: STRING = "Connection"
-- Request: What type of connection the user-agent would prefer
-- Response: Options that are desired for the connection[4]
--| Example: Connection: close
header_content_length: STRING = "Content-Length"
-- Request: The length of the request body in octets (8-bit bytes)
-- Response: The length of the response body in octets (8-bit bytes)
--| Example: Content-Length: 348
header_content_md5: STRING = "Content-MD5"
-- Request: A Base64-encoded binary MD5 sum of the content of the request body
-- Response: A Base64-encoded binary MD5 sum of the content of the response
--| Example: Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ==
header_content_type: STRING = "Content-Type"
-- Request: The mime type of the body of the request (used with POST and PUT requests)
-- Response : The mime type of this content
--| Request example: Content-Type: application/x-www-form-urlencoded
--| Response example: Content-Type: text/html; charset=utf-8
header_date: STRING = "Date"
-- The date and time that the message was sent
--| Example: Date: Tue, 15 Nov 1994 08:12:31 GMT
header_pragma: STRING = "Pragma"
-- Implementation-specific headers that may have various effects anywhere along the request-response chain.
--| Example: Pragma: no-cache
header_via: STRING = "Via"
-- Request: Informs the server of proxies through which the request was sent.
-- Response: Informs the client of proxies through which the response was sent.
--| Example: Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
header_warning: STRING = "Warning"
-- A general warning about possible problems with the entity body.
--| Example: Warning: 199 Miscellaneous warning
feature -- MIME related
header_content_transfer_encoding: STRING = "Content-Transfer-Encoding"
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,140 @@
note
description: "[
Various common MIME types
See also for longer list and description
http://www.iana.org/assignments/media-types/index.html
http://www.webmaster-toolkit.com/mime-types.shtml
Please suggest common/popular MIME type which might be missing here
]"
date: "$Date$"
revision: "$Revision$"
class
HTTP_MIME_TYPES
feature -- Content type : application
application_atom_xml: STRING = "application/atom+xml"
-- atom application content-type header
application_x_www_form_encoded: STRING = "application/x-www-form-urlencoded"
-- Starting chars of form url-encoded data content-type header
application_octet_stream: STRING = "application/octet-stream"
-- Octet stream content-type header
application_javascript: STRING = "application/javascript"
-- JavaScript application content-type header
application_json: STRING = "application/json"
-- JSON application content-type header
application_pdf: STRING = "application/pdf"
-- pdf application content-type header
application_rss_xml: STRING = "application/rss+xml"
-- rss application content-type header
application_xml: STRING = "application/xml"
-- xml application content-type header
application_x_compressed: STRING = "application/x-compressed"
-- x-compressed application content-type header
application_zip: STRING = "application/zip"
-- ZIP application content-type header
feature -- Content type : audio
feature -- Content type : image
image_gif: STRING = "image/gif"
-- GIF image content-type header
image_jpeg: STRING = "image/jpeg"
-- JPEG image content-type header
image_jpg: STRING = "image/jpg"
-- JPEG image content-type header
image_png: STRING = "image/png"
-- PNG image content-type header
image_svg_xml: STRING = "image/svg+xml"
-- SVG+XML image content-type header
feature -- Content type : message
message_http: STRING = "message/http"
-- http message content-type header
message_s_http: STRING = "message/s-http"
-- s-http message content-type
message_partial: STRING = "message/partial"
-- partial message content-type
message_sip: STRING = "message/sip"
-- sip message content-type
feature -- Content type : model
feature -- Content type : multipart
multipart_mixed: STRING = "multipart/mixed"
multipart_alternative: STRING = "multipart/alternative"
multipart_related: STRING = "multipart/related"
multipart_form_data: STRING = "multipart/form-data"
multipart_signed: STRING = "multipart/signed"
multipart_encrypted: STRING = "multipart/encrypted"
feature -- Content type : text
text_css: STRING = "text/css"
-- CSS text content-type header
text_csv: STRING = "text/csv"
-- CSV text content-type header
text_html: STRING = "text/html"
-- HTML text content-type header
text_javascript: STRING = "text/javascript"
-- Javascript text content-type header
-- OBSOLETE
text_json: STRING = "text/json"
-- JSON text content-type header
text_plain: STRING = "text/plain"
-- Plain text content-type header
text_rtf: STRING = "text/rtf"
-- rtf content-type header
text_xml: STRING = "text/xml"
-- XML text content-type header
text_vcard: STRING = "text/vcard"
-- vcard text content-type header
feature -- Content type : video
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -6,31 +6,30 @@ note
class
HTTP_REQUEST_METHOD_CONSTANTS
inherit
HTTP_REQUEST_METHODS
feature -- Id
method_get: INTEGER = 0x1
head: INTEGER = 0x1
method_post: INTEGER = 0x2
get: INTEGER = 0x2
method_put: INTEGER = 0x4
trace: INTEGER = 0x4
method_delete: INTEGER = 0x8
options: INTEGER = 0x8
method_head: INTEGER = 0x10
post: INTEGER = 0x10
put: INTEGER = 0x20
delete: INTEGER = 0x40
connect: INTEGER = 0x80
feature -- Name
method_get_name: STRING = "GET"
method_post_name: STRING = "POST"
method_put_name: STRING = "PUT"
method_delete_name: STRING = "DELETE"
method_head_name: STRING = "HEAD"
method_empty_name: STRING = ""
method_empty: STRING = ""
feature -- Query
@@ -39,35 +38,45 @@ feature -- Query
s: STRING
do
s := a_id.as_lower
if s.same_string (method_get_name) then
Result := method_get
elseif s.same_string (method_post_name) then
Result := method_post
elseif s.same_string (method_put_name) then
Result := method_put
elseif s.same_string (method_delete_name) then
Result := method_delete
elseif s.same_string (method_head_name) then
Result := method_head
if s.same_string (method_get) then
Result := get
elseif s.same_string (method_post) then
Result := post
elseif s.same_string (method_put) then
Result := put
elseif s.same_string (method_delete) then
Result := delete
elseif s.same_string (method_head) then
Result := head
elseif s.same_string (method_trace) then
Result := trace
elseif s.same_string (method_options) then
Result := options
elseif s.same_string (method_connect) then
Result := connect
end
end
method_name (a_id: INTEGER): STRING
do
inspect a_id
when method_get then Result := method_get_name
when method_post then Result := method_post_name
when method_put then Result := method_put_name
when method_delete then Result := method_delete_name
when method_head then Result := method_head_name
else Result := method_empty_name
when head then Result := method_head
when get then Result := method_get
when trace then Result := method_trace
when options then Result := method_options
when post then Result := method_post
when put then Result := method_put
when delete then Result := method_delete
when connect then Result := method_connect
else
Result := method_empty
end
ensure
result_is_upper_case: Result /= Void and then Result.as_upper ~ Result
end
note
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
@@ -76,4 +85,5 @@ note
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,75 @@
note
description: "[
Safe method: HEAD, GET, TRACE, OPTIONS
Intended only for information retrieval, should not change state of server
See http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods
]"
date: "$Date$"
revision: "$Revision$"
class
HTTP_REQUEST_METHODS
feature -- Safe Methods
method_head: STRING = "HEAD"
-- Asks for the response identical to the one that would correspond
-- to a GET request, but without the response body.
-- This is useful for retrieving meta-information written in response headers,
-- without having to transport the entire content.
method_get: STRING = "GET"
-- Requests a representation of the specified resource.
-- Requests using GET (and a few other HTTP methods)
-- "SHOULD NOT have the significance of taking an action other than retrieval"
-- The W3C has published guidance principles on this distinction, saying,
-- "Web application design should be informed by the above principles,
-- but also by the relevant limitations."
method_trace: STRING = "TRACE"
-- Echoes back the received request, so that a client can see what
-- (if any) changes or additions have been made by intermediate servers.
method_options: STRING = "OPTIONS"
-- Returns the HTTP methods that the server supports for specified URL.
-- This can be used to check the functionality of a web server by requesting '*'
-- instead of a specific resource.
feature -- Methods intented for actions
method_post: STRING = "POST"
-- Submits data to be processed (e.g., from an HTML form) to the identified resource.
-- The data is included in the body of the request.
-- This may result in the creation of a new resource or the updates of existing
-- resources or both.
method_put: STRING = "PUT"
-- Uploads a representation of the specified resource.
method_delete: STRING = "DELETE"
-- Deletes the specified resource.
feature -- Other Methods
method_connect: STRING = "CONNECT"
-- Converts the request connection to a transparent TCP/IP tunnel,
-- usually to facilitate SSL-encrypted communication (HTTPS) through
-- an unencrypted HTTP proxy.
method_patch: STRING = "PATCH"
-- Is used to apply partial modifications to a resource
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end