First step to extract the interface of the EWSGI specification into its own library

Applied the changes
This commit is contained in:
Jocelyn Fiat
2011-07-27 15:34:22 +02:00
parent 694c0a193c
commit 302ae8d030
21 changed files with 120 additions and 40 deletions

View File

@@ -1,629 +0,0 @@
note
description: "[
Interface for a request environment
It includes CGI interface and a few extra values that are usually valuable
See http://ken.coar.org/cgi/draft-coar-cgi-v11-03.txt
2.2. Basic Rules
The following rules are used throughout this specification to
describe basic parsing constructs.
alpha = lowalpha | hialpha
alphanum = alpha | digit
lowalpha = a | b | c | d | e | f | g | h
| i | j | k | l | m | n | o | p
| q | r | s | t | u | v | w | x
| y | z
hialpha = A | B | C | D | E | F | G | H
| I | J | K | L | M | N | O | P
| Q | R | S | T | U | V | W | X
| Y | Z
digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
| 8 | 9
hex = digit | A | B | C | D | E | F | a
| b | c | d | e | f
escaped = % hex hex
OCTET = <any 8-bit sequence of data>
CHAR = <any US-ASCII character (octets 0 - 127)>
CTL = <any US-ASCII control character
(octets 0 - 31) and DEL (127)>
CR = <US-ASCII CR, carriage return (13)>
LF = <US-ASCII LF, linefeed (10)>
SP = <US-ASCII SP, space (32)>
HT = <US-ASCII HT, horizontal tab (9)>
NL = CR | LF
LWSP = SP | HT | NL
tspecial = ( | ) | "@" | , | ; | : | \ | "
| / | [ | ] | ? | < | > | { | }
| SP | HT | NL
token = 1*<any CHAR except CTLs or tspecials>
quoted-string = ( " *qdtext " ) | ( "<" *qatext ">")
qdtext = <any CHAR except %" and CTLs but including LWSP>
qatext = <any CHAR except "<", ">" and CTLs but including LWSP>
mark = - | _ | . | ! | ~ | * | ' | ( | )
unreserved = alphanum | mark
reserved = ; | / | ? | : | @ | & | = | $ | ,
uric = reserved | unreserved | escaped
Note that newline (NL) need not be a single character, but can
be a character sequence.
3.2. The Script-URI
The 'Script-URI' is defined as the URI of the resource
identified by the metavariables. Often, this URI will be the
same as the URI requested by the client (the 'Client-URI');
however, it need not be. Instead, it could be a URI invented
by the server, and so it can only be used in the context of
the server and its CGI interface.
The Script-URI has the syntax of generic-RL as defined in
section 2.1 of RFC 1808 [7], with the exception that object
parameters and fragment identifiers are not permitted:
<scheme>://<host><port>/<path>?<query>
The various components of the Script-URI are defined by some
of the metavariables (see section 4 below);
script-uri = protocol "://" SERVER_NAME ":" SERVER_PORT enc-script
enc-path-info "?" QUERY_STRING
where 'protocol' is obtained from SERVER_PROTOCOL,
'enc-script' is a URL-encoded version of SCRIPT_NAME and
'enc-path-info' is a URL-encoded version of PATH_INFO. See
section 4.6 for more information about the PATH_INFO
metavariable.
Note that the scheme and the protocol are not identical; for
instance, a resource accessed via an SSL mechanism may have a
Client-URI with a scheme of "https" rather than "http".
CGI/1.1 provides no means for the script to reconstruct this,
and therefore the Script-URI includes the base protocol used.
]"
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
deferred
class
GW_ENVIRONMENT
inherit
GW_VARIABLES [STRING_8]
ITERABLE [STRING_8]
feature -- Access
table: HASH_TABLE [STRING, STRING]
-- These variables are specific to requests made with HTTP.
-- Interpretation of these variables may depend on the value of
-- SERVER_PROTOCOL.
--
-- Environment variables with names beginning with "HTTP_" contain
-- header data read from the client, if the protocol used was HTTP.
-- The HTTP header name is converted to upper case, has all
-- occurrences of "-" replaced with "_" and has "HTTP_" prepended to
-- give the environment variable name. The header data may be
-- presented as sent by the client, or may be rewritten in ways which
-- do not change its semantics. If multiple headers with the same
-- field-name are received then they must be rewritten as a single
-- header having the same semantics. Similarly, a header that is
-- received on more than one line must be merged onto a single line.
-- The server must, if necessary, change the representation of the
-- data (for example, the character set) to be appropriate for a CGI
-- environment variable.
--
-- The server is not required to create environment variables for all
-- the headers that it receives. In particular, it may remove any
-- headers carrying authentication information, such as
-- "Authorization"; it may remove headers whose value is available to
-- the script via other variables, such as "Content-Length" and
-- "Content-Type".
--
-- For convenience it might also include the following CGI entries
deferred
end
feature -- Access: table
new_cursor: HASH_TABLE_ITERATION_CURSOR [STRING_8, STRING_8]
-- Fresh cursor associated with current structure
do
create Result.make (table)
end
feature -- Common Gateway Interface - 1.1 8 January 1996
auth_type: detachable STRING
-- This variable is specific to requests made via the "http"
-- scheme.
--
-- If the Script-URI required access authentication for external
-- access, then the server MUST set the value of this variable
-- from the 'auth-scheme' token in the request's "Authorization"
-- header field. Otherwise it is set to NULL.
--
-- AUTH_TYPE = "" | auth-scheme
-- auth-scheme = "Basic" | "Digest" | token
--
-- HTTP access authentication schemes are described in section 11
-- of the HTTP/1.1 specification [8]. The auth-scheme is not
-- case-sensitive.
--
-- Servers MUST provide this metavariable to scripts if the
-- request header included an "Authorization" field that was
-- authenticated.
deferred
end
content_length: detachable STRING
-- This metavariable is set to the size of the message-body
-- entity attached to the request, if any, in decimal number of
-- octets. If no data are attached, then this metavariable is
-- either NULL or not defined. The syntax is the same as for the
-- HTTP "Content-Length" header field (section 14.14, HTTP/1.1
-- specification [8]).
--
-- CONTENT_LENGTH = "" | 1*digit
--
-- Servers MUST provide this metavariable to scripts if the
-- request was accompanied by a message-body entity.
deferred
end
content_length_value: INTEGER
-- Integer value related to `content_length"
deferred
end
content_type: detachable STRING
-- If the request includes a message-body, CONTENT_TYPE is set to
-- the Internet Media Type [9] of the attached entity if the type
-- was provided via a "Content-type" field in the request header,
-- or if the server can determine it in the absence of a supplied
-- "Content-type" field. The syntax is the same as for the HTTP
-- "Content-Type" header field.
--
-- CONTENT_TYPE = "" | media-type
-- media-type = type "/" subtype *( ";" parameter)
-- type = token
-- subtype = token
-- parameter = attribute "=" value
-- attribute = token
-- value = token | quoted-string
--
-- The type, subtype, and parameter attribute names are not
-- case-sensitive. Parameter values MAY be case sensitive. Media
-- types and their use in HTTP are described in section 3.7 of
-- the HTTP/1.1 specification [8].
--
-- Example:
--
-- application/x-www-form-urlencoded
--
-- There is no default value for this variable. If and only if it
-- is unset, then the script MAY attempt to determine the media
-- type from the data received. If the type remains unknown, then
-- the script MAY choose to either assume a content-type of
-- application/octet-stream or reject the request with a 415
-- ("Unsupported Media Type") error. See section 7.2.1.3 for more
-- information about returning error status values.
--
-- Servers MUST provide this metavariable to scripts if a
-- "Content-Type" field was present in the original request
-- header. If the server receives a request with an attached
-- entity but no "Content-Type" header field, it MAY attempt to
-- determine the correct datatype, or it MAY omit this
-- metavariable when communicating the request information to the
-- script.
deferred
end
gateway_interface: STRING
-- This metavariable is set to the dialect of CGI being used by
-- the server to communicate with the script. Syntax:
--
-- GATEWAY_INTERFACE = "CGI" "/" major "." minor
-- major = 1*digit
-- minor = 1*digit
--
-- Note that the major and minor numbers are treated as separate
-- integers and hence each may be more than a single digit. Thus
-- CGI/2.4 is a lower version than CGI/2.13 which in turn is
-- lower than CGI/12.3. Leading zeros in either the major or the
-- minor number MUST be ignored by scripts and SHOULD NOT be
-- generated by servers.
--
-- This document defines the 1.1 version of the CGI interface
-- ("CGI/1.1").
--
-- Servers MUST provide this metavariable to scripts.
--
-- The version of the CGI specification to which this server
-- complies. Syntax:
--
-- GATEWAY_INTERFACE = "CGI" "/" 1*digit "." 1*digit
--
-- Note that the major and minor numbers are treated as separate
-- integers and that each may be incremented higher than a single
-- digit. Thus CGI/2.4 is a lower version than CGI/2.13 which in
-- turn is lower than CGI/12.3. Leading zeros must be ignored by
-- scripts and should never be generated by servers.
deferred
end
path_info: STRING assign update_path_info
-- The PATH_INFO metavariable specifies a path to be interpreted
-- by the CGI script. It identifies the resource or sub-resource
-- to be returned by the CGI script, and it is derived from the
-- portion of the URI path following the script name but
-- preceding any query data. The syntax and semantics are similar
-- to a decoded HTTP URL 'path' token (defined in RFC 2396 [4]),
-- with the exception that a PATH_INFO of "/" represents a single
-- void path segment.
--
-- PATH_INFO = "" | ( "/" path )
-- path = segment *( "/" segment )
-- segment = *pchar
-- pchar = <any CHAR except "/">
--
-- The PATH_INFO string is the trailing part of the <path>
-- component of the Script-URI (see section 3.2) that follows the
-- SCRIPT_NAME portion of the path.
--
-- Servers MAY impose their own restrictions and limitations on
-- what values they will accept for PATH_INFO, and MAY reject or
-- edit any values they consider objectionable before passing
-- them to the script.
--
-- Servers MUST make this URI component available to CGI scripts.
-- The PATH_INFO value is case-sensitive, and the server MUST
-- preserve the case of the PATH_INFO element of the URI when
-- making it available to scripts.
deferred
end
path_translated: detachable STRING
-- PATH_TRANSLATED is derived by taking any path-info component
-- of the request URI (see section 6.1.6), decoding it (see
-- section 3.1), parsing it as a URI in its own right, and
-- performing any virtual-to-physical translation appropriate to
-- map it onto the server's document repository structure. If the
-- request URI includes no path-info component, the
-- PATH_TRANSLATED metavariable SHOULD NOT be defined.
--
--
-- PATH_TRANSLATED = *CHAR
--
-- For a request such as the following:
--
-- http://somehost.com/cgi-bin/somescript/this%2eis%2epath%2einfo
--
-- the PATH_INFO component would be decoded, and the result
-- parsed as though it were a request for the following:
--
-- http://somehost.com/this.is.the.path.info
--
-- This would then be translated to a location in the server's
-- document repository, perhaps a filesystem path something like
-- this:
--
-- /usr/local/www/htdocs/this.is.the.path.info
--
-- The result of the translation is the value of PATH_TRANSLATED.
--
-- The value of PATH_TRANSLATED may or may not map to a valid
-- repository location. Servers MUST preserve the case of the
-- path-info segment if and only if the underlying repository
-- supports case-sensitive names. If the repository is only
-- case-aware, case-preserving, or case-blind with regard to
-- document names, servers are not required to preserve the case
-- of the original segment through the translation.
--
-- The translation algorithm the server uses to derive
-- PATH_TRANSLATED is implementation defined; CGI scripts which
-- use this variable may suffer limited portability.
--
-- Servers SHOULD provide this metavariable to scripts if and
-- only if the request URI includes a path-info component.
deferred
end
query_string: STRING
-- A URL-encoded string; the <query> part of the Script-URI. (See
-- section 3.2.)
--
-- QUERY_STRING = query-string
-- query-string = *uric
-- The URL syntax for a query string is described in section 3 of
-- RFC 2396 [4].
--
-- Servers MUST supply this value to scripts. The QUERY_STRING
-- value is case-sensitive. If the Script-URI does not include a
-- query component, the QUERY_STRING metavariable MUST be defined
-- as an empty string ("").
deferred
end
remote_addr: STRING
-- The IP address of the client sending the request to the
-- server. This is not necessarily that of the user agent (such
-- as if the request came through a proxy).
--
-- REMOTE_ADDR = hostnumber
-- hostnumber = ipv4-address | ipv6-address
-- The definitions of ipv4-address and ipv6-address are provided
-- in Appendix B of RFC 2373 [13].
--
-- Servers MUST supply this value to scripts.
deferred
end
remote_host: detachable STRING
-- The fully qualified domain name of the client sending the
-- request to the server, if available, otherwise NULL. (See
-- section 6.1.9.) Fully qualified domain names take the form as
-- described in section 3.5 of RFC 1034 [10] and section 2.1 of
-- RFC 1123 [5]. Domain names are not case sensitive.
--
-- Servers SHOULD provide this information to scripts.
deferred
end
remote_ident: detachable STRING
-- The identity information reported about the connection by a
-- RFC 1413 [11] request to the remote agent, if available.
-- Servers MAY choose not to support this feature, or not to
-- request the data for efficiency reasons.
--
-- REMOTE_IDENT = *CHAR
--
-- The data returned may be used for authentication purposes, but
-- the level of trust reposed in them should be minimal.
--
-- Servers MAY supply this information to scripts if the RFC1413
-- [11] lookup is performed.
deferred
end
remote_user: detachable STRING
-- If the request required authentication using the "Basic"
-- mechanism (i.e., the AUTH_TYPE metavariable is set to
-- "Basic"), then the value of the REMOTE_USER metavariable is
-- set to the user-ID supplied. In all other cases the value of
-- this metavariable is undefined.
--
-- REMOTE_USER = *OCTET
--
-- This variable is specific to requests made via the HTTP
-- protocol.
--
-- Servers SHOULD provide this metavariable to scripts.
deferred
end
request_method: STRING
-- The REQUEST_METHOD metavariable is set to the method with
-- which the request was made, as described in section 5.1.1 of
-- the HTTP/1.0 specification [3] and section 5.1.1 of the
-- HTTP/1.1 specification [8].
--
-- REQUEST_METHOD = http-method
-- http-method = "GET" | "HEAD" | "POST" | "PUT" | "DELETE"
-- | "OPTIONS" | "TRACE" | extension-method
-- extension-method = token
--
-- The method is case sensitive. CGI/1.1 servers MAY choose to
-- process some methods directly rather than passing them to
-- scripts.
--
-- This variable is specific to requests made with HTTP.
--
-- Servers MUST provide this metavariable to scripts.
deferred
end
script_name: STRING
-- The SCRIPT_NAME metavariable is set to a URL path that could
-- identify the CGI script (rather than the script's output). The
-- syntax and semantics are identical to a decoded HTTP URL
-- 'path' token (see RFC 2396 [4]).
--
-- SCRIPT_NAME = "" | ( "/" [ path ] )
--
-- The SCRIPT_NAME string is some leading part of the <path>
-- component of the Script-URI derived in some implementation
-- defined manner. No PATH_INFO or QUERY_STRING segments (see
-- sections 6.1.6 and 6.1.8) are included in the SCRIPT_NAME
-- value.
--
-- Servers MUST provide this metavariable to scripts.
deferred
end
server_name: STRING
-- The SERVER_NAME metavariable is set to the name of the server,
-- as derived from the <host> part of the Script-URI (see section
-- 3.2).
--
-- SERVER_NAME = hostname | hostnumber
--
-- Servers MUST provide this metavariable to scripts.
deferred
end
server_port: INTEGER
-- The SERVER_PORT metavariable is set to the port on which the
-- request was received, as used in the <port> part of the
-- Script-URI.
--
-- SERVER_PORT = 1*digit
--
-- If the <port> portion of the script-URI is blank, the actual
-- port number upon which the request was received MUST be
-- supplied.
--
-- Servers MUST provide this metavariable to scripts.
deferred
end
server_protocol: STRING
-- The SERVER_PROTOCOL metavariable is set to the name and
-- revision of the information protocol with which the request
-- arrived. This is not necessarily the same as the protocol
-- version used by the server in its response to the client.
--
-- SERVER_PROTOCOL = HTTP-Version | extension-version
-- | extension-token
-- HTTP-Version = "HTTP" "/" 1*digit "." 1*digit
-- extension-version = protocol "/" 1*digit "." 1*digit
-- protocol = 1*( alpha | digit | "+" | "-" | "." )
-- extension-token = token
--
-- 'protocol' is a version of the <scheme> part of the
-- Script-URI, but is not identical to it. For example, the
-- scheme of a request may be "https" while the protocol remains
-- "http". The protocol is not case sensitive, but by convention,
-- 'protocol' is in upper case.
--
-- A well-known extension token value is "INCLUDED", which
-- signals that the current document is being included as part of
-- a composite document, rather than being the direct target of
-- the client request.
--
-- Servers MUST provide this metavariable to scripts.
deferred
end
server_software: STRING
-- The SERVER_SOFTWARE metavariable is set to the name and
-- version of the information server software answering the
-- request (and running the gateway).
--
-- SERVER_SOFTWARE = 1*product
-- product = token [ "/" product-version ]
-- product-version = token
-- Servers MUST provide this metavariable to scripts.
deferred
end
feature -- HTTP_*
http_accept_charset: detachable STRING
-- Contents of the Accept-Charset: header from the current request, if there is one.
-- Example: 'iso-8859-1,*,utf-8'.
deferred
end
http_accept_encoding: detachable STRING
-- Contents of the Accept-Encoding: header from the current request, if there is one.
-- Example: 'gzip'.
deferred
end
http_accept_language: detachable STRING
-- Contents of the Accept-Language: header from the current request, if there is one.
-- Example: 'en'.
deferred
end
http_connection: detachable STRING
-- Contents of the Connection: header from the current request, if there is one.
-- Example: 'Keep-Alive'.
deferred
end
http_host: detachable STRING
-- Contents of the Host: header from the current request, if there is one.
deferred
end
http_referer: detachable STRING
-- The address of the page (if any) which referred the user agent to the current page.
-- This is set by the user agent.
-- Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature.
-- In short, it cannot really be trusted.
deferred
end
http_user_agent: detachable STRING
-- Contents of the User-Agent: header from the current request, if there is one.
-- This is a string denoting the user agent being which is accessing the page.
-- A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586).
-- Among other things, you can use this value to tailor your page's
-- output to the capabilities of the user agent.
deferred
end
http_authorization: detachable STRING
-- Contents of the Authorization: header from the current request, if there is one.
deferred
end
feature -- Extra
request_uri: STRING
-- The URI which was given in order to access this page; for instance, '/index.html'.
deferred
end
orig_path_info: detachable STRING
-- Original version of `path_info' before processed by Current environment
deferred
end
feature {GW_REQUEST} -- Element change
set_orig_path_info (s: STRING)
-- Set ORIG_PATH_INFO to `s'
require
s_attached: s /= Void
deferred
ensure
same_orig_path_info: orig_path_info ~ variable ({GW_ENVIRONMENT_NAMES}.orig_path_info)
end
unset_orig_path_info
-- Unset ORIG_PATH_INFO
deferred
ensure
unset: not has_variable ({GW_ENVIRONMENT_NAMES}.orig_path_info)
end
update_path_info (a_path_info: like path_info)
-- Updated PATH_INFO
deferred
ensure
same_path_info: path_info ~ variable ({GW_ENVIRONMENT_NAMES}.path_info)
end
invariant
server_name_not_empty: not server_name.is_empty
server_port_set: server_port /= 0
request_method_attached: request_method /= Void
path_info_attached: path_info /= Void
query_string_attached: query_string /= Void
remote_addr_attached: remote_addr /= Void
path_info_identical: path_info ~ variable ({GW_ENVIRONMENT_NAMES}.path_info)
;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

@@ -1,292 +0,0 @@
note
description: "Summary description for {GW_ENVIRONMENT_VARIABLES}."
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
class
GW_ENVIRONMENT_VARIABLES
inherit
GW_ENVIRONMENT
redefine
update_path_info
end
create
make_with_variables
feature {NONE} -- Initialization
make_with_variables (a_vars: HASH_TABLE [STRING, STRING])
-- Fill with variable from `a_vars'
local
s: detachable STRING
do
create empty_string.make_empty
create table.make (a_vars.count)
from
a_vars.start
until
a_vars.after
loop
table.force (a_vars.item_for_iteration, a_vars.key_for_iteration)
a_vars.forth
end
--| QUERY_STRING
query_string := variable_or_default ({GW_ENVIRONMENT_NAMES}.query_string, empty_string, False)
--| REQUEST_METHOD
request_method := variable_or_default ({GW_ENVIRONMENT_NAMES}.request_method, empty_string, False)
--| CONTENT_TYPE
s := variable ({GW_ENVIRONMENT_NAMES}.content_type)
if s /= Void and then not s.is_empty then
content_type := s
else
content_type := Void
end
--| CONTENT_LENGTH
s := variable ({GW_ENVIRONMENT_NAMES}.content_length)
content_length := s
if s /= Void and then s.is_integer then
content_length_value := s.to_integer
else
--| content_length := 0
end
--| PATH_INFO
path_info := variable_or_default ({GW_ENVIRONMENT_NAMES}.path_info, empty_string, False)
--| SERVER_NAME
server_name := variable_or_default ({GW_ENVIRONMENT_NAMES}.server_name, empty_string, False)
--| SERVER_PORT
s := variable ({GW_ENVIRONMENT_NAMES}.server_port)
if s /= Void and then s.is_integer then
server_port := s.to_integer
else
server_port := 80
end
--| SCRIPT_NAME
script_name := variable_or_default ({GW_ENVIRONMENT_NAMES}.script_name, empty_string, False)
--| REMOTE_ADDR
remote_addr := variable_or_default ({GW_ENVIRONMENT_NAMES}.remote_addr, empty_string, False)
--| REMOTE_HOST
remote_host := variable_or_default ({GW_ENVIRONMENT_NAMES}.remote_host, empty_string, False)
--| REQUEST_URI
request_uri := variable_or_default ({GW_ENVIRONMENT_NAMES}.request_uri, empty_string, False)
end
feature -- Access
table: HASH_TABLE [STRING, STRING]
feature -- Access
variable (a_name: STRING): detachable STRING
do
Result := table.item (a_name)
end
has_variable (a_name: STRING): BOOLEAN
do
Result := table.has_key (a_name)
end
feature {GW_REQUEST, GW_APPLICATION, GW_CONNECTOR} -- Element change
set_variable (a_name: STRING; a_value: STRING)
do
table.force (a_value, a_name)
end
unset_variable (a_name: STRING)
do
table.remove (a_name)
end
feature -- Common Gateway Interface - 1.1 8 January 1996
auth_type: detachable STRING
content_length: detachable STRING
content_length_value: INTEGER
content_type: detachable STRING
gateway_interface: STRING
do
Result := variable_or_default ({GW_ENVIRONMENT_NAMES}.gateway_interface, "", False)
end
path_info: STRING
-- <Precursor/>
--
--| For instance, if the current script was accessed via the URL
--| http://www.example.com/eiffel/path_info.exe/some/stuff?foo=bar, then $_SERVER['PATH_INFO'] would contain /some/stuff.
--|
--| Note that is the PATH_INFO variable does not exists, the `path_info' value will be empty
path_translated: detachable STRING
do
Result := variable ({GW_ENVIRONMENT_NAMES}.path_translated)
end
query_string: STRING
remote_addr: STRING
remote_host: STRING
remote_ident: detachable STRING
do
Result := variable ({GW_ENVIRONMENT_NAMES}.remote_ident)
end
remote_user: detachable STRING
do
Result := variable ({GW_ENVIRONMENT_NAMES}.remote_user)
end
request_method: STRING
script_name: STRING
server_name: STRING
server_port: INTEGER
server_protocol: STRING
do
Result := variable_or_default ({GW_ENVIRONMENT_NAMES}.server_protocol, "HTTP/1.0", True)
end
server_software: STRING
do
Result := variable_or_default ({GW_ENVIRONMENT_NAMES}.server_software, "Unknown Server", True)
end
feature -- HTTP_*
http_accept: detachable STRING
-- Contents of the Accept: header from the current request, if there is one.
do
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_accept)
end
http_accept_charset: detachable STRING
-- Contents of the Accept-Charset: header from the current request, if there is one.
-- Example: 'iso-8859-1,*,utf-8'.
do
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_accept_charset)
end
http_accept_encoding: detachable STRING
-- Contents of the Accept-Encoding: header from the current request, if there is one.
-- Example: 'gzip'.
do
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_accept_encoding)
end
http_accept_language: detachable STRING
-- Contents of the Accept-Language: header from the current request, if there is one.
-- Example: 'en'.
do
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_accept_language)
end
http_connection: detachable STRING
-- Contents of the Connection: header from the current request, if there is one.
-- Example: 'Keep-Alive'.
do
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_connection)
end
http_host: detachable STRING
-- Contents of the Host: header from the current request, if there is one.
do
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_host)
end
http_referer: detachable STRING
-- The address of the page (if any) which referred the user agent to the current page.
-- This is set by the user agent.
-- Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature.
-- In short, it cannot really be trusted.
do
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_referer)
end
http_user_agent: detachable STRING
-- Contents of the User-Agent: header from the current request, if there is one.
-- This is a string denoting the user agent being which is accessing the page.
-- A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586).
-- Among other things, you can use this value to tailor your page's
-- output to the capabilities of the user agent.
do
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_user_agent)
end
http_authorization: detachable STRING
-- Contents of the Authorization: header from the current request, if there is one.
do
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_authorization)
end
feature -- Extra
request_uri: STRING
-- The URI which was given in order to access this page; for instance, '/index.html'.
orig_path_info: detachable STRING
-- Original version of `path_info' before processed by Current environment
feature {GW_REQUEST} -- Update
set_orig_path_info (s: STRING)
do
orig_path_info := s
set_variable ({GW_ENVIRONMENT_NAMES}.orig_path_info, s)
end
unset_orig_path_info
do
orig_path_info := Void
unset_variable ({GW_ENVIRONMENT_NAMES}.orig_path_info)
end
update_path_info (a_path_info: like path_info)
do
path_info := a_path_info
set_variable ({GW_ENVIRONMENT_NAMES}.path_info, a_path_info)
end
feature {NONE} -- Implementation
empty_string: STRING
-- Reusable empty string
invariant
empty_string_unchanged: empty_string.is_empty
;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

