Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/url: Parse should normalize scheme, host to lower case #3913

Closed
gopherbot opened this issue Aug 6, 2012 · 6 comments
Closed

net/url: Parse should normalize scheme, host to lower case #3913

gopherbot opened this issue Aug 6, 2012 · 6 comments
Milestone

Comments

@gopherbot
Copy link

by legoff.laurent:

What steps will reproduce the problem?
package main

import (
    "fmt"
    "io/ioutil"
    "net/http"
)

func GetRDF(url string, printResult bool) ([]byte, error) {
    request, err := http.NewRequest("GET", url, nil)
    if err != nil {
        return nil, err
    }
    request.Header.Add("Accept", "application/rdf+xml")
    resp, err := http.DefaultClient.Do(request)
    if err != nil {
        return nil, err
    }
    defer resp.Body.Close()
    content, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        return nil, err
    }
    rdfContent := string(content)
    if printResult {
        fmt.Println(rdfContent)
    }
    return content, nil
}

func main() {
    rdfUrl := "http://purl.org/dc/elements/1.1/";
    _, err := GetRDF(rdfUrl, true)
    if err != nil {
        fmt.Println(err)
    }
}

What is the expected output?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
    <!ENTITY rdfns 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
    <!ENTITY rdfsns 'http://www.w3.org/2000/01/rdf-schema#'>
    <!ENTITY dcns 'http://purl.org/dc/elements/1.1/'>
    <!ENTITY dctermsns 'http://purl.org/dc/terms/'>
    <!ENTITY dctypens 'http://purl.org/dc/dcmitype/'>
    <!ENTITY dcamns 'http://purl.org/dc/dcam/'>
    <!ENTITY skosns 'http://www.w3.org/2004/02/skos/core#'>
    <!ENTITY owlns 'http://www.w3.org/2002/07/owl#'>
]>
<rdf:RDF...

What do you see instead?
Get HTTP://dublincore.org/documents/2012/06/14/dcmi-terms/: unsupported protocol scheme
"HTTP"

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
windows 7 64bit 

Which version are you using?  (run 'go version')
go version go1

Please provide any additional information below.
it seems that purl redirect the request http://purl.org/dc/elements/1.1/ to
HTTP://dublincore.org/documents/2012/06/14/dcmi-terms/ but with an uppercase protocol
scheme.
https://groups.google.com/d/topic/golang-nuts/IZMji-U09Mg/discussion
@patrickmn
Copy link

Comment 1:

RFC 3986
6.2.2.1.  Case Normalization
   For all URIs, the hexadecimal digits within a percent-encoding
   triplet (e.g., "%3a" versus "%3A") are case-insensitive and therefore
   should be normalized to use uppercase letters for the digits A-F.
   When a URI uses components of the generic syntax, the component
   syntax equivalence rules always apply; namely, that the scheme and
   host are case-insensitive and therefore should be normalized to
   lowercase.  For example, the URI <HTTP://www.EXAMPLE.com/> is
   equivalent to <http://www.example.com/>;.  The other generic syntax
   components are assumed to be case-sensitive unless specifically
   defined otherwise by the scheme (see Section 6.2.3).

@gopherbot
Copy link
Author

Comment 2 by legoff.laurent:

// line 135 of net/http/transport.go file
var rt RoundTripper
if t.altProto != nil {
    rt = t.altProto[req.URL.Scheme]
}
t.lk.Unlock()
if rt == nil {
    return nil, &badStringError{"unsupported protocol scheme", req.URL.Scheme}
}
return rt.RoundTrip(req)
According to Patrick Mylund Nielsen scheme are case insensitive, I suggest to change the
line 137 to:
rt = t.altProto[strings.ToLower(req.URL.Scheme)]

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 3:

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 4:

Labels changed: added go1.1.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 5:

Labels changed: added size-m.

@rsc
Copy link
Contributor

rsc commented Jan 31, 2013

Comment 6:

This issue was closed by revision 4085426.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants