source: project/wiki/eggref/4/uri-generic @ 12726

Last change on this file since 12726 was 12726, checked in by sjamaan, 11 years ago

Document changes in 1.12

File size: 6.7 KB
Line 
1[[tags: eggs]]
2[[toc:]]
3
4== uri-generic
5
6=== Description
7
8The {{uri-generic}} library contains procedures for parsing and
9manipulation of Uniform Resource Identifiers
10([[http://tools.ietf.org/html/rfc3986|RFC 3986]]). It is intended to
11conform more closely to the RFC, and uses combinator parsing and
12character classes rather than regular expressions.
13
14This library should be considered to be a ''basis'' for creating
15scheme-specific URI parser libraries. This library only parses
16the generic components from an URI.  Any specific library can
17further parse subcomponents. For this reason, encoding and decoding
18of percent-encoded characters is not done automatically.
19This should be handled by specific URI scheme implementations.
20
21=== Library Procedures
22
23==== Constructors
24
25As specified in section 2.3 of RFC 3986, URI constructors
26automatically decode percent-encoded octets in the range of unreserved
27characters. This means that the following holds true:
28
29 (equal? (uri-reference "http://example.com/foo-bar")
30         (uri-reference "http://example.com/foo%2Dbar"))  => #t
31
32<procedure>(uri-reference STRING) => URI</procedure>
33
34A URI reference is either a URI or a relative reference (RFC 3986,
35Section 4.1).  If the given string's prefix does not match the syntax
36of a scheme followed by a colon separator, then the given string is
37parsed as a relative reference.
38
39<procedure>(absolute-uri STRING) => URI</procedure>
40
41Parses the given string as an absolute URI, in which no fragments are
42allowed (RFC 3986, Section 4.2)
43
44
45==== Predicates and Accessors
46
47<procedure>(uri? URI) => BOOL</procedure>
48<procedure>(uri-authority URI) => URI-AUTH</procedure>
49<procedure>(uri-scheme URI) => SYMBOL</procedure>
50<procedure>(uri-path URI) => LIST</procedure>
51<procedure>(uri-query URI) => LIST</procedure>
52<procedure>(uri-fragment) URI => STRING</procedure>
53<procedure>(uri-host URI) => STRING</procedure>
54<procedure>(uri-port URI) => INTEGER</procedure>
55<procedure>(uri-username URI) => STRING</procedure>
56<procedure>(uri-password URI) => STRING</procedure>
57<procedure>(authority? URI-AUTH) => BOOL</procedure>
58<procedure>(authority-host URI-AUTH) => STRING</procedure>
59<procedure>(authority-port URI-AUTH) => INTEGER</procedure>
60<procedure>(authority-username URI-AUTH) => STRING</procedure>
61<procedure>(authority-password URI-AUTH) => STRING</procedure>
62
63If a component is not defined in the given URI, then the corresponding
64accessor returns {{#f}}.
65
66<procedure>(update-uri URI #!key authority scheme path query fragment host port username password) => URI</procedure>
67<procedure>(update-authority URI-AUTH #!key host port username password) => URI</procedure>
68
69Update the specified keys in the URI or URI-AUTH object in a
70functional way (ie, it creates a new copy with the modifications).
71
72
73==== String and List Representations
74
75<procedure>(uri->string URI USERINFO) => STRING</procedure>
76
77Reconstructs the given URI into a string; uses a supplied function
78{{LAMBDA USERNAME PASSWORD -> STRING}} to map the userinfo part of the
79URI
80
81<procedure>(uri->list URI USERINFO) => LIST</procedure>
82
83Returns a list of the form {{(SCHEME SPECIFIC FRAGMENT)}};
84{{SPECIFIC}} is of the form {{(AUTHORITY PATH QUERY)}}.
85
86==== Reference Resolution
87
88<procedure>(uri-relative-to URI URI) => URI</procedure>
89
90Constructs an absolute URI given a relative URI and a base URI (RFC 3986, Section 5.2.2)
91
92<procedure>(uri-relative-from URI URI) => URI</procedure>
93
94Constructs a new, possibly relative, URI which represents the location
95of the first URI with respect to the second URI.
96
97==== String encoding and decoding
98
99<procedure>(uri-encode-string STRING) => STRING</procedure>
100
101Returns the percent-encoded form of the given string.
102
103<procedure>(uri-decode-string STRING) => STRING</procedure>
104
105Returns the decoded form of the given string.
106
107
108==== Normalization 
109
110<procedure>(uri-normalize-case URI) => URI</procedure>
111
112URI case normalization (RFC 3986 section 6.2.2.1)
113
114<procedure>(uri-normalize-path-segments URI) => URI</procedure>
115
116URI path segment normalization (RFC 3986 section 6.2.2.3)
117
118=== Requires
119
120; [[matchable]]
121; [[defstruct]]
122
123=== Version History
124
125* 1.12 Fix relative path normalization when original path ends in a slash, remove consecutive slashes from paths in URIs
126* 1.11 Added accessors for the authority components, functional update procedures. Fixed case-normalization.
127* 1.10 Fixed edge case in {{uri-relative-to}} with empty path in base uri,
128       fixed {{uri->string}} for URIs with query args, fixed {{uri->string}}
129       to not add an extraneous slash after authority in case of empty path.
130* 1.9 Fixed bug in uri-encode-string with reserved characters, added
131      tests for decoding and encoding [Peter Bex]
132* 1.8 Added uri-encode-string and uri-decode-string.
133      URI constructors now perform automatic normalization
134      of percent-encoded unreserved characters. [suggested by Peter Bex]
135* 1.6 Added error message about missing scheme in absolute-uri.
136* trunk Small bugfix in absolute-uri. [Peter Bex]
137* 1.5 Bug fixes in uri->string and absolute-uri. [reported by Peter Bex]
138* 1.3 Ported to Hygienic Chicken and the [[test]] egg [Peter Bex]
139* 1.2 Now using defstruct instead of define-record [suggested by Peter Bex]
140* 1.1 Added utf8 compatibility
141* 1.0 Initial Release
142
143=== License
144
145Based on the
146[[http://www.ninebynine.org/Software/ReadMe-URI-Haskell.txt|Haskell
147URI library]] by Graham Klyne <gk@ninebynine.org>.
148
149Copyright 2008 Ivan Raikov, Peter Bex.
150
151Redistribution and use in source and binary forms, with or without
152modification, are permitted provided that the following conditions are
153met:
154
155- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
156
157- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
158
159- Neither name of the copyright holders nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
160
161THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
162
Note: See TracBrowser for help on using the repository browser.