You are looking at historical revision 12401 of this page. It may differ significantly from its current revision.
uri-generic
Description
The uri-generic library contains procedures for parsing and manipulation of Uniform Resource Identifiers (RFC 3986). It is intended to conform more closely to the RFC, and uses combinator parsing and character classes rather than regular expressions.
This library should be considered to be a basis for creating scheme-specific URI parser libraries. This library only parses the generic components from an URI. Any specific library can further parse subcomponents. For this reason, encoding and decoding of percent-encoded characters is not done automatically. This should be handled by specific URI scheme implementations.
Library Procedures
Constructors
As specified in section 2.3 of RFC 3986, URI constructors automatically decode percent-encoded octets in the range of unreserved characters. This means that the following holds true:
(equal? (uri-reference "http://example.com/foo-bar") (uri-reference "http://example.com/foo%2Dbar")) => #t[procedure] (uri-reference STRING) => URI
A URI reference is either a URI or a relative reference (RFC 3986, Section 4.1). If the given string's prefix does not match the syntax of a scheme followed by a colon separator, then the given string is parsed as a relative reference.
[procedure] (absolute-uri STRING) => URIParses the given string as an absolute URI, in which no fragments are allowed (RFC 3986, Section 4.2)
Predicates and Accessors
[procedure] (uri? URI) => BOOL[procedure] (uri-authority URI) => URI-AUTH
[procedure] (uri-scheme URI) => SYMBOL
[procedure] (uri-path URI) => LIST
[procedure] (uri-query URI) => LIST
[procedure] (uri-fragment) URI => STRING
[procedure] (uri-host URI) => STRING
[procedure] (uri-port URI) => INTEGER
[procedure] (uri-username URI) => STRING
[procedure] (uri-password URI) => STRING
If a component is not defined in the given URI, then the corresponding accessor returns #f.
String and List Representations
[procedure] (uri->string URI USERINFO) => STRINGReconstructs the give URI into a string; uses a supplied function LAMBDA USERNAME PASSWORD -> STRING to map the userinfo part of the URI
[procedure] (uri->list URI USERINFO) => LISTReturns a list of the form (SCHEME SPECIFIC FRAGMENT); SPECIFIC is of the form (AUTHORITY PATH QUERY).
Reference Resolution
[procedure] (uri-relative-to URI URI) => URIConstructs an absolute URI given a relative URI and a base URI (RFC 3986, Section 5.2.2)
[procedure] (uri-relative-from URI URI) => URIConstructs a new, possibly relative, URI which represents the location of the first URI with respect to the second URI.
String encoding and decoding
[procedure] (uri-encode-string STRING) => STRINGReturns the percent-encoded form of the given string.
[procedure] (uri-decode-string STRING) => STRINGReturns the decoded form of the given string.
Normalization
[procedure] (uri-normalize-case URI) => URIURI case normalization (RFC 3986 section 6.2.2.1)
[procedure] (uri-normalize-path-segments URI) => URIURI path segment normalization (RFC 3986 section 6.2.2.3)
Requires
Version History
- 1.10 Fixed edge case in uri-relative-to with empty path in base uri, fixed uri->string for URIs with query args, fixed uri->string to not add an extraneous slash after authority in case of empty path.
- 1.9 Fixed bug in uri-encode-string with reserved characters, added tests for decoding and encoding [Peter Bex]
- 1.8 Added uri-encode-string and uri-decode-string. URI constructors now perform automatic normalization of percent-encoded unreserved characters. [suggested by Peter Bex]
- 1.6 Added error message about missing scheme in absolute-uri.
- trunk Small bugfix in absolute-uri. [Peter Bex]
- 1.5 Bug fixes in uri->string and absolute-uri. [reported by Peter Bex]
- 1.3 Ported to Hygienic Chicken and the test egg [Peter Bex]
- 1.2 Now using defstruct instead of define-record [suggested by Peter Bex]
- 1.1 Added utf8 compatibility
- 1.0 Initial Release
License
Based on the Haskell URI library by Graham Klyne <gk@ninebynine.org>.
Copyright 2008 Ivan Raikov, Peter Bex.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- 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.
- 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.
THIS 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.