@@ -1,56 +0,0 @@
note
description: "Summary description for {HTTPD_EXECUTION_VARIABLES}."
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
class
GW_EXECUTION_VARIABLES
inherit
GW_VARIABLES [STRING_32]
undefine
copy, is_equal
end
HASH_TABLE [STRING_32, STRING]
create
make
feature -- Status report
variable (a_name: STRING): detachable STRING_32
do
Result := item (a_name)
end
has_variable (a_name: STRING): BOOLEAN
do
Result := has (a_name)
end
feature {GW_REQUEST, GW_APPLICATION, GW_CONNECTOR} -- Element change
set_variable (a_name: STRING; a_value: STRING_32)
do
force (a_value, a_name)
end
unset_variable (a_name: STRING)
do
remove (a_name)
end
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

@@ -1,167 +0,0 @@
note
description: "[
Server request context of the httpd request
You can create your own descendant of this class to
add/remove specific value or processing
This object is created by {GW_APPLICATION}.new_request_context
]"
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
deferred class
GW_REQUEST
feature -- Access: Input
input: GW_INPUT_STREAM
-- Server input channel
deferred
end
feature -- Access: extra values
request_time: detachable DATE_TIME
-- Request time (UTC)
deferred
end
feature -- Access: environment variables
environment: GW_ENVIRONMENT
-- Environment variables
deferred
end
environment_variable (a_name: STRING): detachable STRING
-- Environment variable related to `a_name'
require
a_name_valid: a_name /= Void and then not a_name.is_empty
deferred
end
feature -- Access: execution variables
execution_variables: GW_EXECUTION_VARIABLES
-- Execution variables set by the application
deferred
end
execution_variable (a_name: STRING): detachable STRING_32
-- Execution variable related to `a_name'
require
a_name_valid: a_name /= Void and then not a_name.is_empty
deferred
end
feature -- URL Parameters
parameters: GW_REQUEST_VARIABLES
-- Variables extracted from QUERY_STRING
deferred
end
parameter (a_name: STRING): detachable STRING_32
-- Parameter for name `n'.
require
a_name_valid: a_name /= Void and then not a_name.is_empty
deferred
end
feature -- Form fields and related
form_fields: GW_REQUEST_VARIABLES
-- Variables sent by POST request
deferred
end
form_field (a_name: STRING): detachable STRING_32
-- Field for name `a_name'.
require
a_name_valid: a_name /= Void and then not a_name.is_empty
deferred
end
uploaded_files: HASH_TABLE [GW_UPLOADED_FILE_DATA, STRING]
-- Table of uploaded files information
--| name: original path from the user
--| type: content type
--| tmp_name: path to temp file that resides on server
--| tmp_base_name: basename of `tmp_name'
--| error: if /= 0 , there was an error : TODO ...
--| size: size of the file given by the http request
deferred
end
feature -- Cookies
cookies_variables: HASH_TABLE [STRING, STRING]
-- Expanded cookies variable
deferred
end
cookies_variable (a_name: STRING): detachable STRING
-- Field for name `a_name'.
require
a_name_valid: a_name /= Void and then not a_name.is_empty
deferred
end
cookies: HASH_TABLE [GW_COOKIE, STRING]
-- Cookies Information
deferred
end
feature -- Access: global variable
variables: HASH_TABLE [STRING_32, STRING_32]
-- Table containing all the various variables
-- Warning: this is computed each time, if you change the content of other containers
-- this won't update this Result's content, unless you query it again
deferred
end
variable (a_name: STRING_8): detachable STRING_32
-- Variable named `a_name' from any of the variables container
-- and following a specific order
-- execution, environment, get, post, cookies
require
a_name_valid: a_name /= Void and then not a_name.is_empty
deferred
end
feature -- Uploaded File Handling
is_uploaded_file (a_filename: STRING): BOOLEAN
-- Is `a_filename' a file uploaded via HTTP POST
deferred
end
feature -- URL Utility
absolute_script_url (a_path: STRING): STRING
-- Absolute Url for the script if any, extended by `a_path'
deferred
end
script_url (a_path: STRING): STRING
-- Url relative to script name if any, extended by `a_path'
require
a_path_attached: a_path /= Void
deferred
end
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

