<commit_before>package main

import (
	"log"
	"net/http"
	"path/filepath"

	casper "github.com/tcnksm/go-casper"
)

func main() {
	certFile, _ := filepath.Abs("crts/server.crt")
	keyFile, _ := filepath.Abs("crts/server.key")

	http.Handle("/static/",
		http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))),
	)

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		csp := casper.New(1<<6, 10)
		if _, err := csp.Push(w, r, "/static/example.jpg", &casper.Options{}); err != nil {
			log.Fatal(err)
		}
		if _, err := csp.Push(w, r, "/static/example2.jpg", &casper.Options{}); err != nil {
			log.Fatal(err)
		}

		w.Header().Add("Content-Type", "text/html")
		w.Write([]byte(`<img src="/static/example.jpg"/>`))
	})

	log.Println(":3000")
	if err := http.ListenAndServeTLS(":3000", certFile, keyFile, nil); err != nil {
		log.Printf("[ERROR] %s", err)
	}<commit_msg>Useful example<commit_after>package main

import (
	"log"
	"net/http"
	"path/filepath"

	casper "github.com/tcnksm/go-casper"
)

const (
	defaultPort = "3000"
)

func main() {
	// See README.md to generate crt and key for this testing.
	certFile, _ := filepath.Abs("crts/server.crt")
	keyFile, _ := filepath.Abs("crts/server.key")

	// Initialize casper.
	pusher := casper.New(1<<6, 10)

	// Handle root
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		log.Printf("[INFO] %s %s", r.Method, r.URL.String())

		assets := []string{
			"/static/example.jpg",
		}

		// Server push!
		if _, err := pusher.Push(w, r, assets, nil); err != nil {
			log.Fatalf("[ERROR] Failed to push assets %v: %s", assets, err)
		}

		// Check what is pushed.
		if pushed := pusher.Pushed(); len(pushed) != 0 {
			log.Printf("[INFO] Pushed!: %v", pushed)
		}

		w.Header().Add("Content-Type", "text/html")
		w.Write([]byte(`<img src="/static/example.jpg"/>`))
	})

	// Handle static assets.
	http.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
		log.Printf("[INFO] %s %s", r.Method, r.URL.String())
		http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))).ServeHTTP(w, r)
	})

	// Start listening.
	log.Println("[INFO] Start listening on port", ":"+defaultPort)
	if err := http.ListenAndServeTLS(":"+defaultPort, certFile, keyFile, nil); err != nil {
		log.Fatalf("[ERROR] Failed to listen: %s", err)
	}
{'fraction_non_alphanumeric': 0.2132762312633833, 'fraction_numerical': 0.009421841541755889, 'mean_word_length': 3.8364389233954452, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 5, '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': '864787', 'n_tokens_mistral': 957, 'n_tokens_neox': 909, 'n_words': 181}