diff --git a/pkg/torznab/torznab.go b/pkg/torznab/torznab.go index 765c784..1e448ce 100644 --- a/pkg/torznab/torznab.go +++ b/pkg/torznab/torznab.go @@ -70,6 +70,10 @@ func (c *client) get(endpoint string, opts map[string]string) (int, *Response, e "t": {"search"}, } + if c.ApiKey != "" { + params.Add("apikey", c.ApiKey) + } + u, err := url.Parse(c.Host) u.Path = strings.TrimSuffix(u.Path, "/") u.RawQuery = params.Encode() @@ -84,9 +88,10 @@ func (c *client) get(endpoint string, opts map[string]string) (int, *Response, e req.SetBasicAuth(c.BasicAuth.Username, c.BasicAuth.Password) } - if c.ApiKey != "" { - req.Header.Add("X-API-Key", c.ApiKey) - } + // Jackett only supports api key via url param while Prowlarr does that and via header + //if c.ApiKey != "" { + // req.Header.Add("X-API-Key", c.ApiKey) + //} resp, err := c.http.Do(req) if err != nil { @@ -126,6 +131,10 @@ func (c *client) getCaps(endpoint string, opts map[string]string) (int, *Caps, e "t": {"caps"}, } + if c.ApiKey != "" { + params.Add("apikey", c.ApiKey) + } + u, err := url.Parse(c.Host) u.Path = strings.TrimSuffix(u.Path, "/") u.RawQuery = params.Encode() @@ -140,9 +149,10 @@ func (c *client) getCaps(endpoint string, opts map[string]string) (int, *Caps, e req.SetBasicAuth(c.BasicAuth.Username, c.BasicAuth.Password) } - if c.ApiKey != "" { - req.Header.Add("X-API-Key", c.ApiKey) - } + // Jackett only supports api key via url param while Prowlarr does that and via header + //if c.ApiKey != "" { + // req.Header.Add("X-API-Key", c.ApiKey) + //} resp, err := c.http.Do(req) if err != nil { diff --git a/pkg/torznab/torznab_test.go b/pkg/torznab/torznab_test.go index 11d40f7..7867cdc 100644 --- a/pkg/torznab/torznab_test.go +++ b/pkg/torznab/torznab_test.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "net/http" "net/http/httptest" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -71,8 +72,14 @@ func TestClient_GetCaps(t *testing.T) { key := "mock-key" srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - apiKey := r.Header.Get("X-API-Key") - if apiKey != key { + //apiKey := r.Header.Get("X-API-Key") + //if apiKey != key { + // w.WriteHeader(http.StatusUnauthorized) + // w.Write(nil) + // return + //} + + if !strings.Contains(r.RequestURI, key) { w.WriteHeader(http.StatusUnauthorized) w.Write(nil) return