<commit_before>package main

import (
	"fmt"
	"net"
	"net/http"
)

type hstsServer struct{}

func (server hstsServer) Handle(pattern string, handler http.Handler) {
	server.HandleFunc(pattern, handler.ServeHTTP)
}

func (hstsServer) HandleFunc(pattern string, handlerFunc http.HandlerFunc) {
	http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
		if hsts(w, r) {
			handlerFunc(w, r)
		}
	})
}

func isLocalhost(hostport string) bool {
	host, _, err := net.SplitHostPort(hostport)
	return err == nil && host == "localhost"
}

// `cont` indicates whether the callee should continue further processing.
func hsts(w http.ResponseWriter, r *http.Request) (cont bool) {
	if r.TLS != nil || maybeAppEngineHTTPS(r) {
		w.Header().Set("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload")
	}

	switch {
	case (r.Host == "hstspreload.appspot.com"):
		u := fmt.Sprintf("https://hstspreload.org%s", r.URL.Path)
		http.Redirect(w, r, u, http.StatusFound)
		return false
	case (r.TLS != nil), isLocalhost(r.Host), maybeAppEngineHTTPS(r), maybeAppEngineCron(r):
		return true
	default:
		// The redirect below causes problems with Managed VMs/Flexible Environments.
		// In a standalone server we'd handle the redirect here, but we let app.yaml
		// handle it for now.

		// u := fmt.Sprintf("https://%s%s", r.Host, r.URL.Path)
		// http.Redirect(w, r, u, http.StatusMovedPermanently)
		return false
	}<commit_msg>Change hstspreload.org redirect to a 301. #yolo<commit_after>package main

import (
	"fmt"
	"net"
	"net/http"
)

type hstsServer struct{}

func (server hstsServer) Handle(pattern string, handler http.Handler) {
	server.HandleFunc(pattern, handler.ServeHTTP)
}

func (hstsServer) HandleFunc(pattern string, handlerFunc http.HandlerFunc) {
	http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
		if hsts(w, r) {
			handlerFunc(w, r)
		}
	})
}

func isLocalhost(hostport string) bool {
	host, _, err := net.SplitHostPort(hostport)
	return err == nil && host == "localhost"
}

// `cont` indicates whether the callee should continue further processing.
func hsts(w http.ResponseWriter, r *http.Request) (cont bool) {
	if r.TLS != nil || maybeAppEngineHTTPS(r) {
		w.Header().Set("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload")
	}

	switch {
	case (r.Host == "hstspreload.appspot.com"):
		u := fmt.Sprintf("https://hstspreload.org%s", r.URL.Path)
		http.Redirect(w, r, u, http.StatusMovedPermanently)
		return false
	case (r.TLS != nil), isLocalhost(r.Host), maybeAppEngineHTTPS(r), maybeAppEngineCron(r):
		return true
	default:
		// The redirect below causes problems with Managed VMs/Flexible Environments.
		// In a standalone server we'd handle the redirect here, but we let app.yaml
		// handle it for now.

		// u := fmt.Sprintf("https://%s%s", r.Host, r.URL.Path)
		// http.Redirect(w, r, u, http.StatusMovedPermanently)
		return false
	}
{'fraction_non_alphanumeric': 0.14090754008870693, 'fraction_numerical': 0.006482429205049471, 'mean_word_length': 4.379816513761468, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '4459984', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1017, 'n_words': 262}