@@ -1,149 +0,0 @@
note
description: "[
Variables/field related to the current request.
]"
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
class
GW_REQUEST_VARIABLES
inherit
GW_VARIABLES [STRING_32]
ITERABLE [STRING_32]
create
make,
make_from_urlencoded
feature -- Initialization
make (n: INTEGER)
do
create table.make (n)
table.compare_objects
end
make_from_urlencoded (a_content: STRING; decoding: BOOLEAN)
do
make (a_content.occurrences ('&') + 1)
import_urlencoded (a_content, decoding)
end
feature -- Status report
count: INTEGER
-- Variables count
do
Result := table.count
end
variable (a_name: STRING): detachable STRING_32
do
Result := table.item (a_name)
end
has_variable (a_name: STRING): BOOLEAN
do
Result := table.has (a_name)
end
feature {GW_REQUEST, GW_APPLICATION, GW_CONNECTOR} -- Element change
set_variable (a_name: STRING; a_value: STRING_32)
do
table.force (a_value, a_name)
end
unset_variable (a_name: STRING)
do
table.remove (a_name)
end
feature -- Import urlencoded
import_urlencoded (a_content: STRING; decoding: BOOLEAN)
-- Import `a_content'
local
n, p, i, j: INTEGER
s: STRING
l_name,l_value: STRING_32
do
n := a_content.count
if n > 0 then
from
p := 1
until
p = 0
loop
i := a_content.index_of ('&', p)
if i = 0 then
s := a_content.substring (p, n)
p := 0
else
s := a_content.substring (p, i - 1)
p := i + 1
end
if not s.is_empty then
j := s.index_of ('=', 1)
if j > 0 then
l_name := s.substring (1, j - 1)
l_value := s.substring (j + 1, s.count)
if decoding then
l_name := url_encoder.decoded_string (l_name)
l_value := url_encoder.decoded_string (l_value)
end
add_variable (l_value, l_name)
end
end
end
end
end
feature -- Access: table
new_cursor: HASH_TABLE_ITERATION_CURSOR [STRING_32, STRING_32]
-- Fresh cursor associated with current structure
do
create Result.make (table)
end
feature {GW_REQUEST} -- Element change
add_variable (v: STRING_32; k: STRING_32)
-- Added `k,v' to variables table
-- Not exported to common client
-- Simulate Read Only Access
require
k_attached: k /= Void
v_attached: v /= Void
do
table.force (v, k)
end
feature {GW_REQUEST} -- Element change
table: HASH_TABLE [STRING_32, STRING_32]
-- Variables table
feature {NONE} -- Implementation
url_encoder: URL_ENCODER
once
create Result
end
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

