Compare commits
3 Commits
ewf_compre
...
net_sendfi
| Author | SHA1 | Date | |
|---|---|---|---|
| 392c4d570a | |||
| 2cc425dc38 | |||
| 50c1adc365 |
@@ -4,7 +4,10 @@
|
||||
<file_rule>
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
<exclude>l
|
||||
|
||||
|
||||
/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="headers" uuid="C28C4F53-9963-46C0-A080-8F13E94E7486">
|
||||
"1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-10-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-10-0 http://www.eiffel.com/developers/xml/configuration-1-10-0.xsd" name="headers" uuid="C28C4F53-9963-46C0-A080-8F13E94E7486">
|
||||
<target name="common" abstract="true">
|
||||
<file_rule>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
<file_rule>
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
<exclude>l
|
||||
|
||||
|
||||
/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf"/>
|
||||
<library name="wsf" location="..\..\..\..\..\..\library\server\wsf\wsf-safe.ecf"/>
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf"/>
|
||||
<library name="wsf" location="..\..\..\..\..\..\library\server\wsf\wsf-safe.ecf"/>
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="http" location="..\..\..\..\..\..\library\network\protocol\http\http-safe.ecf"/>
|
||||
<library name="http_client" location="$ISE_LIBRARY\contrib\library\network\http_client\http_client-safe.ecf"/>
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
</option>
|
||||
<setting name="console_application" value="true"/>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<capability>
|
||||
<concurrency support="scoop" use="scoop"/>
|
||||
<void_safety support="all"/>
|
||||
</capability>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="encoder" location="..\..\library\text\encoder\encoder-safe.ecf" readonly="false"/>
|
||||
<library name="http" location="..\..\library\network\protocol\http\http-safe.ecf"/>
|
||||
@@ -20,6 +24,9 @@
|
||||
<target name="debug_any" extends="common">
|
||||
<root class="EWF_DEBUG_SERVER" feature="make_and_launch"/>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<capability>
|
||||
<concurrency support="scoop" use="scoop"/>
|
||||
</capability>
|
||||
<library name="cgi" location="..\..\library\server\wsf\connector\cgi-safe.ecf" readonly="false"/>
|
||||
<library name="libfcgi" location="..\..\library\server\wsf\connector\libfcgi-safe.ecf" readonly="false"/>
|
||||
<library name="standalone" location="..\..\library\server\wsf\connector\standalone-safe.ecf" readonly="false"/>
|
||||
@@ -29,6 +36,9 @@
|
||||
<target name="debug_standalone" extends="common">
|
||||
<root class="EWF_DEBUG_SERVER" feature="make_and_launch"/>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<capability>
|
||||
<concurrency support="scoop" use="scoop"/>
|
||||
</capability>
|
||||
<library name="default_standalone" location="..\..\library\server\wsf\default\standalone-safe.ecf" readonly="false"/>
|
||||
<cluster name="launcher" location=".\launcher\default\" recursive="true"/>
|
||||
<cluster name="src" location=".\src\" recursive="true"/>
|
||||
|
||||
@@ -70,6 +70,7 @@ feature {NONE} -- Initialization
|
||||
-- can be added here.
|
||||
local
|
||||
l_browser_box: EV_VERTICAL_BOX
|
||||
l_server_box: EV_VERTICAL_BOX
|
||||
l_hor_box: EV_HORIZONTAL_BOX
|
||||
vb: EV_VERTICAL_BOX
|
||||
do
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="console_application" value="true"/>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<variable name="ssl_supported" value="false"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="http" location="..\..\library\network\protocol\http\http-safe.ecf"/>
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="console_application" value="true"/>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="http" location="..\..\library\network\protocol\http\http-safe.ecf"/>
|
||||
<library name="wsf" location="..\..\library\server\wsf\wsf-safe.ecf"/>
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
port=9090
|
||||
verbose=true
|
||||
socket_recv_timeout=15
|
||||
keep_alive_timeout=30
|
||||
@@ -1,26 +0,0 @@
|
||||
note
|
||||
description : "simple application root class"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
SERVICE_COMPRESSION
|
||||
|
||||
inherit
|
||||
WSF_DEFAULT_SERVICE [SERVICE_COMPRESSION_EXECUTION]
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
|
||||
create
|
||||
make_and_launch
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
initialize
|
||||
do
|
||||
Precursor
|
||||
import_service_options (create {WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI}.make_from_file ("service.ini"))
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="service_compression" uuid="C28C4F53-9963-46C0-A080-8F13E94E7486">
|
||||
<target name="service_compression">
|
||||
<root class="SERVICE_COMPRESSION" feature="make_and_launch"/>
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="default_standalone" location="..\..\library\server\wsf\default\standalone-safe.ecf"/>
|
||||
<library name="http" location="..\..\library\network\protocol\http\http-safe.ecf"/>
|
||||
<library name="wsf" location="..\..\library\server\wsf\wsf-safe.ecf" readonly="false"/>
|
||||
<library name="wsf_compression" location="..\..\library\server\wsf\wsf_compression-safe.ecf" readonly="false"/>
|
||||
<cluster name="service_compression" location=".\" recursive="true">
|
||||
<file_rule>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
</file_rule>
|
||||
</cluster>
|
||||
</target>
|
||||
</system>
|
||||
@@ -1,59 +0,0 @@
|
||||
note
|
||||
description: "Simple file execution, serving home.html, ewf.png and 404.html"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
SERVICE_COMPRESSION_EXECUTION
|
||||
|
||||
inherit
|
||||
WSF_ROUTED_EXECUTION
|
||||
redefine
|
||||
initialize,
|
||||
execute_default
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
|
||||
initialize
|
||||
-- Initialize current service.
|
||||
do
|
||||
Precursor
|
||||
initialize_router
|
||||
end
|
||||
|
||||
setup_router
|
||||
local
|
||||
fhdl: WSF_FILE_SYSTEM_HANDLER_WITH_COMPRESSION
|
||||
do
|
||||
create fhdl.make_hidden ("www")
|
||||
fhdl.set_directory_index (<<"index.html">>)
|
||||
fhdl.compression.set_default_compression_format
|
||||
fhdl.compression.enable_compression_for_media_type ({HTTP_MIME_TYPES}.image_jpg)
|
||||
fhdl.set_not_found_handler (agent (ia_uri: READABLE_STRING_8; ia_req: WSF_REQUEST; ia_res: WSF_RESPONSE)
|
||||
do
|
||||
execute_default (ia_req, ia_res)
|
||||
end)
|
||||
router.handle ("/", fhdl, router.methods_GET)
|
||||
end
|
||||
|
||||
|
||||
execute_default (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Dispatch requests without a matching handler.
|
||||
local
|
||||
not_found: WSF_NOT_FOUND_RESPONSE
|
||||
mesg: WSF_RESPONSE_MESSAGE
|
||||
do
|
||||
create not_found.make (request)
|
||||
not_found.add_suggested_location (request.absolute_script_url (""), "Home", "Back to home page")
|
||||
mesg := not_found
|
||||
res.send (mesg)
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB |
@@ -1,16 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>EWF simple_file example</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>EWF simple_file example</h1>
|
||||
<p>This is a static html file served by EWF.</p>
|
||||
<p>Try to <a href="nowhere.html">get lost</a>.</p>
|
||||
<a href="ewf.png"><img src="ewf.png"/></a>
|
||||
<p>This is the real Eiffel tower.</p>
|
||||
<a href="eiffel.jpg"><img src="eiffel.jpg"/></a>
|
||||
<p>Try to <a href="big_file2.html">load a big file</a>.</p>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -22,10 +22,13 @@ create
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
initialize
|
||||
local
|
||||
opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS
|
||||
do
|
||||
Precursor
|
||||
--| Uncomment the following line, to read options from "ewf.ini" configuration file
|
||||
-- import_service_options (create {WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI} opts.make_from_file ("ewf.ini"))
|
||||
--| Uncomment the following 2 lines, to read options from "ewf.ini" configuration file
|
||||
-- create {WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI} opts.make_from_file ("ewf.ini")
|
||||
-- import_service_options (opts)
|
||||
end
|
||||
|
||||
launch (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS)
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="default_standalone" location="..\..\..\..\..\..\library\server\wsf\default\standalone-safe.ecf"/>
|
||||
<library name="wsf" location="..\..\..\..\..\..\library\server\wsf\wsf-safe.ecf"/>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="default_standalone" location="..\..\..\..\..\..\library\server\wsf\default\standalone-safe.ecf"/>
|
||||
<library name="wsf" location="..\..\..\..\..\..\library\server\wsf\wsf-safe.ecf"/>
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<precompile name="precomp_wsf" location="..\..\..\..\precomp\wsf-scoop-safe.ecf"/>
|
||||
<precompile name="precomp_wsf" location="..\..\..\..\precomp\wsf-safe.ecf"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="default_standalone" location="..\..\..\..\library\server\wsf\default\standalone-safe.ecf"/>
|
||||
<library name="wsf" location="..\..\..\..\library\server\wsf\wsf-safe.ecf"/>
|
||||
@@ -28,6 +27,7 @@
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<precompile name="precomp_wsf-mt" location="..\..\..\..\precomp\wsf-mt-safe.ecf"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="default_standalone" location="..\..\..\..\library\server\wsf\default\standalone-safe.ecf"/>
|
||||
<library name="wsf" location="..\..\..\..\library\server\wsf\wsf-safe.ecf"/>
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<precompile name="precomp_wsf-scoop" location="..\..\..\..\precomp\wsf-scoop-safe.ecf"/>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<precompile name="precomp_wsf-mt" location="..\..\..\..\precomp\wsf-mt-safe.ecf"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="default_standalone" location="..\..\..\..\library\server\wsf\default\standalone-safe.ecf"/>
|
||||
<library name="wsf" location="..\..\..\..\library\server\wsf\wsf-safe.ecf"/>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="default_standalone" location="..\..\..\..\library\server\wsf\default\standalone-safe.ecf"/>
|
||||
<library name="encoder" location="..\..\..\..\library\text\encoder\encoder-safe.ecf" readonly="false"/>
|
||||
|
||||
@@ -207,6 +207,8 @@ feature -- Output
|
||||
|
||||
put_character_noexception (c: CHARACTER)
|
||||
-- Write character `c' to socket.
|
||||
require
|
||||
extendible: extendible
|
||||
do
|
||||
socket_buffer.put_character (c, 0)
|
||||
put_managed_pointer_noexception (socket_buffer, 0, character_8_bytes)
|
||||
@@ -217,13 +219,15 @@ feature -- Output
|
||||
-- No exception raised!
|
||||
local
|
||||
ext: C_STRING
|
||||
do
|
||||
do
|
||||
create ext.make (s)
|
||||
put_managed_pointer_noexception (ext.managed_data, 0, s.count)
|
||||
end
|
||||
|
||||
put_readable_string_8 (s: READABLE_STRING_8)
|
||||
-- Write readable string `s' to socket.
|
||||
require
|
||||
extendible: extendible
|
||||
local
|
||||
ext: C_STRING
|
||||
do
|
||||
@@ -243,6 +247,27 @@ feature -- Status report
|
||||
Result := last_string.count = 1
|
||||
end
|
||||
|
||||
set_bytes_sent (nb: INTEGER)
|
||||
-- Set `bytes_sent` to `nb`;
|
||||
do
|
||||
bytes_sent := nb
|
||||
end
|
||||
|
||||
report_error (m: READABLE_STRING_8)
|
||||
-- Report error, and set `socket_error` to `m`.
|
||||
do
|
||||
socket_error := m
|
||||
end
|
||||
|
||||
feature -- Extension
|
||||
|
||||
socket: HTTP_STREAM_SOCKET
|
||||
-- Associated socket.
|
||||
do
|
||||
Result := Current
|
||||
end
|
||||
|
||||
|
||||
note
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
@@ -8,6 +8,75 @@ note
|
||||
deferred class
|
||||
HTTP_STREAM_SOCKET_EXT
|
||||
|
||||
feature {NONE} -- No-Exception network operation
|
||||
feature -- Extension
|
||||
|
||||
socket: HTTP_STREAM_SOCKET
|
||||
-- Associated socket.
|
||||
-- Used to extend HTTP_STREAM_SOCKET with Current interface.
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- No-Exception network operation
|
||||
|
||||
put_file_content_with_timeout (a_file: FILE; a_offset: INTEGER; a_byte_count: INTEGER; a_timeout: INTEGER)
|
||||
-- Send `a_count' bytes from the content of file `a_file' starting at offset `a_offset'.
|
||||
-- When relevant, use the `a_timeout` to wait on completion (if a_timeout < 0, ignored)
|
||||
require
|
||||
a_file_closed_or_openread: a_file.exists and then (a_file.is_access_readable or a_file.is_closed)
|
||||
byte_count_positive: a_byte_count > 0
|
||||
extendible: socket.extendible
|
||||
local
|
||||
l_close_needed: BOOLEAN
|
||||
l_bytes_sent: INTEGER
|
||||
cs: C_STRING
|
||||
do
|
||||
if a_file.exists and then a_file.is_access_readable then
|
||||
if a_file.is_open_read then
|
||||
l_close_needed := False
|
||||
else
|
||||
l_close_needed := True
|
||||
a_file.open_read
|
||||
end
|
||||
create cs.make (a_file.path.name)
|
||||
l_bytes_sent := c_sendfile (socket.descriptor, a_file.file_pointer, a_offset, a_byte_count, a_timeout)
|
||||
if l_bytes_sent < 0 then
|
||||
socket.report_error ("Network error: sendfile")
|
||||
end
|
||||
socket.set_bytes_sent (l_bytes_sent)
|
||||
if l_close_needed then
|
||||
a_file.close
|
||||
end
|
||||
end
|
||||
ensure
|
||||
bytes_sent_updated: not socket.was_error implies (0 <= socket.bytes_sent and socket.bytes_sent <= a_byte_count)
|
||||
end
|
||||
|
||||
put_file_content (a_file: FILE; a_offset: INTEGER; a_byte_count: INTEGER)
|
||||
-- Send `a_count' bytes from the content of file `a_file' starting at offset `a_offset'.
|
||||
-- When relevant, use the `a_timeout` to wait on completion (if a_timeout < 0, ignored)
|
||||
do
|
||||
put_file_content_with_timeout (a_file, a_offset, a_byte_count, -1)
|
||||
end
|
||||
|
||||
feature {NONE} -- External
|
||||
|
||||
c_sendfile (a_fd: INTEGER; fp: POINTER; a_offset: INTEGER; len: INTEGER; a_timeout: INTEGER): INTEGER
|
||||
-- External routine to write file content from `fp` of
|
||||
-- length `len' to socket `a_fd'
|
||||
-- note: On Windows, due to asynchronous potential behavior, wait for completion using `timeout` value.
|
||||
-- EIF_INTEGER c_sendfile_noexception(EIF_INTEGER out_fd, FILE* f, EIF_INTEGER offset, EIF_INTEGER length, EIF_INTEGER timeout).
|
||||
external
|
||||
"C blocking"
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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
|
||||
|
||||
@@ -26,28 +26,22 @@ feature -- Initialization
|
||||
valid_port: a_port >= 0
|
||||
do
|
||||
make
|
||||
set_address (create {like address_type}.make_from_address_and_port (a_address, a_port))
|
||||
bind
|
||||
socket.set_address (create {like socket.address_type}.make_from_address_and_port (a_address, a_port))
|
||||
socket.bind
|
||||
end
|
||||
|
||||
feature -- Basic operation
|
||||
feature -- Extension
|
||||
|
||||
bind
|
||||
socket: HTTP_STREAM_SOCKET
|
||||
-- Associated socket.
|
||||
-- Used to extend HTTP_STREAM_SOCKET with Current interface.
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
feature {NONE} -- Externals: socket option levels
|
||||
|
||||
set_address (addr: detachable like address_type)
|
||||
deferred
|
||||
end
|
||||
|
||||
address_type: NETWORK_SOCKET_ADDRESS
|
||||
deferred
|
||||
end
|
||||
|
||||
descriptor: INTEGER
|
||||
-- Socket descriptor of current socket
|
||||
level_sol_socket: INTEGER_32
|
||||
-- SOL_SOCKET level of options
|
||||
deferred
|
||||
end
|
||||
|
||||
@@ -59,7 +53,7 @@ feature -- Socket Recv and Send timeout.
|
||||
require
|
||||
positive_timeout: a_timeout_seconds >= 0
|
||||
do
|
||||
c_set_sock_recv_timeout (descriptor, level_sol_socket, a_timeout_seconds)
|
||||
c_set_sock_recv_timeout (socket.descriptor, level_sol_socket, a_timeout_seconds)
|
||||
end
|
||||
|
||||
set_send_timeout (a_timeout_seconds: INTEGER)
|
||||
@@ -68,16 +62,77 @@ feature -- Socket Recv and Send timeout.
|
||||
require
|
||||
positive_timeout: a_timeout_seconds >= 0
|
||||
do
|
||||
c_set_sock_send_timeout (descriptor, level_sol_socket, a_timeout_seconds)
|
||||
c_set_sock_send_timeout (socket.descriptor, level_sol_socket, a_timeout_seconds)
|
||||
end
|
||||
|
||||
feature -- Output
|
||||
|
||||
put_file_content_with_timeout (a_file: FILE; a_offset: INTEGER; a_byte_count: INTEGER; a_timeout_ms: INTEGER)
|
||||
-- Send `a_count' bytes from the content of file `a_file' starting at offset `a_offset'.
|
||||
-- When relevant, use the `a_timeout_ms` to wait on completion (if a_timeout < 0, ignored)
|
||||
require
|
||||
a_file_closed_or_openread: a_file.exists and then (a_file.is_access_readable or a_file.is_closed)
|
||||
byte_count_positive: a_byte_count > 0
|
||||
extendible: socket.extendible
|
||||
local
|
||||
l_close_needed: BOOLEAN
|
||||
l_remain: INTEGER
|
||||
l_done: BOOLEAN
|
||||
s: STRING
|
||||
l_bytes_sent: INTEGER
|
||||
do
|
||||
if a_file.exists and then a_file.is_access_readable then
|
||||
if a_file.is_open_read then
|
||||
l_close_needed := False
|
||||
else
|
||||
l_close_needed := True
|
||||
a_file.open_read
|
||||
end
|
||||
if a_offset > 0 then
|
||||
a_file.move (a_offset)
|
||||
end
|
||||
from
|
||||
l_remain := a_byte_count
|
||||
l_done := False
|
||||
until
|
||||
a_file.exhausted or l_done
|
||||
loop
|
||||
a_file.read_stream (l_remain.min (4_096))
|
||||
s := a_file.last_string
|
||||
if s.is_empty then
|
||||
-- File error?
|
||||
l_done := True
|
||||
else
|
||||
socket.put_string_8_noexception (s)
|
||||
l_bytes_sent := l_bytes_sent + socket.bytes_sent
|
||||
l_remain := l_remain - s.count
|
||||
check l_remain >= 0 end
|
||||
l_done := l_remain = 0
|
||||
end
|
||||
end
|
||||
socket.set_bytes_sent (l_bytes_sent)
|
||||
if l_close_needed then
|
||||
a_file.close
|
||||
end
|
||||
end
|
||||
ensure
|
||||
bytes_sent_updated: not socket.was_error implies (0 <= socket.bytes_sent and socket.bytes_sent <= a_byte_count)
|
||||
end
|
||||
|
||||
put_file_content (a_file: FILE; a_offset: INTEGER; a_byte_count: INTEGER)
|
||||
-- Send `a_count' bytes from the content of file `a_file' starting at offset `a_offset'.
|
||||
require
|
||||
a_file_closed_or_openread: a_file.exists and then (a_file.is_access_readable or a_file.is_closed)
|
||||
byte_count_positive: a_byte_count > 0
|
||||
extendible: socket.extendible
|
||||
do
|
||||
put_file_content_with_timeout (a_file, a_offset, a_byte_count, -1)
|
||||
ensure
|
||||
bytes_sent_updated: not socket.was_error implies (0 <= socket.bytes_sent and socket.bytes_sent <= a_byte_count)
|
||||
end
|
||||
|
||||
feature {NONE} -- Externals
|
||||
|
||||
level_sol_socket: INTEGER
|
||||
-- SOL_SOCKET level of options
|
||||
deferred
|
||||
end
|
||||
|
||||
c_set_sock_recv_timeout (a_fd, a_level: INTEGER; a_timeout_seconds: INTEGER)
|
||||
-- C routine to set socket option `SO_RCVTIMEO' with `a_timeout_seconds' seconds.
|
||||
external
|
||||
@@ -157,4 +212,14 @@ feature {NONE} -- No-Exception network operation
|
||||
]"
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="all">
|
||||
<option warning="true" void_safety="all">
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<setting name="concurrency" value="none"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="http" location="..\http-safe.ecf" readonly="false">
|
||||
<option>
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="none">
|
||||
<option warning="true" void_safety="none">
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<setting name="concurrency" value="none"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="http" location="..\http.ecf"/>
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing.ecf"/>
|
||||
|
||||
@@ -29,8 +29,10 @@ feature {NONE} -- Initialization
|
||||
|
||||
create ws_client.make_with_port ("ws://echo.websocket.org", 80, Void)
|
||||
-- create ws_client.make_with_port ("ws://127.0.0.1", 9090, Void)
|
||||
ws_client.launch
|
||||
ws_client.join_all
|
||||
|
||||
ws_client.execute
|
||||
execution_environment.sleep (5_000_000)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -7,10 +7,9 @@
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="all">
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<setting name="console_application" value="true"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="web_socket_client" location="..\..\web_socket_client-safe.ecf" readonly="false"/>
|
||||
@@ -18,7 +17,7 @@
|
||||
</target>
|
||||
<target name="ws_client" extends="common">
|
||||
<root class="APPLICATION" feature="make"/>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
</target>
|
||||
<target name="ws_client_ssl" extends="ws_client">
|
||||
<variable name="ssl_enabled" value="true"/>
|
||||
|
||||
@@ -23,6 +23,11 @@ inherit
|
||||
|
||||
WEB_SOCKET
|
||||
|
||||
THREAD
|
||||
rename
|
||||
make as thread_make
|
||||
end
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
initialize (a_uri: READABLE_STRING_GENERAL; a_protocols: detachable ITERABLE [STRING])
|
||||
@@ -30,6 +35,7 @@ feature -- Initialization
|
||||
require
|
||||
is_valid_uri: is_valid_uri (a_uri)
|
||||
do
|
||||
thread_make
|
||||
uri := a_uri
|
||||
set_default_port
|
||||
create protocol.make_empty
|
||||
@@ -44,6 +50,7 @@ feature -- Initialization
|
||||
require
|
||||
is_valid_uri: is_valid_uri (a_uri)
|
||||
do
|
||||
thread_make
|
||||
uri := a_uri
|
||||
port := a_port
|
||||
create protocol.make_empty
|
||||
@@ -57,9 +64,11 @@ feature -- Initialization
|
||||
require
|
||||
is_valid_uri: is_valid_uri (a_host)
|
||||
do
|
||||
thread_make
|
||||
uri := a_host + ":" + a_port.out + a_path
|
||||
port := a_port
|
||||
create protocol.make_empty
|
||||
-- set_protocols (a_protocols)
|
||||
create ready_state.make
|
||||
socket := new_socket (port, host)
|
||||
create server_handshake.make
|
||||
@@ -89,10 +98,8 @@ feature -- Access
|
||||
local
|
||||
l_uri: URI
|
||||
do
|
||||
if a_uri.is_valid_as_string_8 then
|
||||
create l_uri.make_from_string (a_uri.to_string_8)
|
||||
Result := l_uri.is_valid
|
||||
end
|
||||
create l_uri.make_from_string (a_uri.as_string_8)
|
||||
Result := l_uri.is_valid
|
||||
end
|
||||
|
||||
server_handshake: WEB_SOCKET_HANDSHAKE_DATA
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<library name="lib_http_network" location="..\..\http_network\http_network-safe.ecf"/>
|
||||
<library name="lib_web_socket_protocol" location="..\protocol\web_socket_protocol-safe.ecf"/>
|
||||
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf"/>
|
||||
<library name="thread" location="$ISE_LIBRARY\library\thread\thread-safe.ecf"/>
|
||||
<library name="uri" location="$ISE_LIBRARY\library\text\uri\uri-safe.ecf"/>
|
||||
<cluster name="web_socket_client" location=".\src\" recursive="true">
|
||||
<file_rule>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="none">
|
||||
<option warning="true" void_safety="none">
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
@@ -17,6 +17,7 @@
|
||||
<library name="lib_http_network" location="..\..\http_network\http_network.ecf"/>
|
||||
<library name="lib_web_socket_protocol" location="..\protocol\web_socket_protocol.ecf"/>
|
||||
<library name="net" location="$ISE_LIBRARY\library\net\net.ecf"/>
|
||||
<library name="thread" location="$ISE_LIBRARY\library\thread\thread.ecf"/>
|
||||
<library name="uri" location="$ISE_LIBRARY\library\text\uri\uri.ecf"/>
|
||||
<cluster name="web_socket_client" location=".\src\" recursive="true">
|
||||
<file_rule>
|
||||
|
||||
@@ -12,6 +12,9 @@ class
|
||||
|
||||
inherit
|
||||
WGI_OUTPUT_STREAM
|
||||
redefine
|
||||
put_file_content
|
||||
end
|
||||
|
||||
HTTP_STATUS_CODE_MESSAGES
|
||||
export
|
||||
@@ -94,6 +97,18 @@ feature -- Output
|
||||
last_target_call_succeed := not target.was_error
|
||||
end
|
||||
|
||||
put_file_content (a_file: FILE; a_offset: INTEGER; a_byte_count: INTEGER)
|
||||
-- Send `a_byte_count' bytes from the content of file `a_file' starting at offset `a_offset'.
|
||||
do
|
||||
if a_byte_count > 500_000 then
|
||||
last_target_call_succeed := False
|
||||
target.put_file_content (a_file, a_offset, a_byte_count)
|
||||
last_target_call_succeed := not target.was_error
|
||||
else
|
||||
Precursor (a_file, a_offset, a_byte_count)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_available: BOOLEAN
|
||||
|
||||
@@ -106,9 +106,7 @@ feature -- Output operation
|
||||
put_file_content (f: FILE; a_offset: INTEGER; a_count: INTEGER)
|
||||
-- Send `a_count' bytes from the content of file `f' starting at offset `a_offset'.
|
||||
do
|
||||
if a_count > 0 then
|
||||
output.put_file_content (f, a_offset, a_count)
|
||||
end
|
||||
output.put_file_content (f, a_offset, a_count)
|
||||
end
|
||||
|
||||
flush
|
||||
|
||||
@@ -170,9 +170,6 @@ feature -- Status change
|
||||
-- Report error occurred, with optional message `m'.
|
||||
do
|
||||
has_error := True
|
||||
if m /= Void and then is_verbose then
|
||||
log (m.as_string_8, debug_level)
|
||||
end
|
||||
end
|
||||
|
||||
reset_error
|
||||
@@ -316,7 +313,7 @@ feature -- Execution
|
||||
is_persistent_connection_requested := False
|
||||
else
|
||||
if is_verbose then
|
||||
log_with_separation_line (request_header, information_level)
|
||||
log (request_header, information_level)
|
||||
end
|
||||
process_request (l_socket)
|
||||
end
|
||||
@@ -593,26 +590,6 @@ feature -- Output
|
||||
logger_set: logger = a_logger
|
||||
end
|
||||
|
||||
log_with_separation_line (m: STRING; a_level: INTEGER)
|
||||
-- Log message `m'.
|
||||
require
|
||||
is_verbose: is_verbose
|
||||
local
|
||||
s: STRING
|
||||
do
|
||||
if is_verbose and (verbose_level & a_level) = a_level then
|
||||
create s.make (m.count + 42)
|
||||
s.append (create {STRING}.make_filled ('-', 40))
|
||||
s.append_character ('%N')
|
||||
s.append (m)
|
||||
if attached logger as l_logger then
|
||||
l_logger.log (s)
|
||||
else
|
||||
io.put_string (s + "%N")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
log (m: STRING; a_level: INTEGER)
|
||||
-- Log message `m'.
|
||||
require
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="all">
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<setting name="concurrency" value="none"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="encoder" location="..\..\..\..\..\..\text\encoder\encoder-safe.ecf"/>
|
||||
<library name="ewsgi" location="..\..\ewsgi-safe.ecf" readonly="false"/>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="none">
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<setting name="concurrency" value="none"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="encoder" location="..\..\..\..\..\..\text\encoder\encoder.ecf"/>
|
||||
<library name="ewsgi" location="..\..\ewsgi.ecf" readonly="false"/>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="all">
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<setting name="concurrency" value="none"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="connector_nino" location="..\..\..\..\obsolete\v0\ewsgi\connectors\nino\nino-safe.ecf"/>
|
||||
<library name="encoder" location="..\..\..\..\..\text\encoder\encoder-safe.ecf" readonly="false"/>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="none">
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="connector_nino" location="..\..\..\..\obsolete\v0\ewsgi\connectors\nino\nino.ecf"/>
|
||||
<library name="encoder" location="..\..\..\..\..\text\encoder\encoder.ecf" readonly="false"/>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="all">
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<setting name="concurrency" value="none"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="wsf" location="..\wsf-safe.ecf"/>
|
||||
<library name="wsf_nino" location="..\connector\nino-safe.ecf"/>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="none">
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<setting name="concurrency" value="none"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="wsf" location="..\wsf.ecf"/>
|
||||
<library name="wsf_nino" location="..\connector\nino.ecf"/>
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {WSF_COMPRESSION}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_COMPRESSION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Initialize compression support, by default no compression
|
||||
-- Gzip with the following media types
|
||||
-- applications/javascript
|
||||
-- application/json
|
||||
-- application/xml
|
||||
-- text/css
|
||||
-- text/html
|
||||
--
|
||||
do
|
||||
-- compression algorithms
|
||||
create {ARRAYED_LIST [STRING]} compression_supported_formats.make (0)
|
||||
compression_supported_formats.compare_objects
|
||||
|
||||
-- media types supported by compression.
|
||||
create {ARRAYED_LIST [STRING]} compression_enabled_media_types.make (0)
|
||||
compression_enabled_media_types.compare_objects
|
||||
set_default_compression_enabled_media_types
|
||||
end
|
||||
|
||||
feature -- Query
|
||||
|
||||
encoding_variants (req: WSF_REQUEST; ct: STRING): detachable HTTP_ACCEPT_ENCODING_VARIANTS
|
||||
-- If the client support compression and the server support one of the algorithms
|
||||
-- compress it and update the response header.
|
||||
local
|
||||
conneg : SERVER_CONTENT_NEGOTIATION
|
||||
do
|
||||
if
|
||||
attached req.http_accept_encoding as l_http_encoding and then
|
||||
not compression_supported_formats.is_empty and then
|
||||
compression_enabled_media_types.has (ct)
|
||||
then
|
||||
create conneg.make ("", "", "", "")
|
||||
Result := conneg.encoding_preference (compression_supported_formats, l_http_encoding)
|
||||
if not Result.is_acceptable then
|
||||
Result := Void
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Compression: constants
|
||||
|
||||
gzip_compression_format: STRING = "gzip"
|
||||
-- RFC 1952 (gzip compressed format)
|
||||
|
||||
deflate_compression_format: STRING = "deflate"
|
||||
-- RFC 1951 (deflate compressed format)
|
||||
|
||||
compress_compression_format: STRING = "compress"
|
||||
-- RFC 1950 (zlib compressed format)
|
||||
|
||||
feature -- Compression
|
||||
|
||||
compression_supported_formats : LIST [STRING]
|
||||
-- Server side compression supported formats.
|
||||
-- Supported compression agorithms: `gzip_compression_format', `deflate_compression_format', `compress_compression_format'.
|
||||
-- identity, means no compression at all.
|
||||
|
||||
compression_enabled_media_types: LIST [STRING]
|
||||
-- List of media types supported by compression.
|
||||
|
||||
set_default_compression_format
|
||||
-- gzip default format
|
||||
do
|
||||
enable_gzip_compression
|
||||
end
|
||||
|
||||
disable_all_compression_formats
|
||||
-- Remove all items.
|
||||
do
|
||||
compression_supported_formats.wipe_out
|
||||
end
|
||||
|
||||
enable_gzip_compression
|
||||
-- add 'gzip' format to the list of 'compression_supported' formats.
|
||||
do
|
||||
compression_supported_formats.force (gzip_compression_format)
|
||||
ensure
|
||||
has_gzip: compression_supported_formats.has (gzip_compression_format)
|
||||
end
|
||||
|
||||
disable_gzip_compression
|
||||
-- remove 'gzip' format to the list of 'compression_supported' formats.
|
||||
do
|
||||
compression_supported_formats.prune (gzip_compression_format)
|
||||
ensure
|
||||
not_gzip: not compression_supported_formats.has (gzip_compression_format)
|
||||
end
|
||||
|
||||
enable_deflate_compression
|
||||
-- add 'deflate' format to the list of 'compression_supported' formats.
|
||||
do
|
||||
compression_supported_formats.force (deflate_compression_format)
|
||||
ensure
|
||||
has_deflate: compression_supported_formats.has (deflate_compression_format)
|
||||
end
|
||||
|
||||
disable_deflate_compression
|
||||
-- remove 'deflate' format to the list of 'compression_supported' formats.
|
||||
do
|
||||
compression_supported_formats.prune (deflate_compression_format)
|
||||
ensure
|
||||
not_deflate: not compression_supported_formats.has (deflate_compression_format)
|
||||
end
|
||||
|
||||
enable_compress_compression
|
||||
-- add 'compress' format to the list of 'compression_supported' formats
|
||||
do
|
||||
compression_supported_formats.force (compress_compression_format)
|
||||
ensure
|
||||
has_compress: compression_supported_formats.has (compress_compression_format)
|
||||
end
|
||||
|
||||
disable_compress_compression
|
||||
-- remove 'deflate' format to the list of 'compression_supported' formats.
|
||||
do
|
||||
compression_supported_formats.prune (compress_compression_format)
|
||||
ensure
|
||||
no_compress: not compression_supported_formats.has (compress_compression_format)
|
||||
end
|
||||
|
||||
feature -- Compression: media types
|
||||
|
||||
set_default_compression_enabled_media_types
|
||||
-- Default media types
|
||||
-- applications/javascript
|
||||
-- application/json
|
||||
-- application/xml
|
||||
-- text/css
|
||||
-- text/html
|
||||
-- text/plain
|
||||
do
|
||||
compression_enabled_media_types.force ({HTTP_MIME_TYPES}.application_javascript)
|
||||
compression_enabled_media_types.force ({HTTP_MIME_TYPES}.application_json)
|
||||
compression_enabled_media_types.force ({HTTP_MIME_TYPES}.application_xml)
|
||||
compression_enabled_media_types.force ({HTTP_MIME_TYPES}.text_css)
|
||||
compression_enabled_media_types.force ({HTTP_MIME_TYPES}.text_html)
|
||||
compression_enabled_media_types.force ({HTTP_MIME_TYPES}.text_plain)
|
||||
end
|
||||
|
||||
remove_all_compression_enabled_media_types
|
||||
-- Remove all items.
|
||||
do
|
||||
compression_enabled_media_types.wipe_out
|
||||
end
|
||||
|
||||
enable_compression_for_media_type (a_media_type: STRING)
|
||||
do
|
||||
compression_enabled_media_types.force (a_media_type)
|
||||
ensure
|
||||
has_media_type: compression_enabled_media_types.has (a_media_type)
|
||||
end
|
||||
|
||||
feature -- Compress Data
|
||||
|
||||
compressed_string (a_string: STRING; a_encoding: STRING): STRING
|
||||
-- Compress `a_string' using `deflate_compression_format'
|
||||
local
|
||||
dc: ZLIB_STRING_COMPRESS
|
||||
do
|
||||
create Result.make_empty
|
||||
create dc.string_stream_with_size (Result, 32_768) -- chunk size 32k
|
||||
dc.put_string_with_options (a_string, {ZLIB_CONSTANTS}.Z_default_compression, zlb_strategy (a_encoding), 8, {ZLIB_CONSTANTS}.z_default_strategy.to_integer_32)
|
||||
-- We use the default compression level
|
||||
-- We use the default value for windows bits, the range is 8..15. Higher values use more memory, but produce smaller output.
|
||||
-- Memory: Higher values use more memory, but are faster and produce smaller output. The default is 8, we use 9.
|
||||
end
|
||||
|
||||
zlb_strategy (a_encoding: STRING): INTEGER
|
||||
do
|
||||
if a_encoding.is_case_insensitive_equal_general (gzip_compression_format) then
|
||||
Result := {ZLIB_CONSTANTS}.z_default_window_bits + 16
|
||||
elseif a_encoding.is_case_insensitive_equal_general (deflate_compression_format) then
|
||||
Result := -{ZLIB_CONSTANTS}.z_default_window_bits
|
||||
else
|
||||
check compress: a_encoding.is_case_insensitive_equal_general (compress_compression_format) end
|
||||
Result := {ZLIB_CONSTANTS}.z_default_window_bits
|
||||
end
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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
|
||||
@@ -1,87 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FILE_RESPONSE_WITH_COMPRESSION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FILE_RESPONSE_WITH_COMPRESSION
|
||||
|
||||
inherit
|
||||
WSF_FILE_RESPONSE
|
||||
redefine
|
||||
send_to,
|
||||
initialize
|
||||
end
|
||||
|
||||
create
|
||||
make_with_path,
|
||||
make_with_content_type_and_path,
|
||||
make_html_with_path,
|
||||
make,
|
||||
make_with_content_type,
|
||||
make_html
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
initialize
|
||||
do
|
||||
Precursor
|
||||
create compression.make
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
compression: WSF_COMPRESSION
|
||||
|
||||
compression_variants: detachable HTTP_ACCEPT_ENCODING_VARIANTS
|
||||
|
||||
feature -- Compression setting
|
||||
|
||||
apply_compression (req: WSF_REQUEST)
|
||||
do
|
||||
compression_variants := compression.encoding_variants (req, content_type)
|
||||
end
|
||||
|
||||
feature {WSF_RESPONSE} -- Output
|
||||
|
||||
send_to (res: WSF_RESPONSE)
|
||||
local
|
||||
s: detachable READABLE_STRING_8
|
||||
do
|
||||
if attached compression_variants as l_compression_variants and then
|
||||
attached l_compression_variants.encoding as l_encoding and then
|
||||
attached l_compression_variants.vary_header_value as l_vary_header
|
||||
then
|
||||
Precursor (res)
|
||||
else
|
||||
Precursor (res)
|
||||
-- res.set_status_code (status_code)
|
||||
-- if status_code = {HTTP_STATUS_CODE}.not_found then
|
||||
-- else
|
||||
-- res.put_header_text (header.string)
|
||||
-- s := head
|
||||
-- if s /= Void then
|
||||
-- res.put_string (s)
|
||||
-- end
|
||||
-- if not answer_head_request_method then
|
||||
-- send_file_content_to (file_path, res)
|
||||
-- end
|
||||
-- s := bottom
|
||||
-- if s /= Void then
|
||||
-- res.put_string (s)
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
end
|
||||
note
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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
|
||||
@@ -1,113 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FILE_SYSTEM_HANDLER_WITH_COMPRESSION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FILE_SYSTEM_HANDLER_WITH_COMPRESSION
|
||||
|
||||
inherit
|
||||
WSF_FILE_SYSTEM_HANDLER
|
||||
redefine
|
||||
initialize,
|
||||
process_transfert
|
||||
end
|
||||
|
||||
create
|
||||
make_with_path,
|
||||
make_hidden_with_path,
|
||||
make,
|
||||
make_hidden
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
initialize
|
||||
do
|
||||
Precursor
|
||||
create compression.make
|
||||
end
|
||||
|
||||
feature -- Access: compression
|
||||
|
||||
compression: WSF_COMPRESSION
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process_transfert (f: FILE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
ext: READABLE_STRING_32
|
||||
ct: detachable READABLE_STRING_8
|
||||
fres: WSF_FILE_RESPONSE_WITH_COMPRESSION
|
||||
dt: DATE_TIME
|
||||
h: HTTP_HEADER
|
||||
l_file: RAW_FILE
|
||||
l_content: detachable STRING
|
||||
do
|
||||
create fres.make_with_path (f.path)
|
||||
ext := extension (f.path.name)
|
||||
ct := extension_mime_mapping.mime_type (ext)
|
||||
if ct = Void then
|
||||
ct := fres.content_type
|
||||
else
|
||||
fres.set_content_type (ct)
|
||||
end
|
||||
|
||||
-- Check the CLIENT request
|
||||
-- If the client support compression and one of the algorithms is `deflate_compression_format' we can do compression.
|
||||
-- and we need to add the corresponding 'Content-Encoding' with supported compression formats.
|
||||
if
|
||||
attached compression.encoding_variants (req, ct) as l_compression_variants and then
|
||||
attached l_compression_variants.encoding as l_encoding and then
|
||||
attached l_compression_variants.vary_header_value as l_vary_header
|
||||
then
|
||||
create h.make
|
||||
create l_file.make_with_path (create {PATH}.make_from_string (f.path.name))
|
||||
check
|
||||
f_valid: l_file.exists and then l_file.is_access_readable
|
||||
end
|
||||
h.put_last_modified (file_date (l_file))
|
||||
l_file.open_read
|
||||
l_file.read_stream (l_file.count)
|
||||
l_file.close
|
||||
l_content := compression.compressed_string (l_file.last_string, l_encoding)
|
||||
h.add_header ("Content-Encoding:" + l_encoding)
|
||||
h.add_header ("Vary:" + l_vary_header)
|
||||
h.put_content_type (ct)
|
||||
h.put_content_length (l_content.count)
|
||||
|
||||
-- cache control
|
||||
create dt.make_now_utc
|
||||
h.put_utc_date (dt)
|
||||
if max_age >= 0 then
|
||||
h.put_cache_control ("max-age=" +max_age.out)
|
||||
if max_age > 0 then
|
||||
dt := dt.twin
|
||||
dt.second_add (max_age)
|
||||
end
|
||||
h.put_expires_date (dt)
|
||||
end
|
||||
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||
res.put_header_text (h.string)
|
||||
res.put_string (l_content)
|
||||
else
|
||||
Precursor (f, req, res)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
feature -- Support Compress
|
||||
|
||||
|
||||
note
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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
|
||||
@@ -39,7 +39,6 @@ feature {NONE} -- Initialization
|
||||
|
||||
make_with_path (d: like document_root)
|
||||
do
|
||||
initialize
|
||||
max_age := -1
|
||||
if d.is_empty then
|
||||
document_root := execution_environment.current_working_path
|
||||
@@ -74,11 +73,6 @@ feature {NONE} -- Initialization
|
||||
is_hidden: BOOLEAN
|
||||
-- Current mapped handler should be hidden from self documentation
|
||||
|
||||
initialize
|
||||
-- Initialize Current handler.
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Documentation
|
||||
|
||||
mapping_documentation (m: WSF_ROUTER_MAPPING; a_request_methods: detachable WSF_REQUEST_METHODS): WSF_ROUTER_MAPPING_DOCUMENTATION
|
||||
@@ -217,7 +211,7 @@ feature -- Execution
|
||||
fn := resource_filename (uri)
|
||||
create f.make_with_path (fn)
|
||||
if f.exists then
|
||||
if f.is_access_readable then
|
||||
if f.is_readable then
|
||||
if f.is_directory then
|
||||
if index_disabled then
|
||||
process_directory_index_disabled (uri, req, res)
|
||||
@@ -347,8 +341,6 @@ feature -- Execution
|
||||
end
|
||||
|
||||
process_file (f: FILE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
require
|
||||
f_valid: f.exists and then f.is_access_readable
|
||||
do
|
||||
if
|
||||
attached req.meta_string_variable ("HTTP_IF_MODIFIED_SINCE") as s_if_modified_since and then
|
||||
@@ -363,8 +355,6 @@ feature -- Execution
|
||||
end
|
||||
|
||||
process_transfert (f: FILE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
require
|
||||
f_valid: f.exists and then f.is_access_readable
|
||||
local
|
||||
ext: READABLE_STRING_32
|
||||
ct: detachable READABLE_STRING_8
|
||||
|
||||
@@ -43,6 +43,8 @@ feature {NONE} -- Initialize
|
||||
|
||||
initialize_filtered_router
|
||||
-- Initialize `router` and `filter`.
|
||||
local
|
||||
f: like filter
|
||||
do
|
||||
initialize_router
|
||||
initialize_filter
|
||||
@@ -61,7 +63,7 @@ feature -- Execute Filter
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -104,15 +104,6 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_content_type (a_content_type: detachable like content_type)
|
||||
do
|
||||
if a_content_type = Void then
|
||||
get_content_type
|
||||
else
|
||||
content_type := a_content_type
|
||||
end
|
||||
end
|
||||
|
||||
set_max_age (sec: INTEGER)
|
||||
do
|
||||
header.put_cache_control ("max-age=" + sec.out)
|
||||
|
||||
@@ -389,10 +389,8 @@ feature -- Body
|
||||
message_writable: message_writable
|
||||
not_too_big: a_offset + a_count <= f.count
|
||||
do
|
||||
if a_count > 0 then
|
||||
wgi_response.put_file_content (f, a_offset, a_count)
|
||||
increment_transfered_content_length (a_count)
|
||||
end
|
||||
wgi_response.put_file_content (f, a_offset, a_count)
|
||||
increment_transfered_content_length (a_count)
|
||||
end
|
||||
|
||||
feature -- Chunk body
|
||||
|
||||
@@ -125,6 +125,8 @@ feature -- Tests
|
||||
if f2 /= Void then
|
||||
f2.delete
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
content (f: detachable FILE): STRING
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option debug="false" warning="true" void_safety="all">
|
||||
<option debug="true" warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
@@ -22,6 +22,7 @@
|
||||
</library>
|
||||
<library name="http" location="..\..\..\network\protocol\http\http-safe.ecf" readonly="false"/>
|
||||
<library name="http_client" location="..\..\..\network\http_client\net_http_client-safe.ecf" readonly="false"/>
|
||||
<library name="thread" location="$ISE_LIBRARY\library\thread\thread-safe.ecf"/>
|
||||
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
|
||||
<library name="wsf" location="..\wsf-safe.ecf" readonly="false">
|
||||
<option>
|
||||
@@ -34,6 +35,5 @@
|
||||
<target name="wsf_tests" extends="server">
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
|
||||
<tests name="src" location=".\src\" recursive="true"/>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
</target>
|
||||
</system>
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="wsf_compression" uuid="C558E537-1259-4C94-8C49-117D7E821820" library_target="wsf_compression">
|
||||
<target name="wsf_compression">
|
||||
<root all_classes="true"/>
|
||||
<file_rule>
|
||||
<exclude>/.git$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="all">
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="conneg" location="..\..\network\protocol\content_negotiation\conneg-safe.ecf"/>
|
||||
<library name="http" location="..\..\network\protocol\http\http-safe.ecf"/>
|
||||
<library name="wsf" location="wsf-safe.ecf" readonly="false"/>
|
||||
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
|
||||
<library name="zlib" location="$ISE_LIBRARY\unstable\library\compression\zlib\zlib-safe.ecf" readonly="false"/>
|
||||
<cluster name="compression" location=".\compression\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="wsf_compression" uuid="C558E537-1259-4C94-8C49-117D7E821820" library_target="wsf_compression">
|
||||
<target name="wsf_compression">
|
||||
<root all_classes="true"/>
|
||||
<file_rule>
|
||||
<exclude>/.git$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="none">
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="conneg" location="..\..\network\protocol\content_negotiation\conneg.ecf"/>
|
||||
<library name="wsf" location="wsf.ecf"/>
|
||||
<cluster name="compression" location=".\compression\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="precomp_wsf-mt-safe" uuid="72298F1A-98C7-4BED-8617-11DEFEFB625F" library_target="wsf-mt-safe">
|
||||
<target name="wsf-mt-safe">
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="precomp_wsf-mt" uuid="72298F1A-98C7-4BED-8617-11DEFEFB625F" library_target="wsf-mt">
|
||||
<target name="wsf-mt">
|
||||
<root class="ANY"/>
|
||||
<option void_safety="all">
|
||||
</option>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="precomp_wsf-safe" uuid="3E534F9D-A25F-4CAF-8AAF-FF95DA8F8B64" library_target="wsf-safe">
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="precomp_wsf" uuid="3E534F9D-A25F-4CAF-8AAF-FF95DA8F8B64" library_target="wsf-safe">
|
||||
<target name="wsf-safe">
|
||||
<root class="ANY"/>
|
||||
<option void_safety="all">
|
||||
|
||||
Reference in New Issue
Block a user