|
Pages: [1]
|
 |
|
Author
|
Topic: parsing a http request (Read 875 times)
|
|
fhein
|
I'm using this simple (and probably not so good) code to split up a http request: 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
|
>>s = "/index.html?r=0&b=1" >> >> parse s "?" == ["/index.html" "r=0&b=1"]
>>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
|
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  I think I'll use a non optimal splitting solution so I can move on with the programming
|
|
|
|
|
Logged
|
|
|
|
|
bouba
|
"GET /index.html?a=1 HTTP/1.1 accept: */* host: localhost
"
Well if the format is always this one, you could still use parse. :) 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
|
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
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |
News: 01-09-08 Alpha version of REBOL 3 has been released!
2287 Posts in 593 Topics by 3725 Members
Latest Member: Heigueundulge
|