diff options
author | Ben Morrison <ben@gbmor.dev> | 2020-05-09 14:36:55 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2020-05-09 14:36:55 -0400 |
commit | 707e45702f7aed6d0a0f12c68f235f0fe8bdd9a1 (patch) | |
tree | 6ab3e89e7d3b4c33a5922e0d54342b8817dcfaa6 /http.go | |
parent | 1e93f53cbea237fa9fdcced97971198cd897dc9b (diff) | |
download | api-707e45702f7aed6d0a0f12c68f235f0fe8bdd9a1.tar.gz |
cache.yoink(requestPath) now returns both the raw
response body from the cache and the expiration time formatted as an rfc1123 datetime. added a default clause to cache.bap(requestPath) that responds with a failure state if an invalid query type has been requested.
Diffstat (limited to 'http.go')
-rw-r--r-- | http.go | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/http.go b/http.go index a2948f7..8ef76c5 100644 --- a/http.go +++ b/http.go @@ -9,10 +9,7 @@ import ( const mimePlain = "text/plain; charset=utf-8" const mimeJSON = "application/json; charset=utf-8" -// Validates the request and then sends it off to where it needs to go. -// Eventually. -// I chose this monolithic handler that calls validation functions to -// determine what to do next because this will make it easier to test. +// Validates the request and then queries the cache for the response. func mainHandler(w http.ResponseWriter, r *http.Request) { if !methodHop(r) { errHTTP(w, r, errors.New("405 Method Not Allowed"), http.StatusMethodNotAllowed) @@ -26,7 +23,7 @@ func mainHandler(w http.ResponseWriter, r *http.Request) { } cache.bap(r.URL.Path) - out := cache.yoink(r.URL.Path) + out, expires := cache.yoink(r.URL.Path) if format == "json" { w.Header().Set("Content-Type", mimeJSON) @@ -34,7 +31,7 @@ func mainHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", mimePlain) } - w.Header().Set("Expires", cache.expiresWhen(r.URL.Path)) + w.Header().Set("Expires", expires) _, err := w.Write(out) if err != nil { |