mirror of
https://github.com/golang/go
synced 2024-11-22 20:40:03 -07:00
net/url: use camelCase names
Change-Id: I191b98b846c9de58b1892e695058c727402b5400
GitHub-Last-Rev: f241ddd96b
GitHub-Pull-Request: golang/go#45291
Reviewed-on: https://go-review.googlesource.com/c/go/+/305770
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
5f646f0a98
commit
e6ac2df2b1
@ -425,31 +425,31 @@ func (u *Userinfo) String() string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maybe rawurl is of the form scheme:path.
|
// Maybe rawURL is of the form scheme:path.
|
||||||
// (Scheme must be [a-zA-Z][a-zA-Z0-9+-.]*)
|
// (Scheme must be [a-zA-Z][a-zA-Z0-9+-.]*)
|
||||||
// If so, return scheme, path; else return "", rawurl.
|
// If so, return scheme, path; else return "", rawURL.
|
||||||
func getscheme(rawurl string) (scheme, path string, err error) {
|
func getScheme(rawURL string) (scheme, path string, err error) {
|
||||||
for i := 0; i < len(rawurl); i++ {
|
for i := 0; i < len(rawURL); i++ {
|
||||||
c := rawurl[i]
|
c := rawURL[i]
|
||||||
switch {
|
switch {
|
||||||
case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z':
|
case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z':
|
||||||
// do nothing
|
// do nothing
|
||||||
case '0' <= c && c <= '9' || c == '+' || c == '-' || c == '.':
|
case '0' <= c && c <= '9' || c == '+' || c == '-' || c == '.':
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
return "", rawurl, nil
|
return "", rawURL, nil
|
||||||
}
|
}
|
||||||
case c == ':':
|
case c == ':':
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
return "", "", errors.New("missing protocol scheme")
|
return "", "", errors.New("missing protocol scheme")
|
||||||
}
|
}
|
||||||
return rawurl[:i], rawurl[i+1:], nil
|
return rawURL[:i], rawURL[i+1:], nil
|
||||||
default:
|
default:
|
||||||
// we have encountered an invalid character,
|
// we have encountered an invalid character,
|
||||||
// so there is no valid scheme
|
// so there is no valid scheme
|
||||||
return "", rawurl, nil
|
return "", rawURL, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", rawurl, nil
|
return "", rawURL, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// split slices s into two substrings separated by the first occurrence of
|
// split slices s into two substrings separated by the first occurrence of
|
||||||
@ -466,15 +466,15 @@ func split(s string, sep byte, cutc bool) (string, string) {
|
|||||||
return s[:i], s[i:]
|
return s[:i], s[i:]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse parses rawurl into a URL structure.
|
// Parse parses a raw url into a URL structure.
|
||||||
//
|
//
|
||||||
// The rawurl may be relative (a path, without a host) or absolute
|
// The url may be relative (a path, without a host) or absolute
|
||||||
// (starting with a scheme). Trying to parse a hostname and path
|
// (starting with a scheme). Trying to parse a hostname and path
|
||||||
// without a scheme is invalid but may not necessarily return an
|
// without a scheme is invalid but may not necessarily return an
|
||||||
// error, due to parsing ambiguities.
|
// error, due to parsing ambiguities.
|
||||||
func Parse(rawurl string) (*URL, error) {
|
func Parse(rawURL string) (*URL, error) {
|
||||||
// Cut off #frag
|
// Cut off #frag
|
||||||
u, frag := split(rawurl, '#', true)
|
u, frag := split(rawURL, '#', true)
|
||||||
url, err := parse(u, false)
|
url, err := parse(u, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &Error{"parse", u, err}
|
return nil, &Error{"parse", u, err}
|
||||||
@ -483,20 +483,20 @@ func Parse(rawurl string) (*URL, error) {
|
|||||||
return url, nil
|
return url, nil
|
||||||
}
|
}
|
||||||
if err = url.setFragment(frag); err != nil {
|
if err = url.setFragment(frag); err != nil {
|
||||||
return nil, &Error{"parse", rawurl, err}
|
return nil, &Error{"parse", rawURL, err}
|
||||||
}
|
}
|
||||||
return url, nil
|
return url, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseRequestURI parses rawurl into a URL structure. It assumes that
|
// ParseRequestURI parses a raw url into a URL structure. It assumes that
|
||||||
// rawurl was received in an HTTP request, so the rawurl is interpreted
|
// url was received in an HTTP request, so the url is interpreted
|
||||||
// only as an absolute URI or an absolute path.
|
// only as an absolute URI or an absolute path.
|
||||||
// The string rawurl is assumed not to have a #fragment suffix.
|
// The string url is assumed not to have a #fragment suffix.
|
||||||
// (Web browsers strip #fragment before sending the URL to a web server.)
|
// (Web browsers strip #fragment before sending the URL to a web server.)
|
||||||
func ParseRequestURI(rawurl string) (*URL, error) {
|
func ParseRequestURI(rawURL string) (*URL, error) {
|
||||||
url, err := parse(rawurl, true)
|
url, err := parse(rawURL, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &Error{"parse", rawurl, err}
|
return nil, &Error{"parse", rawURL, err}
|
||||||
}
|
}
|
||||||
return url, nil
|
return url, nil
|
||||||
}
|
}
|
||||||
@ -505,27 +505,27 @@ func ParseRequestURI(rawurl string) (*URL, error) {
|
|||||||
// viaRequest is true, the URL is assumed to have arrived via an HTTP request,
|
// viaRequest is true, the URL is assumed to have arrived via an HTTP request,
|
||||||
// in which case only absolute URLs or path-absolute relative URLs are allowed.
|
// in which case only absolute URLs or path-absolute relative URLs are allowed.
|
||||||
// If viaRequest is false, all forms of relative URLs are allowed.
|
// If viaRequest is false, all forms of relative URLs are allowed.
|
||||||
func parse(rawurl string, viaRequest bool) (*URL, error) {
|
func parse(rawURL string, viaRequest bool) (*URL, error) {
|
||||||
var rest string
|
var rest string
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if stringContainsCTLByte(rawurl) {
|
if stringContainsCTLByte(rawURL) {
|
||||||
return nil, errors.New("net/url: invalid control character in URL")
|
return nil, errors.New("net/url: invalid control character in URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
if rawurl == "" && viaRequest {
|
if rawURL == "" && viaRequest {
|
||||||
return nil, errors.New("empty url")
|
return nil, errors.New("empty url")
|
||||||
}
|
}
|
||||||
url := new(URL)
|
url := new(URL)
|
||||||
|
|
||||||
if rawurl == "*" {
|
if rawURL == "*" {
|
||||||
url.Path = "*"
|
url.Path = "*"
|
||||||
return url, nil
|
return url, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split off possible leading "http:", "mailto:", etc.
|
// Split off possible leading "http:", "mailto:", etc.
|
||||||
// Cannot contain escaped characters.
|
// Cannot contain escaped characters.
|
||||||
if url.Scheme, rest, err = getscheme(rawurl); err != nil {
|
if url.Scheme, rest, err = getScheme(rawURL); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
url.Scheme = strings.ToLower(url.Scheme)
|
url.Scheme = strings.ToLower(url.Scheme)
|
||||||
@ -1058,11 +1058,11 @@ func (u *URL) IsAbs() bool {
|
|||||||
// may be relative or absolute. Parse returns nil, err on parse
|
// may be relative or absolute. Parse returns nil, err on parse
|
||||||
// failure, otherwise its return value is the same as ResolveReference.
|
// failure, otherwise its return value is the same as ResolveReference.
|
||||||
func (u *URL) Parse(ref string) (*URL, error) {
|
func (u *URL) Parse(ref string) (*URL, error) {
|
||||||
refurl, err := Parse(ref)
|
refURL, err := Parse(ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return u.ResolveReference(refurl), nil
|
return u.ResolveReference(refURL), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveReference resolves a URI reference to an absolute URI from
|
// ResolveReference resolves a URI reference to an absolute URI from
|
||||||
@ -1151,8 +1151,8 @@ func (u *URL) Port() string {
|
|||||||
// splitHostPort separates host and port. If the port is not valid, it returns
|
// splitHostPort separates host and port. If the port is not valid, it returns
|
||||||
// the entire input as host, and it doesn't check the validity of the host.
|
// the entire input as host, and it doesn't check the validity of the host.
|
||||||
// Unlike net.SplitHostPort, but per RFC 3986, it requires ports to be numeric.
|
// Unlike net.SplitHostPort, but per RFC 3986, it requires ports to be numeric.
|
||||||
func splitHostPort(hostport string) (host, port string) {
|
func splitHostPort(hostPort string) (host, port string) {
|
||||||
host = hostport
|
host = hostPort
|
||||||
|
|
||||||
colon := strings.LastIndexByte(host, ':')
|
colon := strings.LastIndexByte(host, ':')
|
||||||
if colon != -1 && validOptionalPort(host[colon:]) {
|
if colon != -1 && validOptionalPort(host[colon:]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user