@@ -1,103 +0,0 @@
note
description: "Summary description for {GW_UPLOADED_FILE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
GW_UPLOADED_FILE_DATA
create
make
feature {NONE} -- Initialization
make (n: like name; t: like content_type; s: like size)
do
name := n
content_type := t
size := s
end
feature -- Access
name: STRING
-- original filename
content_type: STRING
-- Content type
size: INTEGER
-- Size of uploaded file
tmp_name: detachable STRING
-- Filename of tmp file
tmp_basename: detachable STRING
-- Basename of tmp file
feature -- Basic operation
move_to (a_destination: STRING): BOOLEAN
-- Move current uploaded file to `a_destination'
require
has_no_error: not has_error
local
f: RAW_FILE
do
if attached tmp_name as n then
create f.make (n)
if f.exists then
f.change_name (a_destination)
Result := True
end
end
end
feature -- Status
has_error: BOOLEAN
-- Has error during uploading
do
Result := error /= 0
end
error: INTEGER
-- Eventual error code
--| no error => 0
feature -- Element change
set_error (e: like error)
-- Set `error' to `e'
do
error := e
end
set_tmp_name (n: like tmp_name)
-- Set `tmp_name' to `n'
do
tmp_name := n
end
set_tmp_basename (n: like tmp_basename)
-- Set `tmp_basename' to `n'
do
tmp_basename := n
end
invariant
valid_tmp_name: not has_error implies attached tmp_name as n and then not n.is_empty
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

