<commit_before>package kwiscale

import (
	"crypto/md5"
	"fmt"
	"net/http"
	"os"
	"path/filepath"
)

// StaticHandler handle static files handlers. Use App.SetStatic(path) that create the static handler
type staticHandler struct {
	RequestHandler
}

// Use http.FileServer to serve file after adding ETag.
func (s *staticHandler) Get() {
	file := s.Vars["file"]
	file = filepath.Join(s.app.Config.StaticDir, file)

	// control or add etag
	if etag, err := eTag(file); err == nil {
		s.response.Header().Add("ETag", etag)
	}

	fs := http.FileServer(http.Dir(s.app.Config.StaticDir))
	fs.ServeHTTP(s.response, s.request)
}

// Get a etag for the file. It's constuct with a md5 sum of
// <filename> + "." + <modification-time>
func eTag(file string) (string, error) {
	stat, err := os.Stat(file)
	if err != nil {
		return "", err
	}

	s := md5.Sum([]byte(stat.Name() + "." + stat.ModTime().String()))
	return fmt.Sprintf("%x", s), nil
}
<commit_msg>Fix prefix problem that made a 404 error<commit_after>package kwiscale

import (
	"crypto/md5"
	"fmt"
	"net/http"
	"os"
	"path/filepath"
)

// StaticHandler handle static files handlers. Use App.SetStatic(path) that create the static handler
type staticHandler struct {
	RequestHandler
}

// Use http.FileServer to serve file after adding ETag.
func (s *staticHandler) Get() {
	file := s.Vars["file"]
	abs, _ := filepath.Abs(s.app.Config.StaticDir)
	file = filepath.Join(abs, file)

	// control or add etag
	if etag, err := eTag(file); err == nil {
		s.response.Header().Add("ETag", etag)
	}

	// create a fileserver for the static dir
	fs := http.FileServer(http.Dir(s.app.Config.StaticDir))
	// stip directory name and serve the file
	http.StripPrefix("/"+filepath.Base(s.app.Config.StaticDir), fs).
		ServeHTTP(s.Response(), s.Request())
}

// Get a etag for the file. It's constuct with a md5 sum of
// <filename> + "." + <modification-time>
func eTag(file string) (string, error) {
	stat, err := os.Stat(file)
	if err != nil {
		return "", err
	}

	s := md5.Sum([]byte(stat.Name() + "." + stat.ModTime().String()))
	return fmt.Sprintf("%x", s), nil
}

{'fraction_non_alphanumeric': 0.1636536631779258, 'fraction_numerical': 0.004281636536631779, 'mean_word_length': 3.8013698630136985, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1020116', 'n_tokens_mistral': 776, 'n_tokens_neox': 753, 'n_words': 209}