Contains the Concourse pipeline definition for building a line-server container
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
697 B

  1. package main
  2. import (
  3. "net/http"
  4. )
  5. const (
  6. cspHeader = "Content-Security-Policy"
  7. frameOptionsHeader = "X-Frame-Options"
  8. )
  9. type csp struct {
  10. h http.Handler
  11. opts CSPOptions
  12. }
  13. type CSPOptions struct {
  14. policy string
  15. frame string
  16. }
  17. func (c csp) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  18. // only add a CSP if one is not already set
  19. if existing := w.Header().Get(cspHeader); existing == "" {
  20. w.Header().Add(cspHeader, c.opts.policy)
  21. }
  22. w.Header().Set(frameOptionsHeader, c.opts.frame)
  23. c.h.ServeHTTP(w, r)
  24. }
  25. func ContentSecurityPolicy(o CSPOptions) func(http.Handler) http.Handler {
  26. fn := func(h http.Handler) http.Handler {
  27. return csp{h, o}
  28. }
  29. return fn
  30. }