From 6f308377eff7573e133c9fdfffdb7be0d630cf91 Mon Sep 17 00:00:00 2001 From: Francesco Minnocci Date: Sun, 18 Sep 2022 01:06:53 +0200 Subject: [PATCH] Use url.JoinPath instead of path.Join for URLs. --- auth/ldap.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/auth/ldap.go b/auth/ldap.go index 9b7e8ea..376cc7a 100644 --- a/auth/ldap.go +++ b/auth/ldap.go @@ -6,7 +6,7 @@ import ( "fmt" "log" "net/http" - "path" + urlpkg "net/url" "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 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( - "GET", path.Join(a.Host, "poisson-ldap", url), bytes.NewBuffer([]byte("")), + "GET", u, bytes.NewBuffer([]byte("")), ) + log.Printf(`%q`, a.Host) + if err != nil { log.Printf(`GET %q resulted in %v`, url, err) return err @@ -74,7 +81,12 @@ func (a *ldapAuthService) doPostRequest(url string, request interface{}, respons 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 { return err }