Merge pull request #12566 from fntlnz/remove-go1.3.3-support

Removed go1.3.3 support
This commit is contained in:
Jessie Frazelle 2015-04-20 17:01:57 -07:00
commit e0f512d938

View file

@ -1,45 +1,11 @@
package requestdecorator
import (
"encoding/base64"
"net/http"
"strings"
"testing"
)
// The following 2 functions are here for 1.3.3 support
// After we drop 1.3.3 support we can use the functions supported
// in go v1.4.0 +
// BasicAuth returns the username and password provided in the request's
// Authorization header, if the request uses HTTP Basic Authentication.
// See RFC 2617, Section 2.
func basicAuth(r *http.Request) (username, password string, ok bool) {
auth := r.Header.Get("Authorization")
if auth == "" {
return
}
return parseBasicAuth(auth)
}
// parseBasicAuth parses an HTTP Basic Authentication string.
// "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" returns ("Aladdin", "open sesame", true).
func parseBasicAuth(auth string) (username, password string, ok bool) {
const prefix = "Basic "
if !strings.HasPrefix(auth, prefix) {
return
}
c, err := base64.StdEncoding.DecodeString(auth[len(prefix):])
if err != nil {
return
}
cs := string(c)
s := strings.IndexByte(cs, ':')
if s < 0 {
return
}
return cs[:s], cs[s+1:], true
}
func TestUAVersionInfo(t *testing.T) {
uavi := NewUAVersionInfo("foo", "bar")
if !uavi.isValid() {
@ -147,7 +113,7 @@ func TestAuthDecorator(t *testing.T) {
t.Fatal(err)
}
username, password, ok := basicAuth(reqDecorated)
username, password, ok := reqDecorated.BasicAuth()
if !ok {
t.Fatalf("Cannot retrieve basic auth info from request")
}
@ -189,7 +155,7 @@ func TestRequestFactory(t *testing.T) {
t.Fatal(err)
}
username, password, ok := basicAuth(req)
username, password, ok := req.BasicAuth()
if !ok {
t.Fatalf("Cannot retrieve basic auth info from request")
}
@ -220,7 +186,7 @@ func TestRequestFactoryNewRequestWithDecorators(t *testing.T) {
t.Fatal(err)
}
username, password, ok := basicAuth(req)
username, password, ok := req.BasicAuth()
if !ok {
t.Fatalf("Cannot retrieve basic auth info from request")
}