diff options
-rw-r--r-- | client/client.go | 1 | ||||
-rw-r--r-- | client/client_test.go | 27 | ||||
-rw-r--r-- | version/version.go | 2 |
3 files changed, 28 insertions, 2 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 diff --git a/version/version.go b/version/version.go index 23e1a19..8142cd6 100644 --- a/version/version.go +++ b/version/version.go @@ -4,4 +4,4 @@ // Peach version. package version -const Version = "0.8.1" +const Version = "0.8.2.dev" |