<commit_before>package origin

import (
	"net/http"
	"regexp"

	"github.com/golang/glog"

	"k8s.io/apimachinery/pkg/util/sets"
	apirequest "k8s.io/apiserver/pkg/endpoints/request"

	configapi "github.com/openshift/origin/pkg/cmd/server/api"
	serverhandlers "github.com/openshift/origin/pkg/cmd/server/handlers"
)

// cacheControlFilter sets the Cache-Control header to the specified value.
func cacheControlFilter(handler http.Handler, value string) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		w.Header().Set("Cache-Control", value)
		handler.ServeHTTP(w, req)
	})
}

// namespacingFilter adds a filter that adds the namespace of the request to the context.  Not all requests will have namespaces,
// but any that do will have the appropriate value added.<commit_msg>don't add cache headers to openapi<commit_after>package origin

import (
	"net/http"
	"regexp"
	"strings"

	"github.com/golang/glog"

	"k8s.io/apimachinery/pkg/util/sets"
	apirequest "k8s.io/apiserver/pkg/endpoints/request"

	configapi "github.com/openshift/origin/pkg/cmd/server/api"
	serverhandlers "github.com/openshift/origin/pkg/cmd/server/handlers"
)

// cacheExcludedPaths is small and simple until the handlers include the cache headers they need
var cacheExcludedPathPrefixes = []string{
	"/swagger-2.0.0.json",
	"/swagger-2.0.0.pb-v1",
	"/swagger-2.0.0.pb-v1.gz",
	"/swagger.json",
	"/swaggerapi",
}

// cacheControlFilter sets the Cache-Control header to the specified value.
func cacheControlFilter(handler http.Handler, value string) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		if _, ok := w.Header()["Cache-Control"]; ok {
			handler.ServeHTTP(w, req)
			return
		}
		for _, prefix := range cacheExcludedPathPrefixes {
			if strings.HasPrefix(req.URL.Path, prefix) {
				handler.ServeHTTP(w, req)
				return
			}
		}

		w.Header().Set("Cache-Control", value)
		handler.ServeHTTP(w, req)
	})
}

// namespacingFilter adds a filter that adds the namespace of the request to the context.  Not all requests will have namespaces,
// but any that do will have the appropriate value added.
{'fraction_non_alphanumeric': 0.12105751391465677, 'fraction_numerical': 0.006957328385899814, 'mean_word_length': 4.273838630806846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5981107', 'n_tokens_mistral': 766, 'n_tokens_neox': 721, 'n_words': 178}