<commit_before>package spoon

import (
	"io/ioutil"
	"net/http"
	"os"
)

type updateHandler struct {
	filename       string
	updateStrategy UpdateStrategy
}

// ServerAutoUpdate calls ServerAutoUpdateHandler to get the handler
// and runs an http server in another goroutine
func ServerAutoUpdate(updateStrategy UpdateStrategy, url string, addr string, filename string) {
	handler := ServerAutoUpdateHandler(updateStrategy, filename)

	http.Handle(url, handler)
	go http.ListenAndServe(addr, nil)
}

// ServerTLSAutoUpdate calls ServerAutoUpdateHandler to get the handler
// and runs an http TLS server in another goroutine
func ServerTLSAutoUpdate(updateStrategy UpdateStrategy, url string, addr string, filename string, certFile string, keyFile string) {
	handler := ServerAutoUpdateHandler(updateStrategy, filename)

	http.Handle(url, handler)
	go http.ListenAndServeTLS(addr, certFile, keyFile, nil)
}
<commit_msg>Add easier way to chain a handler prior to running update logic<commit_after>package spoon

import (
	"io/ioutil"
	"net/http"
	"os"
)

type updateHandler struct {
	filename       string
	updateStrategy UpdateStrategy
}

type wrapHandler struct {
	preHandler PreHandler
	next       http.Handler
}

func (wh *wrapHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	wh.preHandler(wh.next, w, r)
}

// PreHandler used if some sort of pre auth check or something needs to be done prior
// for checking for an update.
type PreHandler func(next http.Handler, w http.ResponseWriter, r *http.Request)

// ServerAutoUpdate calls ServerAutoUpdateHandler to get the handler
// and runs an http server in another goroutine
func ServerAutoUpdate(updateStrategy UpdateStrategy, url string, addr string, filename string, preHandler PreHandler) {

	handler := ServerAutoUpdateHandler(updateStrategy, filename)

	if preHandler != nil {
		next := handler
		handler = &wrapHandler{
			preHandler: preHandler,
			next:       next,
		}
	}

	http.Handle(url, handler)
	go http.ListenAndServe(addr, nil)
}

// ServerTLSAutoUpdate calls ServerAutoUpdateHandler to get the handler
// and runs an http TLS server in another goroutine
func ServerTLSAutoUpdate(updateStrategy UpdateStrategy, url string, addr string, filename string, certFile string, keyFile string, preHandler PreHandler) {

	handler := ServerAutoUpdateHandler(updateStrategy, filename)

	if preHandler != nil {
		next := handler
		handler = &wrapHandler{
			preHandler: preHandler,
			next:       next,
		}
	}

	http.Handle(url, handler)
	go http.ListenAndServeTLS(addr, certFile, keyFile, nil)
}

{'fraction_non_alphanumeric': 0.07680311890838207, 'fraction_numerical': 0.0, 'mean_word_length': 4.81859410430839, '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': '3050381', 'n_tokens_mistral': 750, 'n_tokens_neox': 728, 'n_words': 251}