@@ -1,77 +0,0 @@
note
description : "[
Interface to access the variable stored in a container
]"
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
deferred class
GW_VARIABLES [G -> STRING_GENERAL]
feature -- Status report
has_variable (a_name: STRING): BOOLEAN
-- Has variable associated with `a_name'
require
a_name_not_empty: a_name /= Void and then not a_name.is_empty
deferred
end
feature -- Access
variable (a_name: STRING): detachable G
-- Value for variable associated with `a_name'
-- If not found, return Void
require
a_name_not_empty: a_name /= Void and then not a_name.is_empty
deferred
end
variable_or_default (a_name: STRING; a_default: G; use_default_when_empty: BOOLEAN): G
-- Value for variable `a_name'
-- If not found, return `a_default'
require
a_name_not_empty: a_name /= Void and then not a_name.is_empty
do
if attached variable (a_name) as s then
if use_default_when_empty and then s.is_empty then
Result := a_default
else
Result := s
end
else
Result := a_default
end
end
feature {GW_REQUEST, GW_APPLICATION, GW_CONNECTOR} -- Element change
set_variable (a_name: STRING; a_value: G)
require
a_name_not_empty: a_name /= Void and then not a_name.is_empty
deferred
ensure
variable_set: has_variable (a_name) and then variable (a_name) ~ a_value
end
unset_variable (a_name: STRING)
require
a_name_not_empty: a_name /= Void and then not a_name.is_empty
deferred
ensure
variable_unset: not has_variable (a_name)
end
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

