Script Library: 1238 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 
View scriptLicenseDownload documentation as: HTML or editable
Download scriptHistoryOther scripts by: hallyhaa

Documentation for: url-handler.r


Easy to use!

Construct your object like this:

 site: url-handler "http://www.rebol.com"
 print site/url               ; == http://www.rebol.com/

Then go somewhere else with it:

 site/move-to "docs.html"
 site/move-to "http://www.rebol.com/docs/core23/rebolcore-1.html"
 site/move-to "#sect1"

What is now registered about your URL is this:

 print site/protocol              ; == "http://"
 print site/host               ; == "www.rebol.com"
 print site/path               ; == "/docs/core23/"
 print site/file               ; == "rebolcore-1.html"
 print site/query-part                 ; == ""
 print site/section             ; == "#sect1"
 print site/canonical               ; == "http://www.rebol.com:80/docs/core23/rebolcore-1.html#sect1"
 print site/as-string/from-path-only    ; == "/docs/core23/rebolcore-1.html"

Then what about CGI GET queries? Here:

 site: url-handler "http://dummy.com/index.html?zz=b&hj=d&e=5&f=a%20b&sid=5&nothing=&re=bol#s3"

Get the query as a string:

 probe site/query-part              ; == "?zz=b&hj=d&e=5&f=a%20b&sid=5&nothing=&re=bol"

Or access it as a block:

 probe site/query-block                 ; == [e: "5" f: "a b" hj: "d" nothing: none re: "bol" sid: "5" zz: "b"]

Note that the query part is sorted when in a block.

Here's almost the same URL, but note the difference in the query-part (paramters in a different order):

 site2: url-handler "http://dummy.com/index.html?hj=d&e=5&f=a%20b&sid=5&nothing=&re=bol&zz=b#s3"

If you tell the script to pay attention to the order in which the parameters first came in, the two URLs are not identical:

 print site2/equal?/regard-cgi-order/regard-section site ; == false

But if you disregard the cgi order, they are identical:

 print site2/equal?/regard-section site ; == true

The same goes for the /regard-section refinement. If you do not specify it, the section part of URLs will not be compared.