github.com/vmware/transport-go@v1.3.4/plank/pkg/middleware/basic_security_headers.go (about)

     1  // Copyright 2019-2021 VMware, Inc.
     2  // SPDX-License-Identifier: BSD-2-Clause
     3  
     4  package middleware
     5  
     6  import (
     7  	"github.com/gorilla/mux"
     8  	"net/http"
     9  )
    10  
    11  func BasicSecurityHeaderMiddleware() mux.MiddlewareFunc {
    12  	return func(handler http.Handler) http.Handler {
    13  		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    14  			w.Header().Set("X-Content-Type-Options", "no-sniff")
    15  			w.Header().Set("X-Frame-Options", "SAMEORIGIN")
    16  			w.Header().Set("X-Xss-Protection", "1; mode=block")
    17  			handler.ServeHTTP(w, r)
    18  		})
    19  	}
    20  }