@@ -1,90 +0,0 @@
note
description: "Summary description for {GW_APPLICATION}."
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
deferred class
GW_APPLICATION
feature -- Process request
process (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM; a_output: GW_OUTPUT_STREAM)
-- Process request with environment `env', and i/o streams `a_input' and `a_output'
local
rescued: BOOLEAN
req: detachable like new_request
res: detachable like new_response
do
if not rescued then
pre_execute (env)
req := new_request (env, a_input)
res := new_response (req, a_output)
execute (req, res)
post_execute (req, res)
else
rescue_execute (req, res, (create {EXCEPTION_MANAGER}).last_exception)
end
if res /= Void then
res.commit (a_output)
end
end
feature {NONE} -- Execution
execute (req: GW_REQUEST; res: GW_RESPONSE)
-- Execute the request
-- See `req.input' for input stream
-- `req.environment' for the Gateway environment
-- and `res.output' for output stream
deferred
end
pre_execute (env: GW_ENVIRONMENT)
-- Operation processed before `execute'
require
env_attached: env /= Void
do
end
post_execute (req: detachable GW_REQUEST; res: detachable GW_RESPONSE)
-- Operation processed after `execute', or after `rescue_execute'
do
end
rescue_execute (req: detachable GW_REQUEST; res: detachable GW_RESPONSE; a_exception: detachable EXCEPTION)
-- Operation processed on rescue of `execute'
do
post_execute (req, res)
end
feature -- Factory
new_request (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM): GW_REQUEST
-- New Request context based on `env' and `a_input'
--| note: you can redefine this function to create your own
--| descendant of GW_REQUEST_CONTEXT , or even to reuse/recycle existing
--| instance of GW_REQUEST_CONTEXT
deferred
end
new_response (req: GW_REQUEST; a_output: GW_OUTPUT_STREAM): GW_RESPONSE
-- New Response based on `req' and `a_output'
--| note: you can redefine this function to create your own
--| descendant of GW_RESPONSE , or even to reuse/recycle existing
--| instance of GW_RESPONSE
deferred
end
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

