Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Parse URLs (actually URIs, but that seems overly pedantic). | 5 // Parse URLs (actually URIs, but that seems overly pedantic). |
6 // RFC 3986 | 6 // RFC 3986 |
7 | 7 |
8 package http | 8 package http |
9 | 9 |
10 import ( | 10 import ( |
11 "fmt" | |
11 "os" | 12 "os" |
12 "strconv" | 13 "strconv" |
13 "strings" | 14 "strings" |
14 ) | 15 ) |
15 | 16 |
16 // URLError reports an error and the operation and URL that caused it. | 17 // URLError reports an error and the operation and URL that caused it. |
17 type URLError struct { | 18 type URLError struct { |
18 Op string | 19 Op string |
19 URL string | 20 URL string |
20 Error os.Error | 21 Error os.Error |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 result += urlEscape(url.Path, encodePath) | 509 result += urlEscape(url.Path, encodePath) |
509 } | 510 } |
510 if url.RawQuery != "" { | 511 if url.RawQuery != "" { |
511 result += "?" + url.RawQuery | 512 result += "?" + url.RawQuery |
512 } | 513 } |
513 if url.Fragment != "" { | 514 if url.Fragment != "" { |
514 result += "#" + urlEscape(url.Fragment, encodeFragment) | 515 result += "#" + urlEscape(url.Fragment, encodeFragment) |
515 } | 516 } |
516 return result | 517 return result |
517 } | 518 } |
519 | |
520 // EncodeQuery encodes the query represented as a multimap. | |
521 // Each key's value is encoded as a string using fmt.Sprint, then URL-encoded. | |
522 func EncodeQuery(m map[string][]interface{}) string { | |
rsc
2010/11/24 01:22:38
I'm not okay with this. Why interface{}? What va
dsymonds
2010/11/24 01:54:03
It's interface{} in the same way that fmt.Print, e
| |
523 parts := make([]string, 0, len(m)) // will be large enough for most uses | |
524 for k, vs := range m { | |
525 prefix := URLEscape(k) + "=" | |
526 for _, v := range vs { | |
527 parts = append(parts, prefix+URLEscape(fmt.Sprint(v))) | |
528 } | |
529 } | |
530 return strings.Join(parts, "&") | |
531 } | |
OLD | NEW |