Module Url

module Url : sig..end

This module provides functions for tampering with Url. It's main goal is to allow one to stay in the Ocaml realm without wandering into the Dom_html.​window##location object.

The first functions are mainly from and to string conversion functions for the different parts of a url.

val urldecode : string -> string

urldecode s swaps percent encoding characters for their usual representation.

val urlencode : ?with_plus:bool -> string -> string

urlencode ?with_plus s replace characters for their percent encoding representation. Note that the '/' (slash) character is escaped as well. If with_plus is true (default) then '+''s are escaped as "%2B". If not, '+''s are left as is.

type http_url = {
  hu_host: string;(* <<div class="odocwiki_info"|~The host part of the url~.
>> *)  hu_port: int;(* <<div class="odocwiki_info"|~The port for the connection if any~.
>> *)  hu_path: string list;(* <<div class="odocwiki_info"|~The path splitted on <<span class="odocwiki_inlinecode"|~'~/~'>> characters~.
>> *)  hu_path_string: string;(* <<div class="odocwiki_info"|~The original entire path~.
>> *)  hu_arguments: (string * string) list;(* <<div class="odocwiki_info"|~Arguments as a field~-value
                                             association list~.
>> *)  hu_fragment: string;(* <<div class="odocwiki_info"|~The fragment part ~(after the <<span class="odocwiki_inlinecode"|~'~#~'>> character~)~.
>> *)}

The type for HTTP(s) url.

type file_url = {
  fu_path: string list;  fu_path_string: string;  fu_arguments: (string * string) list;  fu_fragment: string;}

The type for local file urls.

type url =  | Http of http_url(* <<div class="odocwiki_info"|~Non secure ~H~T~T~P urls
>> *) | Https of http_url(* <<div class="odocwiki_info"|~Secure ~H~T~T~P~S urls
>> *) | File of file_url(* <<div class="odocwiki_info"|~Local files
>> *)

The type for urls.

val default_http_port : int

The default port for Http communications (80).

val default_https_port : int

The default port for Https communications (443).

val path_of_path_string : string -> string list

path_of_path_string s splits s on each "/" character.

val encode_arguments : (string * string) list -> string

encode_arguments a expects a list of pair of values of the form (name,value) were name is the name of an argument and value it's associated value.

val decode_arguments : string -> (string * string) list

decode_arguments s parses s returning the sliced-diced association list.

The following part allow one to handle Url object in a much higher level than what a string provides.

val url_of_string : string -> url option

url_of_string s parses s and builds a value of type url if s is not a valid url string, it returns None.

val string_of_url : url -> string

string_of_url u returns a valid string representation of u. Note that * string_of_url ((fun Some u -> u) (url_of_string s)) is NOT necessarily * equal to s. However url_of_string (string_of_url u) = u.

module Current : sig..end

This module can be used to handle the Url associated to the current document.