@@ -1,44 +0,0 @@
note
description: "Summary description for {GW_CONNECTOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
GW_CONNECTOR
feature {NONE} -- Initialization
make (a_app: like application)
do
application := a_app
initialize
end
initialize
-- Initialize connector
do
end
feature {NONE} -- Access
application: GW_APPLICATION
-- Gateway Application
feature -- Server
launch
deferred
end
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

@@ -1,76 +0,0 @@
note
description: "[
Contains all information of a rfc2109 cookie that was read from the request header
]"
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
class
GW_COOKIE
create
make
convert
value: {READABLE_STRING_8, STRING_8, READABLE_STRING_GENERAL, STRING_GENERAL}
feature {NONE} -- Initialization
make (a_name: STRING; a_value: STRING)
-- Creates current.
require
a_name_not_empty: a_name /= Void and then not a_name.is_empty
a_value_not_empty: a_value /= Void and then not a_value.is_empty
do
name := a_name
value := a_value
ensure
a_name_set: name = a_name
a_value_set: value = a_value
end
feature -- Access
name: STRING
-- Required. The name of the state information ("cookie") is NAME,
-- and its value is VALUE. NAMEs that begin with $ are reserved for
-- other uses and must not be used by applications.
value: STRING
-- The VALUE is opaque to the user agent and may be anything the
-- origin server chooses to send, possibly in a server-selected
-- printable ASCII encoding. "Opaque" implies that the content is of
-- interest and relevance only to the origin server. The content
-- may, in fact, be readable by anyone that examines the Set-Cookie
-- header.
feature -- Query
variables: detachable HASH_TABLE [STRING, STRING]
-- Potential variable contained in the encoded cookie's value.
feature -- Status report
value_is_string (s: READABLE_STRING_GENERAL): BOOLEAN
-- Is `value' same string as `s'
do
Result := s.same_string (value)
end
invariant
name_attached: name /= Void
value_attached: value /= Void
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

@@ -1,89 +0,0 @@
note
description: "Summary description for {GW_ENVIRONMENT_NAMES}."
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
class
GW_ENVIRONMENT_NAMES
feature -- Access
request_uri: STRING = "REQUEST_URI"
request_method: STRING = "REQUEST_METHOD"
query_string: STRING = "QUERY_STRING"
content_type: STRING = "CONTENT_TYPE"
content_length: STRING = "CONTENT_LENGTH"
path_info: STRING = "PATH_INFO"
path_translated: STRING = "PATH_TRANSLATED"
http_user_agent: STRING = "HTTP_USER_AGENT"
http_authorization: STRING = "HTTP_AUTHORIZATION"
http_host: STRING = "HTTP_HOST"
http_cookie: STRING = "HTTP_COOKIE"
http_from: STRING = "HTTP_FROM"
http_accept: STRING = "HTTP_ACCEPT"
http_accept_charset: STRING = "HTTP_ACCEPT_CHARSET"
http_accept_encoding: STRING = "HTTP_ACCEPT_ENCODING"
http_accept_language: STRING = "HTTP_ACCEPT_LANGUAGE"
http_connection: STRING = "HTTP_CONNECTION"
http_referer: STRING = "HTTP_REFERER"
gateway_interface: STRING = "GATEWAY_INTERFACE"
auth_type: STRING = "AUTH_TYPE"
remote_host: STRING = "REMOTE_HOST"
remote_addr: STRING = "REMOTE_ADDR"
remote_ident: STRING = "REMOTE_IDENT"
remote_user: STRING = "REMOTE_USER"
script_name: STRING = "SCRIPT_NAME"
server_name: STRING = "SERVER_NAME"
server_port: STRING = "SERVER_PORT"
server_protocol: STRING = "SERVER_PROTOCOL"
server_software: STRING = "SERVER_SOFTWARE"
feature -- Extra names
request_time: STRING = "REQUEST_TIME"
self: STRING = "SELF"
orig_path_info: STRING = "ORIG_PATH_INFO"
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

@@ -36,8 +36,31 @@ feature {NONE} -- Status output
body.append (s)
end
feature -- Status setting
is_status_set: BOOLEAN
do
Result := status_code /= 0
end
set_status_code (a_code: INTEGER)
-- Set response status code
-- Should be done before sending any data back to the client
do
status_code := a_code
end
status_code: INTEGER
-- Response status
feature -- Output operation
write_string (s: STRING)
-- Send the string `s'
do
write (s)
end
write_file_content (fn: STRING)
-- Send the content of file `fn'
local
@@ -57,9 +80,27 @@ feature -- Output operation
end
end
write_header_object (h: GW_HEADER)
-- Send `header' to `output'.
feature -- Header output operation
write_header (a_status_code: INTEGER; a_headers: detachable ARRAY [TUPLE [key: STRING; value: STRING]])
-- Send headers with status `a_status', and headers from `a_headers'
local
h: GW_HEADER
i,n: INTEGER
do
set_status_code (a_status_code)
create h.make
if a_headers /= Void then
from
i := a_headers.lower
n := a_headers.upper
until
i > n
loop
h.put_header_key_value (a_headers[i].key, a_headers[i].value)
i := i + 1
end
end
header := h
end
@@ -67,10 +108,10 @@ feature {GW_APPLICATION} -- Commit
commit (a_output: GW_OUTPUT_STREAM)
do
a_output.put_status (status_code)
header.send_to (a_output)
write (body)
Precursor (a_output)
a_output.put_status_line (status_code)
a_output.put_string (header.string)
a_output.put_string (body)
a_output.flush
end
;note

View File

@@ -35,7 +35,7 @@ feature -- Factory
Result.execution_variables.set_variable (request_count.out, "REQUEST_COUNT")
end
new_response (a_output: GW_OUTPUT_STREAM): GW_IN_MEMORY_RESPONSE
new_response (req: GW_REQUEST; a_output: GW_OUTPUT_STREAM): GW_IN_MEMORY_RESPONSE
do
create {GW_IN_MEMORY_RESPONSE} Result.make
end

View File

