Skip to content

Commit

Permalink
Remove response headers
Browse files Browse the repository at this point in the history
  • Loading branch information
lewislbr committed May 24, 2024
1 parent ebe254f commit 1b51ec1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 51 deletions.
21 changes: 0 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ GSS (Go serve SPA) is a containerized web server for single-page applications wr
- Optimized for single-page apps.
- Automatically serves pre-compressed brotli and gzip files if available.
- Sensible default cache configuration.
- Configurable response headers.
- Optional out-of-the-box metrics.
- Deployable as a container.
- Lightweight.
Expand Down Expand Up @@ -100,26 +99,6 @@ Configures the port where metrics, if enabled, will be available. `8081` by defa
> metricsPort: 3001
> ```
### Response headers: `headers`
##### string: {string: string}
Headers to add to the response. `Cache-Control`, `Content-Encoding`, `Content-Type`, and `Vary` are automatically set.
> Example:
>
> ```yaml
> # gss.yaml
>
> headers:
> Content-Security-Policy: "default-src 'self'; connect-src 'self'"
> Referrer-Policy: "strict-origin-when-cross-origin"
> Strict-Transport-Security: "max-age=63072000; includeSubDomains; preload"
> X-Content-Type-Options: "nosniff"
> X-Frame-Options: "SAMEORIGIN"
> X-XSS-Protection: "1; mode=block"
> ```
### Metrics collection: `metrics`
##### string: boolean
Expand Down
18 changes: 5 additions & 13 deletions gss.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,16 @@ func setUpLogger() {
}

type config struct {
FilesPort int `yaml:"filesPort,omitempty"`
MetricsPort int `yaml:"metricsPort,omitempty"`
ResponseHeaders map[string]string `yaml:"headers,omitempty"`
MetricsEnabled bool `yaml:"metrics,omitempty"`
FilesPort int `yaml:"filesPort,omitempty"`
MetricsPort int `yaml:"metricsPort,omitempty"`
MetricsEnabled bool `yaml:"metrics,omitempty"`
}

func newConfig() *config {
return &config{
// Default values
FilesPort: 8080,
MetricsPort: 8081,
ResponseHeaders: map[string]string{
"Server": "GSS",
},
FilesPort: 8080,
MetricsPort: 8081,
MetricsEnabled: false,
}
}
Expand Down Expand Up @@ -122,10 +118,6 @@ func (f *fileServer) setHeaders(h http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Vary", "Accept-Encoding")

for k, v := range f.Config.ResponseHeaders {
w.Header().Set(k, v)
}

h.ServeHTTP(w, r)
}
}
Expand Down
17 changes: 0 additions & 17 deletions gss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,6 @@ import (
func TestGSS(t *testing.T) {
metrics := registerMetrics()

t.Run("uses the provided headers", func(t *testing.T) {
t.Parallel()

cfg := &config{
ResponseHeaders: map[string]string{
"X-Test": "test",
},
}
fileServer := newFileServer(cfg, metrics).init()
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/", nil)

fileServer.Server.Handler.ServeHTTP(w, r)

assert.Equal(t, "test", w.Header().Get("X-Test"))
})

t.Run("redirects index correctly", func(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 1b51ec1

Please sign in to comment.