removed CRLF eol in many files
This commit is contained in:
@@ -1,149 +1,149 @@
|
||||
note
|
||||
description: "Summary description for {HTTP_CONSTANTS}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
HTTP_CONSTANTS
|
||||
|
||||
feature
|
||||
|
||||
http_version_1_1: STRING = "HTTP/1.1"
|
||||
http_version_1_0: STRING = "HTTP/1.0"
|
||||
crlf: STRING = "%/13/%/10/"
|
||||
|
||||
feature -- Status codes
|
||||
|
||||
-- 1xx Informational -Request received, continuing process
|
||||
Continue : STRING = "100"
|
||||
Switching_Protocols : STRING = "101"
|
||||
|
||||
|
||||
-- 2xx Success - The action was successfully received, understood, and accepted
|
||||
Ok: STRING = "200"
|
||||
Created : STRING = "201"
|
||||
Accepted : STRING = "202"
|
||||
Non_Authoritative_Information : STRING = "203"
|
||||
No_Content : STRING = "204"
|
||||
Reset_Content : STRING = "205"
|
||||
Parcial_Content : STRING = "206"
|
||||
|
||||
|
||||
-- 3xx Redirection - Further Action must be taken in order to complete the request
|
||||
Multiple_Choices : STRING = "300"
|
||||
Moved_Permanently: STRING = "301"
|
||||
Found : STRING = "302"
|
||||
See_Other : STRING = "303"
|
||||
Not_Modified : STRING = "304"
|
||||
Use_Proxy : STRING = "305"
|
||||
Temporary_Redirect : STRING = "307"
|
||||
|
||||
|
||||
--4xx Client Error - The request contains bad syntax or cannot be fulfilled
|
||||
Bad_Request : STRING = "400"
|
||||
Unauthorized : STRING = "401"
|
||||
Payment_Required : STRING = "402"
|
||||
Forbidden : STRING = "403"
|
||||
Not_Found : STRING = "404"
|
||||
Method_Not_Allowed : STRING = "405"
|
||||
Not_Acceptable : STRING = "406"
|
||||
Proxy_Authentication_Required : STRING = "407"
|
||||
Request_Time_out : STRING = "408"
|
||||
Conflict : STRING = "409"
|
||||
Gone : STRING = "410"
|
||||
Length_Required : STRING = "411"
|
||||
Precondition_Failed : STRING = "412"
|
||||
Request_Entity_Too_Large : STRING = "413"
|
||||
Request_URI_Too_Large : STRING = "414"
|
||||
Unsupported_Media_Type : STRING = "415"
|
||||
Requested_range_not_satisfiable : STRING = "416"
|
||||
Expectation_Failed : STRING = "417"
|
||||
|
||||
|
||||
--5xx Server Error - The server failed to fulfill an apparently valid request
|
||||
server_error: STRING = "500"
|
||||
Internal_Server_Error : STRING = "500"
|
||||
Not_Implemented : STRING = "501"
|
||||
Bad_Gateway : STRING = "502"
|
||||
Service_Unavailable : STRING = "503"
|
||||
Gateway_Time_out : STRING = "504"
|
||||
HTTP_Version_not_supported : STRING = "505"
|
||||
|
||||
|
||||
-- messages
|
||||
ok_message: STRING = "OK"
|
||||
continue_message : STRING = "Continue"
|
||||
not_found_message: STRING = "URI not found"
|
||||
not_implemented_message: STRING = "Not Implemented"
|
||||
|
||||
feature -- content types
|
||||
|
||||
text_html: STRING = "text/html"
|
||||
|
||||
feature -- General Header Fields
|
||||
|
||||
-- There are a few header fields which have general applicability for both request and response messages,
|
||||
-- but which do not apply to the entity being transferred.
|
||||
-- These header fields apply only to the message being transmitted.
|
||||
|
||||
Cache_control : STRING = "Cache-Control"
|
||||
Connection : STRING = "Connection"
|
||||
Date : STRING = "Date"
|
||||
Pragma : STRING = "PRAGMA"
|
||||
Trailer : STRING = "Trailer"
|
||||
Transfer_encoding : STRING = "Transfer-Encoding"
|
||||
Upgrade : STRING = "Upgrade"
|
||||
Via : STRING = "Via"
|
||||
Warning : STRING = "Warning"
|
||||
|
||||
|
||||
feature -- Request Header
|
||||
Accept : STRING = "Accept"
|
||||
Accept_charset : STRING = "Accept-Charset"
|
||||
Accept_encoding : STRING = "Accept-Encoding"
|
||||
Accept_language : STRING = "Accept-Language"
|
||||
Authorization : STRING = "Authorization"
|
||||
Expect : STRING = "Expect"
|
||||
From_header : STRING = "From"
|
||||
Host : STRING = "Host"
|
||||
If_match : STRING = "If-Match"
|
||||
If_modified_since : STRING = "If-Modified-Since"
|
||||
If_none_match : STRING = "If-None-Match"
|
||||
If_range : STRING = "If-Range"
|
||||
If_unmodified_since : STRING = "If-Unmodified-Since"
|
||||
Max_forwards : STRING = "Max-Forwards"
|
||||
Proxy_authorization : STRING = "Proxy-Authorization"
|
||||
Range : STRING = "Range"
|
||||
Referer : STRING = "Referrer"
|
||||
TE : STRING = "TE"
|
||||
User_agent : STRING = "User-Agent"
|
||||
|
||||
|
||||
feature -- Entity Header
|
||||
|
||||
Allow : STRING = "Allow"
|
||||
Content_encoding : STRING = "Content-Encoding"
|
||||
Content_language : STRING = "Content-Language"
|
||||
Content_length : STRING = "Content-Length"
|
||||
Content_location : STRING = "Content-Location"
|
||||
Content_MD5 : STRING = "Content-MD5"
|
||||
Content_range : STRING = "Content-Range"
|
||||
Content_type : STRING = "Content-Type"
|
||||
Expires : STRING = "Expires"
|
||||
Last_modified : STRING = "Last-Modified"
|
||||
|
||||
|
||||
feature -- Http Method
|
||||
Options : STRING = "OPTIONS"
|
||||
Get : STRING = "GET"
|
||||
Head : STRING = "HEAD"
|
||||
Post : STRING = "POST"
|
||||
Put : STRING = "PUT"
|
||||
Delete : STRING = "DELETE"
|
||||
Trace : STRING = "TRACE"
|
||||
Connect : STRING = "CONNECT"
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
note
|
||||
description: "Summary description for {HTTP_CONSTANTS}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
HTTP_CONSTANTS
|
||||
|
||||
feature
|
||||
|
||||
http_version_1_1: STRING = "HTTP/1.1"
|
||||
http_version_1_0: STRING = "HTTP/1.0"
|
||||
crlf: STRING = "%/13/%/10/"
|
||||
|
||||
feature -- Status codes
|
||||
|
||||
-- 1xx Informational -Request received, continuing process
|
||||
Continue : STRING = "100"
|
||||
Switching_Protocols : STRING = "101"
|
||||
|
||||
|
||||
-- 2xx Success - The action was successfully received, understood, and accepted
|
||||
Ok: STRING = "200"
|
||||
Created : STRING = "201"
|
||||
Accepted : STRING = "202"
|
||||
Non_Authoritative_Information : STRING = "203"
|
||||
No_Content : STRING = "204"
|
||||
Reset_Content : STRING = "205"
|
||||
Parcial_Content : STRING = "206"
|
||||
|
||||
|
||||
-- 3xx Redirection - Further Action must be taken in order to complete the request
|
||||
Multiple_Choices : STRING = "300"
|
||||
Moved_Permanently: STRING = "301"
|
||||
Found : STRING = "302"
|
||||
See_Other : STRING = "303"
|
||||
Not_Modified : STRING = "304"
|
||||
Use_Proxy : STRING = "305"
|
||||
Temporary_Redirect : STRING = "307"
|
||||
|
||||
|
||||
--4xx Client Error - The request contains bad syntax or cannot be fulfilled
|
||||
Bad_Request : STRING = "400"
|
||||
Unauthorized : STRING = "401"
|
||||
Payment_Required : STRING = "402"
|
||||
Forbidden : STRING = "403"
|
||||
Not_Found : STRING = "404"
|
||||
Method_Not_Allowed : STRING = "405"
|
||||
Not_Acceptable : STRING = "406"
|
||||
Proxy_Authentication_Required : STRING = "407"
|
||||
Request_Time_out : STRING = "408"
|
||||
Conflict : STRING = "409"
|
||||
Gone : STRING = "410"
|
||||
Length_Required : STRING = "411"
|
||||
Precondition_Failed : STRING = "412"
|
||||
Request_Entity_Too_Large : STRING = "413"
|
||||
Request_URI_Too_Large : STRING = "414"
|
||||
Unsupported_Media_Type : STRING = "415"
|
||||
Requested_range_not_satisfiable : STRING = "416"
|
||||
Expectation_Failed : STRING = "417"
|
||||
|
||||
|
||||
--5xx Server Error - The server failed to fulfill an apparently valid request
|
||||
server_error: STRING = "500"
|
||||
Internal_Server_Error : STRING = "500"
|
||||
Not_Implemented : STRING = "501"
|
||||
Bad_Gateway : STRING = "502"
|
||||
Service_Unavailable : STRING = "503"
|
||||
Gateway_Time_out : STRING = "504"
|
||||
HTTP_Version_not_supported : STRING = "505"
|
||||
|
||||
|
||||
-- messages
|
||||
ok_message: STRING = "OK"
|
||||
continue_message : STRING = "Continue"
|
||||
not_found_message: STRING = "URI not found"
|
||||
not_implemented_message: STRING = "Not Implemented"
|
||||
|
||||
feature -- content types
|
||||
|
||||
text_html: STRING = "text/html"
|
||||
|
||||
feature -- General Header Fields
|
||||
|
||||
-- There are a few header fields which have general applicability for both request and response messages,
|
||||
-- but which do not apply to the entity being transferred.
|
||||
-- These header fields apply only to the message being transmitted.
|
||||
|
||||
Cache_control : STRING = "Cache-Control"
|
||||
Connection : STRING = "Connection"
|
||||
Date : STRING = "Date"
|
||||
Pragma : STRING = "PRAGMA"
|
||||
Trailer : STRING = "Trailer"
|
||||
Transfer_encoding : STRING = "Transfer-Encoding"
|
||||
Upgrade : STRING = "Upgrade"
|
||||
Via : STRING = "Via"
|
||||
Warning : STRING = "Warning"
|
||||
|
||||
|
||||
feature -- Request Header
|
||||
Accept : STRING = "Accept"
|
||||
Accept_charset : STRING = "Accept-Charset"
|
||||
Accept_encoding : STRING = "Accept-Encoding"
|
||||
Accept_language : STRING = "Accept-Language"
|
||||
Authorization : STRING = "Authorization"
|
||||
Expect : STRING = "Expect"
|
||||
From_header : STRING = "From"
|
||||
Host : STRING = "Host"
|
||||
If_match : STRING = "If-Match"
|
||||
If_modified_since : STRING = "If-Modified-Since"
|
||||
If_none_match : STRING = "If-None-Match"
|
||||
If_range : STRING = "If-Range"
|
||||
If_unmodified_since : STRING = "If-Unmodified-Since"
|
||||
Max_forwards : STRING = "Max-Forwards"
|
||||
Proxy_authorization : STRING = "Proxy-Authorization"
|
||||
Range : STRING = "Range"
|
||||
Referer : STRING = "Referrer"
|
||||
TE : STRING = "TE"
|
||||
User_agent : STRING = "User-Agent"
|
||||
|
||||
|
||||
feature -- Entity Header
|
||||
|
||||
Allow : STRING = "Allow"
|
||||
Content_encoding : STRING = "Content-Encoding"
|
||||
Content_language : STRING = "Content-Language"
|
||||
Content_length : STRING = "Content-Length"
|
||||
Content_location : STRING = "Content-Location"
|
||||
Content_MD5 : STRING = "Content-MD5"
|
||||
Content_range : STRING = "Content-Range"
|
||||
Content_type : STRING = "Content-Type"
|
||||
Expires : STRING = "Expires"
|
||||
Last_modified : STRING = "Last-Modified"
|
||||
|
||||
|
||||
feature -- Http Method
|
||||
Options : STRING = "OPTIONS"
|
||||
Get : STRING = "GET"
|
||||
Head : STRING = "HEAD"
|
||||
Post : STRING = "POST"
|
||||
Put : STRING = "PUT"
|
||||
Delete : STRING = "DELETE"
|
||||
Trace : STRING = "TRACE"
|
||||
Connect : STRING = "CONNECT"
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
note
|
||||
description: "[
|
||||
Provides features to encode and decode messages
|
||||
]"
|
||||
legal: "See notice at end of class."
|
||||
status: "Community Preview 1.0"
|
||||
date: "$Date: 2009-09-01 19:15:37 -0300 (mar 01 de sep de 2009) $"
|
||||
revision: "$Revision: 80577 $"
|
||||
|
||||
class
|
||||
HTTP_ENCODING_FACILITIES
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
encode_natural(a_i: NATURAL; a_is_fragmented: BOOLEAN): NATURAL
|
||||
-- Leftshift of the natural (don't use numbers >= 2^31) and subsequent append of the flag bit.
|
||||
-- Use decode_natural and decode_flag for decoding.
|
||||
require
|
||||
no_too_big: a_i < 2147483648
|
||||
do
|
||||
Result := (a_i |<< 1) + a_is_fragmented.to_integer.as_natural_32
|
||||
end
|
||||
|
||||
change_flag(a_i: NATURAL; a_new_flag: BOOLEAN): NATURAL
|
||||
-- Changes the flag to "new_flag" and doesn't change the encoded natural.
|
||||
do
|
||||
Result := (a_i & 0xFFFFFFFE) + a_new_flag.to_integer.as_natural_32
|
||||
end
|
||||
|
||||
decode_natural_and_flag (a_i: NATURAL): TUPLE [NATURAL, BOOLEAN]
|
||||
-- Convenience feature which combines both decodings (natural and flag)
|
||||
do
|
||||
Result := [decode_natural (a_i), decode_flag (a_i)]
|
||||
end
|
||||
|
||||
decode_natural (a_i: NATURAL): NATURAL
|
||||
-- The natural that was encoded in {ENCODING_FACILITIES}.encode_natural.
|
||||
do
|
||||
Result := (a_i |>> 1)
|
||||
end
|
||||
|
||||
decode_flag (a_i: NATURAL): BOOLEAN
|
||||
--`Result': the flag that was encoded in encode_natural
|
||||
do
|
||||
Result := (a_i.bit_and (1) = 1)
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
note
|
||||
description: "[
|
||||
Provides features to encode and decode messages
|
||||
]"
|
||||
legal: "See notice at end of class."
|
||||
status: "Community Preview 1.0"
|
||||
date: "$Date: 2009-09-01 19:15:37 -0300 (mar 01 de sep de 2009) $"
|
||||
revision: "$Revision: 80577 $"
|
||||
|
||||
class
|
||||
HTTP_ENCODING_FACILITIES
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
encode_natural(a_i: NATURAL; a_is_fragmented: BOOLEAN): NATURAL
|
||||
-- Leftshift of the natural (don't use numbers >= 2^31) and subsequent append of the flag bit.
|
||||
-- Use decode_natural and decode_flag for decoding.
|
||||
require
|
||||
no_too_big: a_i < 2147483648
|
||||
do
|
||||
Result := (a_i |<< 1) + a_is_fragmented.to_integer.as_natural_32
|
||||
end
|
||||
|
||||
change_flag(a_i: NATURAL; a_new_flag: BOOLEAN): NATURAL
|
||||
-- Changes the flag to "new_flag" and doesn't change the encoded natural.
|
||||
do
|
||||
Result := (a_i & 0xFFFFFFFE) + a_new_flag.to_integer.as_natural_32
|
||||
end
|
||||
|
||||
decode_natural_and_flag (a_i: NATURAL): TUPLE [NATURAL, BOOLEAN]
|
||||
-- Convenience feature which combines both decodings (natural and flag)
|
||||
do
|
||||
Result := [decode_natural (a_i), decode_flag (a_i)]
|
||||
end
|
||||
|
||||
decode_natural (a_i: NATURAL): NATURAL
|
||||
-- The natural that was encoded in {ENCODING_FACILITIES}.encode_natural.
|
||||
do
|
||||
Result := (a_i |>> 1)
|
||||
end
|
||||
|
||||
decode_flag (a_i: NATURAL): BOOLEAN
|
||||
--`Result': the flag that was encoded in encode_natural
|
||||
do
|
||||
Result := (a_i.bit_and (1) = 1)
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
note
|
||||
description: "Summary description for {HTTP_SERVER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
HTTP_SERVER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make (cfg: like configuration)
|
||||
do
|
||||
configuration := cfg
|
||||
end
|
||||
|
||||
setup (a_http_handler: HTTP_HANDLER)
|
||||
require
|
||||
a_http_handler_valid: a_http_handler /= Void
|
||||
do
|
||||
if configuration.is_verbose then
|
||||
log ("%N%N%N")
|
||||
log ("Starting Web Application Server (port="+ configuration.http_server_port.out +"):%N")
|
||||
end
|
||||
stop_requested := False
|
||||
a_http_handler.execute
|
||||
end
|
||||
|
||||
shutdown_server
|
||||
do
|
||||
stop_requested := True
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
configuration: HTTP_SERVER_CONFIGURATION
|
||||
-- Configuration of the server
|
||||
|
||||
stop_requested: BOOLEAN
|
||||
-- Stops the server
|
||||
|
||||
feature -- Output
|
||||
|
||||
log (a_message: READABLE_STRING_8)
|
||||
-- Log `a_message'
|
||||
do
|
||||
io.put_string (a_message)
|
||||
end
|
||||
|
||||
;note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
note
|
||||
description: "Summary description for {HTTP_SERVER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
HTTP_SERVER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make (cfg: like configuration)
|
||||
do
|
||||
configuration := cfg
|
||||
end
|
||||
|
||||
setup (a_http_handler: HTTP_HANDLER)
|
||||
require
|
||||
a_http_handler_valid: a_http_handler /= Void
|
||||
do
|
||||
if configuration.is_verbose then
|
||||
log ("%N%N%N")
|
||||
log ("Starting Web Application Server (port="+ configuration.http_server_port.out +"):%N")
|
||||
end
|
||||
stop_requested := False
|
||||
a_http_handler.execute
|
||||
end
|
||||
|
||||
shutdown_server
|
||||
do
|
||||
stop_requested := True
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
configuration: HTTP_SERVER_CONFIGURATION
|
||||
-- Configuration of the server
|
||||
|
||||
stop_requested: BOOLEAN
|
||||
-- Stops the server
|
||||
|
||||
feature -- Output
|
||||
|
||||
log (a_message: READABLE_STRING_8)
|
||||
-- Log `a_message'
|
||||
do
|
||||
io.put_string (a_message)
|
||||
end
|
||||
|
||||
;note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -1,118 +1,118 @@
|
||||
deferred class HTTP_REQUEST_HANDLER
|
||||
|
||||
inherit
|
||||
ANY
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
create request_uri.make_empty
|
||||
create script_name.make_empty
|
||||
create query_string.make_empty
|
||||
create answer
|
||||
create headers.make (0)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
request_uri: STRING
|
||||
-- requested url
|
||||
|
||||
script_name: STRING
|
||||
-- Script name
|
||||
|
||||
query_string: STRING
|
||||
-- Query string
|
||||
|
||||
data: detachable STRING
|
||||
-- the entire request message
|
||||
|
||||
headers : HASH_TABLE [STRING, STRING]
|
||||
-- Provides access to the request's HTTP headers, for example:
|
||||
-- headers["Content-Type"] is "text/plain"
|
||||
|
||||
answer: HTTP_RESPONSE
|
||||
-- reply to this request
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process
|
||||
-- process the request and create an answer
|
||||
require
|
||||
valid_uri: request_uri /= Void
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Recycle
|
||||
|
||||
reset
|
||||
-- reinit the fields
|
||||
do
|
||||
request_uri.wipe_out
|
||||
script_name.wipe_out
|
||||
query_string.wipe_out
|
||||
data := Void
|
||||
answer.reset
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_uri (new_uri: STRING)
|
||||
-- set new URI
|
||||
require
|
||||
valid_uri: new_uri /= Void
|
||||
local
|
||||
p: INTEGER
|
||||
do
|
||||
request_uri := new_uri
|
||||
p := new_uri.index_of ('?', 1)
|
||||
if p > 0 then
|
||||
script_name := new_uri.substring (1, p - 1)
|
||||
query_string := new_uri.substring (p + 1, new_uri.count)
|
||||
else
|
||||
script_name := new_uri.string
|
||||
query_string := ""
|
||||
end
|
||||
end
|
||||
|
||||
set_data (new_data: STRING)
|
||||
-- set new data
|
||||
do
|
||||
data := new_data
|
||||
end
|
||||
|
||||
set_headers ( a_header : HASH_TABLE [STRING, STRING] )
|
||||
do
|
||||
headers := a_header
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
real_filename (fn: STRING): STRING
|
||||
-- Real filename from url-path `fn'
|
||||
--| Find a better design for this piece of code
|
||||
--| Eventually in a spec/$ISE_PLATFORM/ specific cluster
|
||||
do
|
||||
if {PLATFORM}.is_windows then
|
||||
create Result.make_from_string (fn)
|
||||
Result.replace_substring_all ("/", "\")
|
||||
if Result[Result.count] = '\' then
|
||||
Result.remove_tail (1)
|
||||
end
|
||||
else
|
||||
Result := fn
|
||||
if Result[Result.count] = '/' then
|
||||
Result := Result.substring (1, Result.count - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
deferred class HTTP_REQUEST_HANDLER
|
||||
|
||||
inherit
|
||||
ANY
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
create request_uri.make_empty
|
||||
create script_name.make_empty
|
||||
create query_string.make_empty
|
||||
create answer
|
||||
create headers.make (0)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
request_uri: STRING
|
||||
-- requested url
|
||||
|
||||
script_name: STRING
|
||||
-- Script name
|
||||
|
||||
query_string: STRING
|
||||
-- Query string
|
||||
|
||||
data: detachable STRING
|
||||
-- the entire request message
|
||||
|
||||
headers : HASH_TABLE [STRING, STRING]
|
||||
-- Provides access to the request's HTTP headers, for example:
|
||||
-- headers["Content-Type"] is "text/plain"
|
||||
|
||||
answer: HTTP_RESPONSE
|
||||
-- reply to this request
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process
|
||||
-- process the request and create an answer
|
||||
require
|
||||
valid_uri: request_uri /= Void
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Recycle
|
||||
|
||||
reset
|
||||
-- reinit the fields
|
||||
do
|
||||
request_uri.wipe_out
|
||||
script_name.wipe_out
|
||||
query_string.wipe_out
|
||||
data := Void
|
||||
answer.reset
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_uri (new_uri: STRING)
|
||||
-- set new URI
|
||||
require
|
||||
valid_uri: new_uri /= Void
|
||||
local
|
||||
p: INTEGER
|
||||
do
|
||||
request_uri := new_uri
|
||||
p := new_uri.index_of ('?', 1)
|
||||
if p > 0 then
|
||||
script_name := new_uri.substring (1, p - 1)
|
||||
query_string := new_uri.substring (p + 1, new_uri.count)
|
||||
else
|
||||
script_name := new_uri.string
|
||||
query_string := ""
|
||||
end
|
||||
end
|
||||
|
||||
set_data (new_data: STRING)
|
||||
-- set new data
|
||||
do
|
||||
data := new_data
|
||||
end
|
||||
|
||||
set_headers ( a_header : HASH_TABLE [STRING, STRING] )
|
||||
do
|
||||
headers := a_header
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
real_filename (fn: STRING): STRING
|
||||
-- Real filename from url-path `fn'
|
||||
--| Find a better design for this piece of code
|
||||
--| Eventually in a spec/$ISE_PLATFORM/ specific cluster
|
||||
do
|
||||
if {PLATFORM}.is_windows then
|
||||
create Result.make_from_string (fn)
|
||||
Result.replace_substring_all ("/", "\")
|
||||
if Result[Result.count] = '\' then
|
||||
Result.remove_tail (1)
|
||||
end
|
||||
else
|
||||
Result := fn
|
||||
if Result[Result.count] = '/' then
|
||||
Result := Result.substring (1, Result.count - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -1,147 +1,147 @@
|
||||
|
||||
class HTTP_RESPONSE
|
||||
|
||||
inherit
|
||||
HTTP_CONSTANTS
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
create
|
||||
default_create
|
||||
|
||||
feature -- creation
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
set_defaults
|
||||
end
|
||||
|
||||
set_defaults
|
||||
-- Set default values for the reply
|
||||
do
|
||||
status_code := ok
|
||||
create content_length_data.make_empty
|
||||
reason_phrase := ok_message
|
||||
content_type_data := text_html
|
||||
set_reply_text (Void)
|
||||
end
|
||||
|
||||
feature -- Recycle
|
||||
|
||||
reset
|
||||
do
|
||||
set_defaults
|
||||
end
|
||||
|
||||
feature -- response header fields
|
||||
|
||||
status_code: STRING
|
||||
-- status
|
||||
|
||||
content_length_data : STRING
|
||||
-- length
|
||||
|
||||
reason_phrase: STRING
|
||||
-- message, if any
|
||||
|
||||
content_type_data: STRING
|
||||
-- type of content in this reply (eg. text/html)
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_content_length (new_content_length: INTEGER)
|
||||
require
|
||||
positive_or_zero: new_content_length >= 0
|
||||
do
|
||||
content_length_data := new_content_length.out
|
||||
end
|
||||
|
||||
set_status_code (new_status_code: STRING)
|
||||
require
|
||||
not_void: new_status_code /= Void
|
||||
do
|
||||
status_code := new_status_code
|
||||
end
|
||||
|
||||
set_reason_phrase (new_reason_phrase: STRING)
|
||||
require
|
||||
not_void: new_reason_phrase /= Void
|
||||
do
|
||||
reason_phrase := new_reason_phrase
|
||||
end
|
||||
|
||||
set_content_type (new_content_type: STRING)
|
||||
require
|
||||
not_void: new_content_type /= Void
|
||||
do
|
||||
content_type_data := new_content_type
|
||||
end
|
||||
|
||||
feature -- Access: send reply
|
||||
|
||||
reply_header: STRING
|
||||
-- header
|
||||
do
|
||||
Result := http_version_1_1.twin
|
||||
Result.extend (' ')
|
||||
Result.append (status_code)
|
||||
Result.extend (' ')
|
||||
Result.append (reason_phrase)
|
||||
Result.append (crlf)
|
||||
Result.append ({HTTP_SERVER_CONFIGURATION}.Server_details)
|
||||
Result.append (crlf)
|
||||
Result.append (Content_type + ": ")
|
||||
Result.append (content_type_data)
|
||||
Result.append (crlf)
|
||||
Result.append (Content_length + ": ")
|
||||
Result.append (content_length_data)
|
||||
Result.append (crlf)
|
||||
Result.append (crlf)
|
||||
-- TODO: could add the size of data being sent here and
|
||||
-- then keep the connection alive
|
||||
end
|
||||
|
||||
reply_header_continue: STRING
|
||||
-- header
|
||||
do
|
||||
Result := http_version_1_1.twin
|
||||
Result.extend (' ')
|
||||
Result.append (status_code)
|
||||
Result.extend (' ')
|
||||
Result.append (continue_message)
|
||||
Result.append (crlf)
|
||||
Result.append (crlf)
|
||||
-- TODO: could add the size of data being sent here and
|
||||
-- then keep the connection alive
|
||||
end
|
||||
|
||||
reply_text: STRING
|
||||
-- reply text
|
||||
|
||||
feature -- Change element: send reply
|
||||
|
||||
set_reply_text (new_text: detachable STRING)
|
||||
-- text could be Void
|
||||
do
|
||||
if new_text = Void then
|
||||
create reply_text.make_empty
|
||||
else
|
||||
reply_text := new_text
|
||||
end
|
||||
end
|
||||
|
||||
append_reply_text (more_text: STRING)
|
||||
-- add more text to the reply
|
||||
require
|
||||
reply_text /= Void
|
||||
more_text /= Void
|
||||
do
|
||||
reply_text.append (more_text)
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
class HTTP_RESPONSE
|
||||
|
||||
inherit
|
||||
HTTP_CONSTANTS
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
create
|
||||
default_create
|
||||
|
||||
feature -- creation
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
set_defaults
|
||||
end
|
||||
|
||||
set_defaults
|
||||
-- Set default values for the reply
|
||||
do
|
||||
status_code := ok
|
||||
create content_length_data.make_empty
|
||||
reason_phrase := ok_message
|
||||
content_type_data := text_html
|
||||
set_reply_text (Void)
|
||||
end
|
||||
|
||||
feature -- Recycle
|
||||
|
||||
reset
|
||||
do
|
||||
set_defaults
|
||||
end
|
||||
|
||||
feature -- response header fields
|
||||
|
||||
status_code: STRING
|
||||
-- status
|
||||
|
||||
content_length_data : STRING
|
||||
-- length
|
||||
|
||||
reason_phrase: STRING
|
||||
-- message, if any
|
||||
|
||||
content_type_data: STRING
|
||||
-- type of content in this reply (eg. text/html)
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_content_length (new_content_length: INTEGER)
|
||||
require
|
||||
positive_or_zero: new_content_length >= 0
|
||||
do
|
||||
content_length_data := new_content_length.out
|
||||
end
|
||||
|
||||
set_status_code (new_status_code: STRING)
|
||||
require
|
||||
not_void: new_status_code /= Void
|
||||
do
|
||||
status_code := new_status_code
|
||||
end
|
||||
|
||||
set_reason_phrase (new_reason_phrase: STRING)
|
||||
require
|
||||
not_void: new_reason_phrase /= Void
|
||||
do
|
||||
reason_phrase := new_reason_phrase
|
||||
end
|
||||
|
||||
set_content_type (new_content_type: STRING)
|
||||
require
|
||||
not_void: new_content_type /= Void
|
||||
do
|
||||
content_type_data := new_content_type
|
||||
end
|
||||
|
||||
feature -- Access: send reply
|
||||
|
||||
reply_header: STRING
|
||||
-- header
|
||||
do
|
||||
Result := http_version_1_1.twin
|
||||
Result.extend (' ')
|
||||
Result.append (status_code)
|
||||
Result.extend (' ')
|
||||
Result.append (reason_phrase)
|
||||
Result.append (crlf)
|
||||
Result.append ({HTTP_SERVER_CONFIGURATION}.Server_details)
|
||||
Result.append (crlf)
|
||||
Result.append (Content_type + ": ")
|
||||
Result.append (content_type_data)
|
||||
Result.append (crlf)
|
||||
Result.append (Content_length + ": ")
|
||||
Result.append (content_length_data)
|
||||
Result.append (crlf)
|
||||
Result.append (crlf)
|
||||
-- TODO: could add the size of data being sent here and
|
||||
-- then keep the connection alive
|
||||
end
|
||||
|
||||
reply_header_continue: STRING
|
||||
-- header
|
||||
do
|
||||
Result := http_version_1_1.twin
|
||||
Result.extend (' ')
|
||||
Result.append (status_code)
|
||||
Result.extend (' ')
|
||||
Result.append (continue_message)
|
||||
Result.append (crlf)
|
||||
Result.append (crlf)
|
||||
-- TODO: could add the size of data being sent here and
|
||||
-- then keep the connection alive
|
||||
end
|
||||
|
||||
reply_text: STRING
|
||||
-- reply text
|
||||
|
||||
feature -- Change element: send reply
|
||||
|
||||
set_reply_text (new_text: detachable STRING)
|
||||
-- text could be Void
|
||||
do
|
||||
if new_text = Void then
|
||||
create reply_text.make_empty
|
||||
else
|
||||
reply_text := new_text
|
||||
end
|
||||
end
|
||||
|
||||
append_reply_text (more_text: STRING)
|
||||
-- add more text to the reply
|
||||
require
|
||||
reply_text /= Void
|
||||
more_text /= Void
|
||||
do
|
||||
reply_text.append (more_text)
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
note
|
||||
description: "Summary description for {SHARED_URI_CONTENTS_TYPES}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
SHARED_URI_CONTENTS_TYPES
|
||||
feature
|
||||
|
||||
ct_table: URI_CONTENTS_TYPES
|
||||
once
|
||||
create Result.make
|
||||
end
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
note
|
||||
description: "Summary description for {SHARED_URI_CONTENTS_TYPES}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
SHARED_URI_CONTENTS_TYPES
|
||||
feature
|
||||
|
||||
ct_table: URI_CONTENTS_TYPES
|
||||
once
|
||||
create Result.make
|
||||
end
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
note
|
||||
description: "Summary description for {TCP_STREAM_SOCKET}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
TCP_STREAM_SOCKET
|
||||
|
||||
inherit
|
||||
NETWORK_STREAM_SOCKET
|
||||
redefine
|
||||
make
|
||||
end
|
||||
|
||||
create
|
||||
make_server_by_address_and_port,
|
||||
make_server_by_port
|
||||
|
||||
create {NETWORK_STREAM_SOCKET}
|
||||
make_from_descriptor_and_address
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Create a network stream socket.
|
||||
do
|
||||
Precursor
|
||||
set_reuse_address
|
||||
end
|
||||
|
||||
make_server_by_address_and_port (an_address: INET_ADDRESS; a_port: INTEGER)
|
||||
-- Create server socket on `an_address' and `a_port'.
|
||||
require
|
||||
valid_port: a_port >= 0
|
||||
do
|
||||
make
|
||||
create address.make_from_address_and_port (an_address, a_port)
|
||||
bind
|
||||
end
|
||||
|
||||
feature -- Basic operation
|
||||
|
||||
send_message (a_msg: STRING)
|
||||
local
|
||||
a_package : PACKET
|
||||
a_data : MANAGED_POINTER
|
||||
c_string : C_STRING
|
||||
do
|
||||
create c_string.make (a_msg)
|
||||
create a_data.make_from_pointer (c_string.item, a_msg.count + 1)
|
||||
create a_package.make_from_managed_pointer (a_data)
|
||||
send (a_package, 1)
|
||||
end
|
||||
|
||||
feature -- Output
|
||||
|
||||
put_readable_string_8 (s: READABLE_STRING_8)
|
||||
-- Write readable string `s' to socket.
|
||||
local
|
||||
ext: C_STRING
|
||||
do
|
||||
create ext.make (s)
|
||||
put_managed_pointer (ext.managed_data, 0, s.count)
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
try_ready_for_reading: BOOLEAN
|
||||
-- Is data available for reading from the socket right now?
|
||||
require
|
||||
socket_exists: exists
|
||||
local
|
||||
retval: INTEGER
|
||||
do
|
||||
retval := c_select_poll_with_timeout (descriptor, True, 0)
|
||||
Result := (retval > 0)
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
note
|
||||
description: "Summary description for {TCP_STREAM_SOCKET}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
TCP_STREAM_SOCKET
|
||||
|
||||
inherit
|
||||
NETWORK_STREAM_SOCKET
|
||||
redefine
|
||||
make
|
||||
end
|
||||
|
||||
create
|
||||
make_server_by_address_and_port,
|
||||
make_server_by_port
|
||||
|
||||
create {NETWORK_STREAM_SOCKET}
|
||||
make_from_descriptor_and_address
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Create a network stream socket.
|
||||
do
|
||||
Precursor
|
||||
set_reuse_address
|
||||
end
|
||||
|
||||
make_server_by_address_and_port (an_address: INET_ADDRESS; a_port: INTEGER)
|
||||
-- Create server socket on `an_address' and `a_port'.
|
||||
require
|
||||
valid_port: a_port >= 0
|
||||
do
|
||||
make
|
||||
create address.make_from_address_and_port (an_address, a_port)
|
||||
bind
|
||||
end
|
||||
|
||||
feature -- Basic operation
|
||||
|
||||
send_message (a_msg: STRING)
|
||||
local
|
||||
a_package : PACKET
|
||||
a_data : MANAGED_POINTER
|
||||
c_string : C_STRING
|
||||
do
|
||||
create c_string.make (a_msg)
|
||||
create a_data.make_from_pointer (c_string.item, a_msg.count + 1)
|
||||
create a_package.make_from_managed_pointer (a_data)
|
||||
send (a_package, 1)
|
||||
end
|
||||
|
||||
feature -- Output
|
||||
|
||||
put_readable_string_8 (s: READABLE_STRING_8)
|
||||
-- Write readable string `s' to socket.
|
||||
local
|
||||
ext: C_STRING
|
||||
do
|
||||
create ext.make (s)
|
||||
put_managed_pointer (ext.managed_data, 0, s.count)
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
try_ready_for_reading: BOOLEAN
|
||||
-- Is data available for reading from the socket right now?
|
||||
require
|
||||
socket_exists: exists
|
||||
local
|
||||
retval: INTEGER
|
||||
do
|
||||
retval := c_select_poll_with_timeout (descriptor, True, 0)
|
||||
Result := (retval > 0)
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -1,91 +1,91 @@
|
||||
class URI_CONTENTS_TYPES
|
||||
|
||||
create
|
||||
|
||||
make
|
||||
|
||||
|
||||
feature
|
||||
|
||||
content_types: HASH_TABLE [STRING, STRING]
|
||||
|
||||
extension (uri: STRING): STRING
|
||||
-- extract extendion from a URI
|
||||
local
|
||||
i: INTEGER
|
||||
do
|
||||
-- going from the end find the position of the "."
|
||||
from
|
||||
i := uri.count
|
||||
until
|
||||
i = 0 or else uri.item (i) = '.'
|
||||
loop
|
||||
i := i - 1
|
||||
end
|
||||
Result := uri.substring (i+1, uri.count)
|
||||
end
|
||||
|
||||
feature {NONE}
|
||||
|
||||
make
|
||||
do
|
||||
create content_types.make (30)
|
||||
content_types.put ("text/html", "html")
|
||||
content_types.put ("text/html", "htm")
|
||||
content_types.put ("image/gif", "gif")
|
||||
content_types.put ("image/jpeg", "jpeg")
|
||||
content_types.put ("image/png", "jpg")
|
||||
content_types.put ("image/png", "png")
|
||||
end
|
||||
|
||||
|
||||
|
||||
feature -- Access: Encoding
|
||||
|
||||
urlencode (s: STRING): STRING
|
||||
-- URL encode `s'
|
||||
do
|
||||
Result := s.string
|
||||
Result.replace_substring_all ("#", "%%23")
|
||||
Result.replace_substring_all (" ", "%%20")
|
||||
Result.replace_substring_all ("%T", "%%09")
|
||||
Result.replace_substring_all ("%N", "%%0A")
|
||||
Result.replace_substring_all ("/", "%%2F")
|
||||
Result.replace_substring_all ("&", "%%26")
|
||||
Result.replace_substring_all ("<", "%%3C")
|
||||
Result.replace_substring_all ("=", "%%3D")
|
||||
Result.replace_substring_all (">", "%%3E")
|
||||
Result.replace_substring_all ("%"", "%%22")
|
||||
Result.replace_substring_all ("%'", "%%27")
|
||||
end
|
||||
|
||||
urldecode (s: STRING): STRING
|
||||
-- URL decode `s'
|
||||
do
|
||||
Result := s.string
|
||||
Result.replace_substring_all ("%%23", "#")
|
||||
Result.replace_substring_all ("%%20", " ")
|
||||
Result.replace_substring_all ("%%09", "%T")
|
||||
Result.replace_substring_all ("%%0A", "%N")
|
||||
Result.replace_substring_all ("%%2F", "/")
|
||||
Result.replace_substring_all ("%%26", "&")
|
||||
Result.replace_substring_all ("%%3C", "<")
|
||||
Result.replace_substring_all ("%%3D", "=")
|
||||
Result.replace_substring_all ("%%3E", ">")
|
||||
Result.replace_substring_all ("%%22", "%"")
|
||||
Result.replace_substring_all ("%%27", "%'")
|
||||
end
|
||||
|
||||
stripslashes (s: STRING): STRING
|
||||
do
|
||||
Result := s.string
|
||||
Result.replace_substring_all ("\%"", "%"")
|
||||
Result.replace_substring_all ("\'", "'")
|
||||
Result.replace_substring_all ("\/", "/")
|
||||
Result.replace_substring_all ("\\", "\")
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
class URI_CONTENTS_TYPES
|
||||
|
||||
create
|
||||
|
||||
make
|
||||
|
||||
|
||||
feature
|
||||
|
||||
content_types: HASH_TABLE [STRING, STRING]
|
||||
|
||||
extension (uri: STRING): STRING
|
||||
-- extract extendion from a URI
|
||||
local
|
||||
i: INTEGER
|
||||
do
|
||||
-- going from the end find the position of the "."
|
||||
from
|
||||
i := uri.count
|
||||
until
|
||||
i = 0 or else uri.item (i) = '.'
|
||||
loop
|
||||
i := i - 1
|
||||
end
|
||||
Result := uri.substring (i+1, uri.count)
|
||||
end
|
||||
|
||||
feature {NONE}
|
||||
|
||||
make
|
||||
do
|
||||
create content_types.make (30)
|
||||
content_types.put ("text/html", "html")
|
||||
content_types.put ("text/html", "htm")
|
||||
content_types.put ("image/gif", "gif")
|
||||
content_types.put ("image/jpeg", "jpeg")
|
||||
content_types.put ("image/png", "jpg")
|
||||
content_types.put ("image/png", "png")
|
||||
end
|
||||
|
||||
|
||||
|
||||
feature -- Access: Encoding
|
||||
|
||||
urlencode (s: STRING): STRING
|
||||
-- URL encode `s'
|
||||
do
|
||||
Result := s.string
|
||||
Result.replace_substring_all ("#", "%%23")
|
||||
Result.replace_substring_all (" ", "%%20")
|
||||
Result.replace_substring_all ("%T", "%%09")
|
||||
Result.replace_substring_all ("%N", "%%0A")
|
||||
Result.replace_substring_all ("/", "%%2F")
|
||||
Result.replace_substring_all ("&", "%%26")
|
||||
Result.replace_substring_all ("<", "%%3C")
|
||||
Result.replace_substring_all ("=", "%%3D")
|
||||
Result.replace_substring_all (">", "%%3E")
|
||||
Result.replace_substring_all ("%"", "%%22")
|
||||
Result.replace_substring_all ("%'", "%%27")
|
||||
end
|
||||
|
||||
urldecode (s: STRING): STRING
|
||||
-- URL decode `s'
|
||||
do
|
||||
Result := s.string
|
||||
Result.replace_substring_all ("%%23", "#")
|
||||
Result.replace_substring_all ("%%20", " ")
|
||||
Result.replace_substring_all ("%%09", "%T")
|
||||
Result.replace_substring_all ("%%0A", "%N")
|
||||
Result.replace_substring_all ("%%2F", "/")
|
||||
Result.replace_substring_all ("%%26", "&")
|
||||
Result.replace_substring_all ("%%3C", "<")
|
||||
Result.replace_substring_all ("%%3D", "=")
|
||||
Result.replace_substring_all ("%%3E", ">")
|
||||
Result.replace_substring_all ("%%22", "%"")
|
||||
Result.replace_substring_all ("%%27", "%'")
|
||||
end
|
||||
|
||||
stripslashes (s: STRING): STRING
|
||||
do
|
||||
Result := s.string
|
||||
Result.replace_substring_all ("\%"", "%"")
|
||||
Result.replace_substring_all ("\'", "'")
|
||||
Result.replace_substring_all ("\/", "/")
|
||||
Result.replace_substring_all ("\\", "\")
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user