require 'regex'
RH=: rxcomp 0 : 0
(?x)
(GET|POST) \s # meth
(?:([a-z]+)(?::))? # prot
(?:(?://)([^:/]+))? # host
(?:(?::)([^/]+))? # port
(/[^?\# ]+) # path
(?:(?:\?)([^# ]*))? # para
(?:(?:\#)([^ ]*))? # hash
\s (.+) # vers
)
RB=: rxcomp '(?m)(?:[^\r]|\r\n\s)+\r\n'
split=: ({.~ ; (}.~ 2&+)) i.&':'
http=: 3 : 0
i=. y i.CR
h=. i{.y
b=. (i+2)}.y
M=. ,."1}.{.RH rxmatches h
H=. (;:'meth prot host port path para hash vers'),.M<;.0 h
N=. |:"2 RB rxmatches b
B=. N split;.0 b
H,B
)
NB. ===========================================================
TEST1=: toCRLF 0 : 0
GET /test#one HTTP
X-TTTT: sdfsdfsdf
)
TEST2=: toCRLF 0 : 0
GET http://somewhere:1023/fdsfsdf?fdsfd HTTP/1.1
X-TTTT: sdfsdfsdf
)
TEST3=: toCRLF 0 : 0
GET https://www.site.com/asdf/qwer?query=asdf HTTP/1.1
)
TEST4=: toCRLF 0 : 0
GET /asdf/qwer?query=asdf HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/msword,
application/vnd.ms-powerpoint, application/x-icq, */*
Accept-Language: ru
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
.NET CLR 1.1.4322)
Host: ws:81
Connection: Keep-Alive
)
TEST5=: toCRLF 0 : 0
GET /asdf/qwer?query=asdf HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel, application/msword,
application/vnd.ms-powerpoint, application/x-icq, */*
Accept-Language: ru
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
.NET CLR 1.1.4322)
Host: ws:81
Connection: Keep-Alive
)
NB. ===========================================================
http TEST1
+------+-----------+
|meth |GET |
+------+-----------+
|prot | |
+------+-----------+
|host | |
+------+-----------+
|port | |
+------+-----------+
|path |/test |
+------+-----------+
|para | |
+------+-----------+
|hash |one |
+------+-----------+
|vers |HTTP |
+------+-----------+
|X-TTTT|sdfsdfsdf |
+------+-----------+
http TEST2
+------+-----------+
|meth |GET |
+------+-----------+
|prot |http |
+------+-----------+
|host |somewhere |
+------+-----------+
|port |1023 |
+------+-----------+
|path |/fdsfsdf |
+------+-----------+
|para |fdsfd |
+------+-----------+
|hash | |
+------+-----------+
|vers |HTTP/1.1 |
+------+-----------+
|X-TTTT|sdfsdfsdf |
+------+-----------+
http TEST3
+----+------------+
|meth|GET |
+----+------------+
|prot|https |
+----+------------+
|host|www.site.com|
+----+------------+
|port| |
+----+------------+
|path|/asdf/qwer |
+----+------------+
|para|query=asdf |
+----+------------+
|hash| |
+----+------------+
|vers|HTTP/1.1 |
+----+------------+
| | |
+----+------------+
http TEST4
+---------------+----------------------------------------------
|meth |GET
+---------------+----------------------------------------------
|prot |
+---------------+----------------------------------------------
|host |
+---------------+----------------------------------------------
|port |
+---------------+----------------------------------------------
|path |/asdf/qwer
+---------------+----------------------------------------------
|para |query=asdf
+---------------+----------------------------------------------
|hash |
+---------------+----------------------------------------------
|vers |HTTP/1.1
+---------------+----------------------------------------------
|Accept |image/gif, image/x-xbitmap, image/jpeg, image/
+---------------+----------------------------------------------
|Accept-Language|ru
+---------------+----------------------------------------------
|Accept-Encoding|gzip, deflate
+---------------+----------------------------------------------
|User-Agent |Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
+---------------+----------------------------------------------
|Host |ws:81
+---------------+----------------------------------------------
|Connection |Keep-Alive
+---------------+----------------------------------------------
http TEST5
+---------------+----------------------------------------------
|meth |GET
+---------------+----------------------------------------------
|prot |
+---------------+----------------------------------------------
|host |
+---------------+----------------------------------------------
|port |
+---------------+----------------------------------------------
|path |/asdf/qwer
+---------------+----------------------------------------------
|para |query=asdf
+---------------+----------------------------------------------
|hash |
+---------------+----------------------------------------------
|vers |HTTP/1.1
+---------------+----------------------------------------------
|Accept |image/gif, image/x-xbitmap, image/jpeg, image/
+---------------+----------------------------------------------
|Accept-Language|ru
+---------------+----------------------------------------------
|Accept-Encoding|gzip, deflate
+---------------+----------------------------------------------
|User-Agent |Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
+---------------+----------------------------------------------
|Host |ws:81
+---------------+----------------------------------------------
|Connection |Keep-Alive
+---------------+----------------------------------------------
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm