diff --git a/providers/dns/httpreq/httpreq.go b/providers/dns/httpreq/httpreq.go index f6a1fe0c..af1b73a7 100644 --- a/providers/dns/httpreq/httpreq.go +++ b/providers/dns/httpreq/httpreq.go @@ -10,6 +10,7 @@ import ( "net/http" "net/url" "os" + "path" "time" "github.com/xenolf/lego/challenge/dns01" @@ -158,7 +159,8 @@ func (d *DNSProvider) doPost(uri string, msg interface{}) error { return err } - endpoint, err := d.config.Endpoint.Parse(uri) + newURI := path.Join(d.config.Endpoint.EscapedPath(), uri) + endpoint, err := d.config.Endpoint.Parse(newURI) if err != nil { return err } diff --git a/providers/dns/httpreq/httpreq_test.go b/providers/dns/httpreq/httpreq_test.go index 7b64d297..4ca4103d 100644 --- a/providers/dns/httpreq/httpreq_test.go +++ b/providers/dns/httpreq/httpreq_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "net/url" + "path" "testing" "github.com/stretchr/testify/require" @@ -104,6 +105,7 @@ func TestNewDNSProvider_Present(t *testing.T) { mode string username string password string + pathPrefix string handler http.HandlerFunc expectedError string }{ @@ -111,6 +113,11 @@ func TestNewDNSProvider_Present(t *testing.T) { desc: "success", handler: successHandler, }, + { + desc: "success with path prefix", + handler: successHandler, + pathPrefix: "/api/acme/", + }, { desc: "error", handler: http.NotFound, @@ -150,11 +157,11 @@ func TestNewDNSProvider_Present(t *testing.T) { t.Parallel() mux := http.NewServeMux() - mux.HandleFunc("/present", test.handler) + mux.HandleFunc(path.Join("/", test.pathPrefix, "present"), test.handler) server := httptest.NewServer(mux) config := NewDefaultConfig() - config.Endpoint = mustParse(server.URL) + config.Endpoint = mustParse(server.URL + test.pathPrefix) config.Mode = test.mode config.Username = test.username config.Password = test.password