Use the net package function for credentials.

This change ensures any usernames or passwords which contain symbols that
would confuse the URL parser are properly escaped.
This commit is contained in:
Dave Collins 2014-09-20 19:05:38 -05:00
parent 1caddd4a37
commit a5b1a31e07

View file

@ -15,6 +15,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url"
"strings" "strings"
) )
@ -52,7 +53,7 @@ func jsonRPCSend(user string, password string, server string, message []byte,
client.Transport = transport client.Transport = transport
protocol = "https" protocol = "https"
} }
credentials := user + ":" + password credentials := url.UserPassword(user, password).String()
resp, err := client.Post(protocol+"://"+credentials+"@"+server, resp, err := client.Post(protocol+"://"+credentials+"@"+server,
"application/json", bytes.NewReader(message)) "application/json", bytes.NewReader(message))
if err != nil { if err != nil {