diff options
| author | Russ Cox <rsc@golang.org> | 2009-04-15 18:40:55 -0700 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2009-04-15 18:40:55 -0700 |
| commit | cff99ba167a9eb6f134a576f0438390ddacba38d (patch) | |
| tree | e335678a7c56ef773c15a7b3103a0a4a71917b82 /src/lib/http/url.go | |
| parent | 17c290ffb9a14061321eb570a8d3e3a93d8ca2c9 (diff) | |
| download | go-cff99ba167a9eb6f134a576f0438390ddacba38d.tar.xz | |
make Location translate relative path to absolute
(HTTP requires absolute in protocol).
add URL tests
R=r
DELTA=243 (242 added, 0 deleted, 1 changed)
OCL=27472
CL=27523
Diffstat (limited to 'src/lib/http/url.go')
| -rw-r--r-- | src/lib/http/url.go | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/lib/http/url.go b/src/lib/http/url.go index 13ac7772e6..d92a3baa62 100644 --- a/src/lib/http/url.go +++ b/src/lib/http/url.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Parse URLs (actually URIs, but that seems overly pedantic). -// TODO(rsc): Add tests. +// RFC 2396 package http @@ -196,3 +196,29 @@ func ParseURLReference(rawurlref string) (url *URL, err *os.Error) { return url, nil } +// String reassembles url into a valid URL string. +// +// There are redundant fields stored in the URL structure: +// the String method consults Scheme, Path, Host, Userinfo, +// Query, and Fragment, but not RawPath or Authority. +func (url *URL) String() string { + result := ""; + if url.Scheme != "" { + result += url.Scheme + ":"; + } + if url.Host != "" || url.Userinfo != "" { + result += "//"; + if url.Userinfo != "" { + result += url.Userinfo + "@"; + } + result += url.Host; + } + result += url.Path; + if url.Query != "" { + result += "?" + url.Query; + } + if url.Fragment != "" { + result += "#" + url.Fragment; + } + return result; +} |
