-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I want to proxy this service behind Cloudflare in order to hide its IP. Cloudflare has its own rules for what to cache and how long. I don't want to rely on that, this force it to never cache.
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package util | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestNoStoreMiddleware(t *testing.T) { | ||
sampleHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
}) | ||
|
||
handler := NoStoreMiddleware(sampleHandler) | ||
|
||
tests := []struct { | ||
method string | ||
expectedCacheControl string | ||
}{ | ||
{"GET", "no-store"}, | ||
{"POST", ""}, | ||
} | ||
|
||
for _, tt := range tests { | ||
req, err := http.NewRequest(tt.method, "/test", nil) | ||
if err != nil { | ||
t.Fatalf("Could not create %v request: %v", tt.method, err) | ||
} | ||
|
||
recorder := httptest.NewRecorder() | ||
handler.ServeHTTP(recorder, req) | ||
|
||
actualCacheControl := recorder.Header().Get("Cache-Control") | ||
if actualCacheControl != tt.expectedCacheControl { | ||
t.Errorf("expected Cache-Control header to be %q for %v request, got %q", | ||
tt.expectedCacheControl, tt.method, actualCacheControl) | ||
} | ||
} | ||
} |