summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/client.go1
-rw-r--r--client/client_test.go27
2 files changed, 27 insertions, 1 deletions
diff --git a/client/client.go b/client/client.go
index a60ee00..a2868f2 100644
--- a/client/client.go
+++ b/client/client.go
@@ -26,5 +26,6 @@ func Get(url string) (*http.Response, error) {
func buildHeaders(req *http.Request) *http.Request {
req.Header.Set("User-Agent", "peach/"+version.Version+
" peach.ricketyspace.net")
+ req.Header.Set("Cache-Control", "max-age=0")
return req
}
diff --git a/client/client_test.go b/client/client_test.go
index ea2a7b5..b0309c7 100644
--- a/client/client_test.go
+++ b/client/client_test.go
@@ -4,12 +4,37 @@
package client
import (
+ "fmt"
"io"
+ "net/http"
+ "net/http/httptest"
"testing"
+
+ "ricketyspace.net/peach/version"
)
func TestGet(t *testing.T) {
- res, err := Get("https://plan.cat/~s")
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ // Check user-agent header.
+ expectedUA := fmt.Sprintf("peach/%s peach.ricketyspace.net",
+ version.Version)
+ if r.Header.Get("User-Agent") != expectedUA {
+ t.Errorf("header: user agent: %v != %v",
+ r.Header.Get("User-Agent"), expectedUA)
+ return
+ }
+
+ // Check cache-control header.
+ if r.Header.Get("Cache-Control") != "max-age=0" {
+ t.Errorf("header: cache control: %v != max-age=0",
+ r.Header.Get("Cache-Control"))
+ return
+ }
+ fmt.Fprint(w, "OK")
+ }))
+ defer ts.Close()
+
+ res, err := Get(ts.URL)
if err != nil {
t.Errorf("get failed: %v", err)
return