aboutsummaryrefslogtreecommitdiffhomepage
path: root/http
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-04-28 10:51:07 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-04-28 10:51:07 -0700
commit1eba1730d1af50ed545f4fde78b22d6fb62ca11e (patch)
tree61f99282f66529b42625a8f335593bdcb461459c /http
parent04adf5fdf53951f270923c41171a52575db53e46 (diff)
Move HTTP client to its own package
Diffstat (limited to 'http')
-rw-r--r--http/client/client.go (renamed from http/client.go)43
-rw-r--r--http/client/response.go (renamed from http/response.go)2
-rw-r--r--http/client/response_test.go (renamed from http/response_test.go)2
-rw-r--r--http/doc.go10
4 files changed, 26 insertions, 31 deletions
diff --git a/http/client.go b/http/client/client.go
index 1884224..7663064 100644
--- a/http/client.go
+++ b/http/client/client.go
@@ -1,8 +1,8 @@
-// Copyright 2017 Frédéric Guillot. All rights reserved.
+// Copyright 2018 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
-package http
+package client
import (
"bytes"
@@ -49,6 +49,26 @@ type Client struct {
Insecure bool
}
+// WithCredentials defines the username/password for HTTP Basic authentication.
+func (c *Client) WithCredentials(username, password string) *Client {
+ c.username = username
+ c.password = password
+ return c
+}
+
+// WithAuthorization defines authorization header value.
+func (c *Client) WithAuthorization(authorization string) *Client {
+ c.authorizationHeader = authorization
+ return c
+}
+
+// WithCacheHeaders defines caching headers.
+func (c *Client) WithCacheHeaders(etagHeader, lastModifiedHeader string) *Client {
+ c.etagHeader = etagHeader
+ c.lastModifiedHeader = lastModifiedHeader
+ return c
+}
+
// Get execute a GET HTTP request.
func (c *Client) Get() (*Response, error) {
request, err := c.buildRequest(http.MethodGet, nil)
@@ -197,22 +217,7 @@ func (c *Client) buildHeaders() http.Header {
return headers
}
-// NewClient returns a new HTTP client.
-func NewClient(url string) *Client {
+// New returns a new HTTP client.
+func New(url string) *Client {
return &Client{url: url, Insecure: false}
}
-
-// NewClientWithCredentials returns a new HTTP client that requires authentication.
-func NewClientWithCredentials(url, username, password string) *Client {
- return &Client{url: url, Insecure: false, username: username, password: password}
-}
-
-// NewClientWithAuthorization returns a new client with a custom authorization header.
-func NewClientWithAuthorization(url, authorization string) *Client {
- return &Client{url: url, Insecure: false, authorizationHeader: authorization}
-}
-
-// NewClientWithCacheHeaders returns a new HTTP client that send cache headers.
-func NewClientWithCacheHeaders(url, etagHeader, lastModifiedHeader string) *Client {
- return &Client{url: url, etagHeader: etagHeader, lastModifiedHeader: lastModifiedHeader, Insecure: false}
-}
diff --git a/http/response.go b/http/client/response.go
index a0cfc3f..f033d61 100644
--- a/http/response.go
+++ b/http/client/response.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
-package http
+package client
import (
"io"
diff --git a/http/response_test.go b/http/client/response_test.go
index c5f6a1c..f3402a8 100644
--- a/http/response_test.go
+++ b/http/client/response_test.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
-package http
+package client
import "testing"
diff --git a/http/doc.go b/http/doc.go
deleted file mode 100644
index f0eb1fa..0000000
--- a/http/doc.go
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2018 Frédéric Guillot. All rights reserved.
-// Use of this source code is governed by the MIT license
-// that can be found in the LICENSE file.
-
-/*
-
-Package http implements a set of utilities related to the HTTP protocol.
-
-*/
-package http