Merge pull request #49 from colin-adams/protocol_version

First attempt at WSF_HTTP_PROTOCOL_VERSION
This commit is contained in:
Jocelyn Fiat
2013-03-27 10:53:52 -07:00
2 changed files with 87 additions and 37 deletions

View File

@@ -0,0 +1,78 @@
note
description: "[
Parsed form of HTTP-Version field of request line.
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.1 for specification if the protocol is HTTP.
CGI 1.1 (not official specification) supports alternative protocols
and extension tokens. We do not currently recognise any of
these as valid.
date: "$Date$"
revision: "$Revision$"
]"
class WSF_HTTP_PROTOCOL_VERSION
create
make
feature {NONE} -- Initialization
make (a_protocol: READABLE_STRING_8)
-- Create by parsing `a_protocol'.
require
a_protocol_attached: a_protocol /= Void
local
l_tokens: LIST [READABLE_STRING_8]
l_protocol_name, l_protocol_version, l_major, l_minor: STRING_8
do
l_tokens := a_protocol.split ('/')
if l_tokens.count = 2 then
l_protocol_name := l_tokens [1].as_string_8
l_protocol_name.left_adjust
l_protocol_name.right_adjust
if l_protocol_name.is_case_insensitive_equal ({HTTP_CONSTANTS}.http_version_1_0.substring (1, 4)) then
l_protocol_version := l_tokens [2].as_string_8
l_protocol_version.left_adjust
l_protocol_version.right_adjust
l_tokens := l_protocol_version.split ('.')
if l_tokens.count = 2 then
l_major := l_tokens [1].as_string_8
l_major.left_adjust
l_major.right_adjust
l_minor := l_tokens [2].as_string_8
l_minor.left_adjust
l_minor.right_adjust
if l_major.is_natural then
major := l_major.to_natural
is_valid := True
-- We should be able to work with version 2
-- or greater by just functioning as HTTP/1.1
end
if l_minor.is_natural then
minor := l_minor.to_natural
end
end
end
end
end
feature -- Access
major: NATURAL
-- Major version of HTTP protocol;
-- Typically 1
minor: NATURAL
-- Major version of HTTP protocol;
-- Typically 1 or 0
feature -- Status report
is_valid: BOOLEAN
-- Was SERVER_PROTOCOL parsed successfully as HTTP?
end

View File

@@ -19,8 +19,16 @@ feature -- Access
-- Does `req' require use of `proxy_server'?
require
req_attached: req /= Void
local
l_version: WSF_HTTP_PROTOCOL_VERSION
do
if is_http_1_0 (req) then
--| This default version just replies True for HTTP/1.0.
--| For HTTP/0.9 or other protocols, we hope
--| that the connector has already rejected the request. Anyway, a
--| proxy server won't help us (? - is that correct?)
create l_version.make (req.server_protocol)
if l_version.is_valid and then l_version.major = 1 and then
l_version.minor = 0 then
Result := True
end
end
@@ -39,42 +47,6 @@ feature -- Access
Result.scheme.is_case_insensitive_equal ("https")
end
is_http_1_0 (req: WSF_REQUEST): BOOLEAN
-- Does `req' come from an HTTP/1.0 client?
require
req_attached: req /= Void
local
l_protocol: READABLE_STRING_8
l_tokens: LIST [READABLE_STRING_8]
l_protocol_name, l_protocol_version, l_major, l_minor: STRING_8
do
l_protocol := req.server_protocol
l_tokens := l_protocol.split ('/')
if l_tokens.count = 2 then
l_protocol_name := l_tokens [1].as_string_8
l_protocol_name.left_adjust
l_protocol_name.right_adjust
if l_protocol_name.is_case_insensitive_equal ({HTTP_CONSTANTS}.http_version_1_0.substring (1, 4)) then
l_protocol_version := l_tokens [2].as_string_8
l_protocol_version.left_adjust
l_protocol_version.right_adjust
l_tokens := l_protocol_version.split ('.')
if l_tokens.count = 2 then
l_major := l_tokens [1].as_string_8
l_major.left_adjust
l_major.right_adjust
l_minor := l_tokens [2].as_string_8
l_minor.left_adjust
l_minor.right_adjust
if l_major.is_integer and then l_major.to_integer = 1 and then
l_minor.is_integer and then l_minor.to_integer = 0 then
Result := True
end
end
end
end
end
note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"