aboutsummaryrefslogtreecommitdiff
path: root/request_handlers.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2023-08-15 15:42:00 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2023-08-15 15:42:00 +0530
commit33283bff8b1ae239036aeb1526ec3b7483767ed7 (patch)
tree3219f6a539acca526d2ea6c2fa2d6c79c0b8e958 /request_handlers.go
parentaf9d2adedcb37b2c6c316cf52950a19d2a245803 (diff)
added option to use client authv0.0.5
Diffstat (limited to 'request_handlers.go')
-rw-r--r--request_handlers.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/request_handlers.go b/request_handlers.go
index adf5535..187d759 100644
--- a/request_handlers.go
+++ b/request_handlers.go
@@ -32,9 +32,11 @@ func (c Client) get(endpoint string) ([]byte, error) {
req, _ := http.NewRequest(http.MethodGet, endpoint, nil)
// add authorization headers
- // TODO: implement client auth
- //req.Header.Add("X-MAL-CLIENT-ID", c.ClientAuth)
- req.Header.Add("Authorization", c.MainAuth)
+ if c.ClientAuthOnly {
+ req.Header.Add("X-MAL-CLIENT-ID", c.ClientAuth)
+ } else {
+ req.Header.Add("Authorization", c.MainAuth)
+ }
// send request
res, err := c.httpClient.Do(req)
@@ -60,6 +62,10 @@ func (c Client) get(endpoint string) ([]byte, error) {
}
func (c Client) delete(endpoint string) error {
+ if c.ClientAuthOnly {
+ return ErrClientAuthNotSupported
+ }
+
// can safely ignore error with http.NewRequest
req, _ := http.NewRequest(http.MethodDelete, endpoint, nil)
@@ -95,6 +101,10 @@ func (c Client) delete(endpoint string) error {
}
func (c Client) put(endpoint string, params url.Values) ([]byte, error) {
+ if c.ClientAuthOnly {
+ return []byte{}, ErrClientAuthNotSupported
+ }
+
encodedParams := params.Encode()
// can safely ignore error with http.NewRequest