Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:scottgw/http-e-parser

  • Loading branch information...
commit f4e0342469daae0144fdae705ca33212808b3769 2 parents eaa60e7 + 865192f
@scottgw authored
View
42 accept.e
@@ -0,0 +1,42 @@
+note
+ description: "Summary description for {ACCEPT}."
+ author: ""
+ date: "$Date$"
+ revision: "$Revision$"
+
+class
+ ACCEPT
+
+inherit
+ REQUEST_HEADER
+
+create
+ make
+
+feature
+ id: INTEGER = 1
+
+ make (a_types: LIST [TUPLE[STRING, STRING]])
+ do
+ types := a_types
+ end
+
+ types: LIST [TUPLE[fst: STRING; snd: STRING]]
+
+ tag_str: STRING = "Accept"
+
+ content_out: STRING
+ local
+ l: ARRAYED_LIST [STRING]
+ do
+ create l.make (10)
+
+ across
+ types as tc
+ loop
+ l.extend (tc.item.fst + "/" + tc.item.snd)
+ end
+
+ Result := list_sep (l, ',')
+ end
+end
View
33 accept_charset.e
@@ -0,0 +1,33 @@
+note
+ description: "Summary description for {ACCEPT_CHARSET}."
+ author: ""
+ date: "$Date$"
+ revision: "$Revision$"
+
+class
+ ACCEPT_CHARSET
+
+inherit
+ REQUEST_HEADER
+
+create
+ make
+
+feature
+ make (a_sets: LIST [STRING])
+ do
+ charsets := a_sets
+ end
+
+ charsets: LIST [STRING]
+
+ id: INTEGER = 2
+
+ tag_str: STRING = "Accept-Charset"
+
+ content_out: STRING
+ do
+ Result := list_sep (charsets,',')
+ end
+
+end
View
33 accept_encoding.e
@@ -0,0 +1,33 @@
+note
+ description: "Summary description for {ACCEPT_ENCODING}."
+ author: ""
+ date: "$Date$"
+ revision: "$Revision$"
+
+class
+ ACCEPT_ENCODING
+
+inherit
+ REQUEST_HEADER
+
+create
+ make
+
+feature
+ make (a_encodings: LIST [STRING])
+ do
+ encodings := a_encodings
+ end
+
+ encodings: LIST [STRING]
+
+ id: INTEGER = 3
+
+ tag_str: STRING = "Accept-Encoding"
+
+ content_out: STRING
+ do
+ Result := list_sep (encodings, ',')
+ end
+
+end
View
33 accept_language.e
@@ -0,0 +1,33 @@
+note
+ description: "Summary description for {ACCEPT_LANGUAGE}."
+ author: ""
+ date: "$Date$"
+ revision: "$Revision$"
+
+class
+ ACCEPT_LANGUAGE
+
+inherit
+ REQUEST_HEADER
+
+create
+ make
+
+feature
+
+ make (a_langs: LIST [STRING])
+ do
+ langs := a_langs
+ end
+
+ langs: LIST [STRING]
+
+ id: INTEGER = 4
+ tag_str: STRING = "Accept-Language"
+
+ content_out: STRING
+ do
+ Result := list_sep (langs, ',')
+ end
+
+end
View
71 hand_parser.e
@@ -50,6 +50,7 @@ feature {NONE}
local
tag: STRING
list: ARRAYED_LIST [STRING]
+
reqs: ARRAYED_LIST [REQUEST_HEADER]
gens: ARRAYED_LIST [GENERAL_HEADER]
alive: BOOLEAN
@@ -59,28 +60,78 @@ feature {NONE}
tag := words [1]
if tag.is_equal ("Accept") then
- list := tokenize_comma (words [2])
- reqs.extend (create {REQUEST_HEADER}.accept (list))
+ parse_accepts (words [2])
elseif tag.is_equal ("Accept-Language") then
list := tokenize_comma (words [2])
- reqs.extend (create {REQUEST_HEADER}.accept_language (list))
+ request.add_accept_language (list)
elseif tag.is_equal ("Accept-Charset") then
list := tokenize_comma (words [2])
- reqs.extend (create {REQUEST_HEADER}.accept_charset (list))
+ request.add_accept_charset (list)
elseif tag.is_equal ("Accept-Encoding") then
list := tokenize_comma (words [2])
- reqs.extend (create {REQUEST_HEADER}.accept_encoding (list))
+ request.add_accept_encoding (list)
elseif tag.is_equal ("Host") then
- reqs.extend (create {REQUEST_HEADER}.host (words[2]))
+ request.add_host (words [2])
elseif tag.is_equal ("User-Agent") then
- list := words.twin
- list.go_i_th (2)
- list.remove_left
- reqs.extend (create {REQUEST_HEADER}.user_agent (words))
+ request.add_user_agent (words [2])
elseif tag.is_equal ("Connection") then
alive := words[2].as_lower.is_equal ("keep-alive")
gens.extend (create {GENERAL_HEADER}.connection (alive))
+ elseif tag.is_equal ("Range") then
+ request.add_range (parse_range (words[2]))
+ end
+ end
+
+ parse_accepts (a_str: STRING)
+ local
+ types: LIST [STRING]
+ type_split: LIST [STRING]
+ tuple_list: ARRAYED_LIST [TUPLE [STRING, STRING]]
+ do
+ types := tokenize_comma (a_str)
+
+ create tuple_list.make (10)
+
+ across
+ types as tc
+ loop
+ --
+ type_split := tc.item.split ('/')
+ tuple_list.extend ([type_split [1], type_split [2]])
+ end
+
+ request.add_accept (tuple_list)
+ end
+
+ parse_range (a_str: STRING): INTEGER_INTERVAL
+ local
+ start_range: STRING
+ end_range: STRING
+ split: LIST [STRING]
+ start_i: INTEGER
+ end_i: INTEGER
+ do
+ split := a_str.split ('=')
+ start_range := split [1]
+ end_range := split [2]
+
+ if start_range.is_empty then
+ start_i := -1
+ elseif start_range.is_integer then
+ start_i := start_range.to_integer
+ else
+ error := True
+ end
+
+ if end_range.is_empty then
+ end_i := {INTEGER}.max_value
+ elseif end_range.is_integer then
+ end_i := end_range.to_integer
+ else
+ error := True
end
+
+ create Result.make (start_i, end_i)
end
parse_first_line (words: ARRAYED_LIST [STRING])
View
33 host.e
@@ -0,0 +1,33 @@
+note
+ description: "Summary description for {HOST}."
+ author: ""
+ date: "$Date$"
+ revision: "$Revision$"
+
+class
+ HOST
+
+inherit
+ REQUEST_HEADER
+
+create
+ make
+
+feature
+ make (a_host: STRING)
+ do
+ host := a_host
+ end
+
+ id: INTEGER = 8
+
+ tag_str: STRING = "Host"
+
+ content_out: STRING
+ do
+ Result := host
+ end
+
+ host: STRING
+
+end
View
50 http_request.e
@@ -54,6 +54,56 @@ feature
uri := a_uri
end
+ add_range (int: INTEGER_INTERVAL)
+ do
+ create range.make (int)
+ request_headers.extend (range)
+ end
+
+ add_accept (list: LIST [TUPLE [STRING, STRING]])
+ do
+ create accept.make (list)
+ request_headers.extend (accept)
+ end
+
+ add_accept_language (list: LIST [STRING])
+ do
+ create accept_language.make (list)
+ request_headers.extend (accept_language)
+ end
+
+ add_accept_charset (list: LIST [STRING])
+ do
+ create accept_charset.make (list)
+ request_headers.extend (accept_charset)
+ end
+
+ add_accept_encoding (list: LIST [STRING])
+ do
+ create accept_encoding.make (list)
+ request_headers.extend (accept_encoding)
+ end
+
+ add_user_agent (a_str: STRING)
+ do
+ create user_agent.make (a_str)
+ request_headers.extend (user_agent)
+ end
+
+ add_host (a_str: STRING)
+ do
+ create host.make (a_str)
+ request_headers.extend (host)
+ end
+
+ range: RANGE
+ accept: ACCEPT
+ accept_language: ACCEPT_LANGUAGE
+ accept_charset: ACCEPT_CHARSET
+ accept_encoding: ACCEPT_ENCODING
+ user_agent: USER_AGENT
+ host: HOST
+
general_headers: ARRAYED_LIST [GENERAL_HEADER]
request_headers: ARRAYED_LIST [REQUEST_HEADER]
View
42 range.e
@@ -0,0 +1,42 @@
+note
+ description: "Summary description for {RANGE}."
+ author: ""
+ date: "$Date$"
+ revision: "$Revision$"
+
+class
+ RANGE
+
+inherit
+ REQUEST_HEADER
+
+create
+ make
+
+feature
+ id: INTEGER = 16
+
+ make (a_interval: INTEGER_INTERVAL)
+ do
+ interval := a_interval
+ end
+
+ interval: INTEGER_INTERVAL
+
+ tag_str: STRING = "Range"
+
+ content_out: STRING
+ do
+ Result := "bytes="
+ if interval.lower >= 0 then
+ Result := Result + interval.lower.out
+ end
+
+ Result := Result + "-"
+
+ if interval.upper < {INTEGER}.max_value then
+ Result := Result + interval.upper.out
+ end
+ end
+
+end
View
96 request_header.e
@@ -4,7 +4,7 @@ note
date: "$Date$"
revision: "$Revision$"
-class
+deferred class
REQUEST_HEADER
inherit
@@ -13,81 +13,29 @@ inherit
out
end
-create
- accept,
- accept_charset,
- accept_encoding,
- accept_language,
- host,
- user_agent
-
feature
- host (a_address: STRING)
- do
- id := Host_id
- str := a_address
+ content_out: STRING
+ deferred
end
- accept (a_list: ARRAYED_LIST [STRING])
- do
- id := Accept_id
- list := a_list
- end
-
- accept_charset (a_list: ARRAYED_LIST [STRING])
- do
- id := Accept_charset_id
- list := a_list
- end
-
- accept_encoding (a_list: ARRAYED_LIST [STRING])
- do
- id := Accept_encoding_id
- list := a_list
- end
-
- accept_language (a_list: ARRAYED_LIST [STRING])
- do
- id := Accept_language_id
- list := a_list
- end
-
- user_agent (a_list: ARRAYED_LIST [STRING])
- do
- id := User_agent_id
- list := a_list
- end
-
- str: STRING
- list: ARRAYED_LIST [STRING]
-
out: STRING
local
i: INTEGER
do
- Result := tag_str + ": "
-
- inspect id
- when Host_id then
- Result := Result + str
- when User_agent_id then
- result := Result + list_sep (list, ' ')
- else
- Result := Result + list_sep (list, ',')
- end
+ Result := tag_str + ": " + content_out
end
- list_sep (a_list: ARRAYED_LIST [STRING]; sep: CHARACTER): STRING
+ list_sep (a_list: LIST [STRING]; sep: CHARACTER): STRING
local
i: INTEGER
do
Result := ""
from i := 1
- until i > list.count
+ until i > a_list.count
loop
- Result := Result + list [i]
+ Result := Result + a_list [i]
- if i /= list.count then
+ if i /= a_list.count then
Result := Result + sep.out
end
@@ -96,32 +44,10 @@ feature
end
tag_str: STRING
- do
- inspect id
- when Accept_id then
- Result := "Accept"
- when Accept_charset_id then
- Result := "Accept-Charset"
- when Accept_encoding_id then
- Result := "Accept-Encoding"
- when Accept_language_id then
- Result := "Accept-Language"
- when Host_id then
- Result := "Host"
- when User_agent_id then
- Result := "User-Agent"
- else
-
- end
+ deferred
end
-feature {NONE}
id: INTEGER
-
- Accept_id: INTEGER = 1
- Accept_charset_id: INTEGER = 2
- Accept_encoding_id: INTEGER = 3
- Accept_language_id: INTEGER = 4
- Host_id: INTEGER = 8
- User_agent_id: INTEGER = 19
+ deferred
+ end
end
View
17 request_uri.e
@@ -7,6 +7,12 @@ note
class
REQUEST_URI
+inherit
+ ANY
+ redefine
+ out
+ end
+
create
star, absolute, relative
@@ -47,4 +53,15 @@ feature
end
end
+ out: STRING
+ do
+ if is_star then
+ Result := "*"
+ elseif is_absolute then
+ Result := host + resource
+ else
+ Result := resource
+ end
+ end
+
end
View
33 user_agent.e
@@ -0,0 +1,33 @@
+note
+ description: "Summary description for {USER_AGENT}."
+ author: ""
+ date: "$Date$"
+ revision: "$Revision$"
+
+class
+ USER_AGENT
+
+inherit
+ REQUEST_HEADER
+
+create
+ make
+
+feature
+ make (a_str: STRING)
+ do
+ name := a_str
+ end
+
+ name: STRING
+
+ tag_str: STRING = "User-Agent"
+
+ id: INTEGER = 19
+
+ content_out: STRING
+ do
+ Result := name
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.