@@ -9,9 +9,6 @@ class
inherit
GW_RESPONSE
redefine
commit
end
create {GW_APPLICATION}
make
@@ -33,15 +30,7 @@ feature {NONE} -- Initialization
buffer_count: INTEGER
feature -- Status setting
set_status_code (c: INTEGER)
-- Set the status code of the response
do
header.put_status (c)
end
feature -- Output operation
feature {NONE} -- Core output operation
write (s: STRING)
-- Send the content of `s'
@@ -71,6 +60,33 @@ feature -- Output operation
end
end
feature -- Status setting
is_status_set: BOOLEAN
do
Result := status_code /= 0
end
set_status_code (a_code: INTEGER)
-- Set response status code
-- Should be done before sending any data back to the client
do
status_code := a_code
output.put_status_line (status_code)
--| We could also just append it to the `buffer'
end
status_code: INTEGER
-- Response status
feature -- Output operation
write_string (s: STRING)
-- Send the string `s'
do
write (s)
end
write_file_content (fn: STRING)
-- Send the content of file `fn'
local
@@ -90,12 +106,31 @@ feature -- Output operation
end
end
write_header_object (h: GW_HEADER)
-- Send `header' to `output'.
feature -- Header output operation
write_header (a_status_code: INTEGER; a_headers: detachable ARRAY [TUPLE [key: STRING; value: STRING]])
-- Send headers with status `a_status', and headers from `a_headers'
local
h: GW_HEADER
i,n: INTEGER
do
header := h
set_status_code (a_status_code)
create h.make
if a_headers /= Void then
from
i := a_headers.lower
n := a_headers.upper
until
i > n
loop
h.put_header_key_value (a_headers[i].key, a_headers[i].value)
i := i + 1
end
end
write (h.string)
end
feature {NONE} -- Implementation
flush_buffer
@@ -113,7 +148,7 @@ feature {GW_APPLICATION} -- Commit
commit (a_output: GW_OUTPUT_STREAM)
do
flush_buffer
Precursor (a_output)
a_output.flush
end
;note

View File

@@ -2,7 +2,7 @@ note
description: "[
Summary description for {GW_HEADER}.
Note the return status code is not part of the HTTP header
Note the return status code is not part of the HTTP header
]"
legal: "See notice at end of class."
status: "See notice at end of class."
@@ -35,13 +35,6 @@ feature -- Access
headers: LIST [STRING]
-- Header's lines
send_to (res: GW_RESPONSE)
-- Send Current string representation to `a_output'
do
res.write_string (string)
--| Could be optimized
end
string: STRING
-- String representation of the headers
local

View File

@@ -1,87 +0,0 @@
note
description: "Summary description for {GW_RESPONSE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
GW_RESPONSE
feature {GW_APPLICATION} -- Commit
commit (a_output_stream: GW_OUTPUT_STREAM)
-- Commit the current response
deferred
ensure
status_set: is_status_set
end
feature {NONE} -- Core output operation
write (s: STRING)
-- Send the string `s'
-- this can be used for header and body
deferred
end
feature -- Status setting
is_status_set: BOOLEAN
-- Is status set?
deferred
end
set_status_code (a_code: INTEGER)
-- Set response status code
-- Should be done before sending any data back to the client
require
status_not_set: not is_status_set
deferred
ensure
status_code_set: status_code = a_code
status_set: is_status_set
end
status_code: INTEGER
-- Response status
deferred
end
feature -- Output operation
write_string (s: STRING)
-- Send the string `s'
require
status_set: is_status_set
deferred
end
write_file_content (fn: STRING)
-- Send the content of file `fn'
require
status_set: is_status_set
deferred
end
feature -- Header output operation
write_header (a_status_code: INTEGER; a_headers: detachable ARRAY [TUPLE [key: STRING; value: STRING]])
-- Send headers with status `a_status', and headers from `a_headers'
require
status_not_set: not is_status_set
deferred
ensure
status_set: is_status_set
end
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

@@ -70,14 +70,6 @@ feature -- Output operation
feature -- Header output operation
write_header_object (h: GW_HEADER)
-- Send `header' to `output'.
require
status_set: is_status_set
do
h.send_to (Current)
end
write_header (a_status_code: INTEGER; a_headers: detachable ARRAY [TUPLE [key: STRING; value: STRING]])
-- Send headers with status `a_status', and headers from `a_headers'
local
@@ -97,7 +89,7 @@ feature -- Header output operation
i := i + 1
end
end
write_header_object (h)
write (h.string)
end
feature {NONE} -- Implementation: Access

View File

@@ -1,40 +0,0 @@
note
description : "[
Objects that represents the input stream
]"
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
deferred class
GW_INPUT_STREAM
feature -- Access
last_string: STRING_8
-- Last read string from stream
deferred
end
feature -- Basic operation
read_stream (n: INTEGER)
require
n_positive: n > 0
deferred
ensure
at_max_n: last_string.count <= n
end
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

@@ -1,101 +0,0 @@
note
description : "[
Objects that represents the output stream
]"
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
deferred class
GW_OUTPUT_STREAM
inherit
ANY
HTTP_STATUS_CODE_MESSAGES
export
{NONE} all
end
feature -- Core operation
put_string (s: STRING_8)
-- Write `s' into the output stream
require
s_not_empty: s /= Void and then not s.is_empty
deferred
end
flush
-- Flush the output stream
do
end
feature -- Status writing
put_status_line (a_code: INTEGER)
-- Put status code line for `a_code'
--| Note this is a default implemantation, and could be redefined
--| for instance in relation to NPH CGI script
local
s: STRING
do
create s.make (16)
s.append ({HTTP_CONSTANTS}.http_version_1_1)
s.append_character (' ')
s.append_integer (a_code)
if attached http_status_code_message (a_code) as l_status_message then
s.append_character (' ')
s.append_string (l_status_message)
end
put_header_line (s)
end
feature -- Basic operation
put_substring (s: STRING; start_index, end_index: INTEGER)
-- Write `s[start_index:end_index]' into the output stream
require
s_not_empty: s /= Void and then not s.is_empty
do
put_string (s.substring (start_index, end_index))
end
put_file_content (fn: STRING)
-- Send the content of file `fn'
local
f: RAW_FILE
do
create f.make (fn)
if f.exists and then f.is_readable then
f.open_read
from
until
f.exhausted
loop
f.read_stream (4096)
put_string (f.last_string)
end
f.close
end
end
put_header_line (s: STRING)
-- Send `s' to http client as header line
do
put_string (s)
put_string ("%R%N")
end
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