Use url.JoinPath instead of path.Join for URLs.

dev-old
Francesco Minnocci 2 years ago
parent d7f9f2935d
commit 6f308377ef
Signed by: BachoSeven
GPG Key ID: 2BE4AB7FDAD828A4

@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"path" urlpkg "net/url"
"git.phc.dm.unipi.it/phc/website/model" "git.phc.dm.unipi.it/phc/website/model"
) )
@ -44,10 +44,17 @@ func newLDAPAuthService(host string) Service {
// doGetRequest is a utility to make HTTP GET requests // doGetRequest is a utility to make HTTP GET requests
func (a *ldapAuthService) doGetRequest(url string, response interface{}) error { func (a *ldapAuthService) doGetRequest(url string, response interface{}) error {
u, err := urlpkg.JoinPath(a.Host, "poisson-ldap", url)
if err != nil {
return err
}
req, err := http.NewRequest( req, err := http.NewRequest(
"GET", path.Join(a.Host, "poisson-ldap", url), bytes.NewBuffer([]byte("")), "GET", u, bytes.NewBuffer([]byte("")),
) )
log.Printf(`%q`, a.Host)
if err != nil { if err != nil {
log.Printf(`GET %q resulted in %v`, url, err) log.Printf(`GET %q resulted in %v`, url, err)
return err return err
@ -74,7 +81,12 @@ func (a *ldapAuthService) doPostRequest(url string, request interface{}, respons
return err return err
} }
req, err := http.NewRequest("POST", path.Join(a.Host, "ldap", url), bytes.NewBuffer(jsonStr)) u, err := urlpkg.JoinPath(a.Host, "ldap", url)
if err != nil {
return err
}
req, err := http.NewRequest("POST", u, bytes.NewBuffer(jsonStr))
if err != nil { if err != nil {
return err return err
} }

Loading…
Cancel
Save