Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: parsing a http request
Pages: [1] Print
Author Topic: parsing a http request  (Read 875 times)
fhein
Newbie
*
Offline Offline

Posts: 47


View Profile
parsing a http request
« on: May 21, 2005, 11:54:12 AM »

I'm using this simple (and probably not so good) code to split up a http request:

Code:
 
if valid?: parse/all str [
copy method to " " skip
copy URI to " "
thru "^/"
some [
copy aname to ":" (append args aname) 2 skip
copy aval to "^/" (append args aval) skip
]
content: to end
][
print "stuff"
]

but now I want URI to only contain the the part up to "?" and put the rest of it in another var. For example:

/index.html?r=0&b=1

=>  URI="/index.html"  rest="r=0&b=1"

/index.html

=> URI="/index.html"  rest=""
Logged
bouba
Newbie
*
Offline Offline

Posts: 10


View Profile
parsing a http request
« Reply #1 on: May 23, 2005, 03:20:23 AM »

Code:
>>s = "/index.html?r=0&b=1"
>>
>> parse s "?"
== ["/index.html" "r=0&b=1"]

Code:
>>s = "/index.html"
>>
>> parse s "?"
== ["/index.html"]

almost there for the second one, it just simply doesn't exist if you do it this way.
Hope this helps
« Last Edit: May 23, 2005, 03:22:41 AM by bouba » Logged
fhein
Newbie
*
Offline Offline

Posts: 47


View Profile
parsing a http request
« Reply #2 on: May 23, 2005, 04:35:07 PM »

hmm, that's not exactly what I'm trying to do.. you see the url is part of a longer string so I can't use the simple parse syntax. here's an example of what a request can look like:

"GET /index.html?a=1 HTTP/1.1
accept: */*
host: localhost

"



thanks anyhow though, and don't give up just yet Tongue I think I'll use a non optimal splitting solution so I can move on with the programming
Logged
bouba
Newbie
*
Offline Offline

Posts: 10


View Profile
parsing a http request
« Reply #3 on: May 24, 2005, 01:44:11 AM »

Quote

"GET /index.html?a=1 HTTP/1.1
accept: */*
host: localhost

"

 
Well if the format is always this one, you could still use parse. :)

Code:
rule: [thru "GET" copy uri to " " (uri: parse uri "?")]
parse str rule
print mold uri

Problem is, does your string always has this format? :o)

A+

Bouba
« Last Edit: May 24, 2005, 01:44:44 AM by bouba » Logged
fhein
Newbie
*
Offline Offline

Posts: 47


View Profile
parsing a http request
« Reply #4 on: May 27, 2005, 11:48:43 AM »

well, the http request follows some basic rules (you can check the complete rfc at w3.org but it's huuuuge). I think I'll skip using parse though, because there are too many things I just want to ignore if they aren't relevant :\

the synthax is something like:

{method} {uri} HTTP/{version}crfl
{argname}: {argvalues}crlf
...more arg-pairs...
crlf
{possible content where I don't want automatic line-feed conversion}


I _hope_ that the lines in the header always are terminated by CRLF = #{0D0A} because that would make things alot easier for me Tongue
Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: parsing a http request
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 20, 2008, 09:00:18 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2287 Posts in 593 Topics by 3725 Members
Latest Member: Heigueundulge

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc