Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

gofix http url handling functions into "url" package.

  • Loading branch information...
commit cd3981cea739f94c4a0af96b06db05d554da216b 1 parent 5da5c9a
@brianolson brianolson authored
Showing with 30 additions and 31 deletions.
  1. +5 −6 authrequest.go
  2. +15 −14 verify.go
  3. +10 −11 yadis.go
View
11 authrequest.go
@@ -8,7 +8,7 @@ import (
"strings"
"io"
"os"
- "http"
+ "url"
)
const (
@@ -17,7 +17,6 @@ const (
IdentifierURL
)
-
func GetRedirectURL(Identifier string, realm string, returnto string) (string, os.Error) {
var err os.Error
var Id, IdType = NormalizeIdentifier(Identifier)
@@ -97,11 +96,11 @@ func CreateAuthenticationRequest(OPEndPoint, ClaimedID, Realm, ReturnTo string)
p["openid.return_to"] = Realm + ReturnTo
p["openid.realm"] = Realm
- var url string
- url = OPEndPoint + "?"
+ var url_ string
+ url_ = OPEndPoint + "?"
for k, v := range p {
- url += http.URLEscape(k) + "=" + http.URLEscape(v) + "&"
+ url_ += url.QueryEscape(k) + "=" + url.QueryEscape(v) + "&"
}
- return url
+ return url_
}
View
29 verify.go
@@ -10,6 +10,7 @@ import (
"http"
"regexp"
"bytes"
+ "url"
)
// Verify that the url given match a successfull authentication
@@ -17,15 +18,15 @@ import (
// * true if authenticated, false otherwise
// * The Claimed identifier if authenticated
// * Eventually an error
-func Verify(url string) (grant bool, identifier string, err os.Error) {
+func Verify(url_ string) (grant bool, identifier string, err os.Error) {
grant = false
identifier = ""
err = nil
//var urlm map[string]string
//urlm, err = url2map(url)
- var values http.Values
- values, err = http.ParseQuery(url)
+ var values url.Values
+ values, err = url.ParseQuery(url_)
if err != nil {
return false, "", err
}
@@ -53,11 +54,11 @@ var REVerifyDirectIsValid = "is_valid:true"
var REVerifyDirectNs = regexp.MustCompile("ns:([a-zA-Z0-9:/.]*)")
// Like Verify on a parsed URL
-func VerifyValues(values http.Values) (grant bool, identifier string, err os.Error) {
+func VerifyValues(values url.Values) (grant bool, identifier string, err os.Error) {
err = nil
- var postArgs http.Values
- postArgs = http.Values(map[string][]string{})
+ var postArgs url.Values
+ postArgs = url.Values(map[string][]string{})
//postArgs = new(http.Values)
postArgs.Set("openid.mode", "check_authentication")
@@ -69,7 +70,7 @@ func VerifyValues(values http.Values) (grant bool, identifier string, err os.Err
}
for k, v := range values {
if k == "openid.op_endpoint" {
- continue // skip it
+ continue // skip it
}
postArgs[k] = v
}
@@ -116,15 +117,15 @@ func VerifyValues(values http.Values) (grant bool, identifier string, err os.Err
}
// Transform an url string into a map of parameters/value
-func url2map(url string) (map[string]string, os.Error) {
+func url2map(url_ string) (map[string]string, os.Error) {
pmap := make(map[string]string)
var start, end, eq, length int
var param, value string
var err os.Error
- length = len(url)
+ length = len(url_)
start = 0
- for start < length && url[start] != '?' {
+ for start < length && url_[start] != '?' {
start++
}
if start >= length {
@@ -134,19 +135,19 @@ func url2map(url string) (map[string]string, os.Error) {
for end < length {
start = end + 1
eq = start
- for eq < length && url[eq] != '=' {
+ for eq < length && url_[eq] != '=' {
eq++
}
end = eq + 1
- for end < length && url[end] != '&' {
+ for end < length && url_[end] != '&' {
end++
}
- param, err = http.URLUnescape(url[start:eq])
+ param, err = url.QueryUnescape(url_[start:eq])
if err != nil {
return nil, err
}
- value, err = http.URLUnescape(url[eq+1 : end])
+ value, err = url.QueryUnescape(url_[eq+1 : end])
if err != nil {
return nil, err
}
View
21 yadis.go
@@ -7,6 +7,7 @@ package openid
import (
"os"
"http"
+ "url"
"xml"
"fmt"
"io"
@@ -16,7 +17,6 @@ import (
"strings"
)
-
func Yadis(ID string) (io.Reader, os.Error) {
r, err := YadisRequest(ID, "GET")
if err != nil || r == nil {
@@ -32,11 +32,11 @@ func Yadis(ID string) (io.Reader, os.Error) {
// If it is an HTML doc search for meta tags
if bytes.Equal([]byte(contentType), []byte("text/html")) {
- url, err := searchHTMLMetaXRDS(r.Body)
+ url_, err := searchHTMLMetaXRDS(r.Body)
if err != nil {
return nil, err
}
- return Yadis(url)
+ return Yadis(url_)
}
// If the response contain an X-XRDS-Location header
@@ -49,7 +49,7 @@ func Yadis(ID string) (io.Reader, os.Error) {
return nil, nil
}
-func YadisRequest(url string, method string) (resp *http.Response, err os.Error) {
+func YadisRequest(url_ string, method string) (resp *http.Response, err os.Error) {
resp = nil
var request = new(http.Request)
@@ -57,9 +57,9 @@ func YadisRequest(url string, method string) (resp *http.Response, err os.Error)
var Header = make(http.Header)
request.Method = method
- request.RawURL = url
+ request.RawURL = url_
- request.URL, err = http.ParseURL(url)
+ request.URL, err = url.Parse(url_)
if err != nil {
return
}
@@ -81,7 +81,7 @@ func YadisRequest(url string, method string) (resp *http.Response, err os.Error)
if response.StatusCode == 301 || response.StatusCode == 302 || response.StatusCode == 303 || response.StatusCode == 307 {
location := response.Header.Get("Location")
request.RawURL = location
- request.URL, err = http.ParseURL(location)
+ request.URL, err = url.Parse(location)
if err != nil {
return
}
@@ -97,12 +97,11 @@ var metaRE *regexp.Regexp
var xrdsRE *regexp.Regexp
func init() {
-metaRE = regexp.MustCompile("<[ \t]*[mM][eE][tT][aA][^>]*[hH][tT][tT][pP]-[eE][qQ][uU][iI][vV]=[\"'][xX]-[xX][rR][dD][sS]-[lL][oO][cC][aA][tT][iI][oO][nN][\"'][^>]*>")
-xrdsRE = regexp.MustCompile("[cC][oO][nN][tT][eE][nN][tT]=[\"']([^\"]+)[\"']")
-//xrdsRE = regexp.MustCompile("content=[\"']([^\"']+)[\"']")
+ metaRE = regexp.MustCompile("<[ \t]*[mM][eE][tT][aA][^>]*[hH][tT][tT][pP]-[eE][qQ][uU][iI][vV]=[\"'][xX]-[xX][rR][dD][sS]-[lL][oO][cC][aA][tT][iI][oO][nN][\"'][^>]*>")
+ xrdsRE = regexp.MustCompile("[cC][oO][nN][tT][eE][nN][tT]=[\"']([^\"]+)[\"']")
+ //xrdsRE = regexp.MustCompile("content=[\"']([^\"']+)[\"']")
}
-
func searchHTMLMetaXRDS(r io.Reader) (string, os.Error) {
data, err := ioutil.ReadAll(r)
if err != nil {
Please sign in to comment.
Something went wrong with that request. Please try again.