<commit_before>package main

import (
	"bufio"
        "log"
        "net/http"
        "net/http/httputil"
	"os"
	"strings"
)

const (
	CONFIG_FILE = "config.txt"
)

func loadConfig() ([]string, error) {
	file, err := os.Open(CONFIG_FILE)
	if err != nil {
		return nil, err
	}

	defer file.Close()

	var lines []string
	s := bufio.NewScanner(file)
	for s.Scan() {
		lines = append(lines, s.Text())
	}
	return lines, nil
}

func requestForValidPath(r *http.Request, config []string) bool {
	path := strings.TrimPrefix(r.URL.Path, "/")
	for _, s := range config {
		if s == path {
			return true
		}
	}

	return false
}

func main() {
	cfg, err := loadConfig()
	if err !=nil {
		log.Fatal(err)
	}

	log.Println(cfg)

        http.HandleFunc("/",  func(w http.ResponseWriter, r *http.Request) {
		bytes, err := httputil.DumpRequest(r, true)
		if err != nil {
			log.Println(err)
			return
		}

		log.Println(string(bytes))
		if strings.ToUpper(r.Method) == "POST" && requestForValidPath(r, cfg) {
			w.WriteHeader(http.StatusOK)
		} else {
			w.WriteHeader(http.StatusBadRequest)
		}

        })
        log.Fatal(http.ListenAndServe(":80", nil))
}<commit_msg>log bad requests for #2<commit_after>package main

import (
	"bufio"
        "log"
        "net/http"
        "net/http/httputil"
	"os"
	"strings"
)

const (
	CONFIG_FILE = "config.txt"
)

func loadConfig() ([]string, error) {
	file, err := os.Open(CONFIG_FILE)
	if err != nil {
		return nil, err
	}

	defer file.Close()

	var lines []string
	s := bufio.NewScanner(file)
	for s.Scan() {
		lines = append(lines, s.Text())
	}
	return lines, nil
}

func requestForValidPath(r *http.Request, config []string) bool {
	path := strings.TrimPrefix(r.URL.Path, "/")
	for _, s := range config {
		if s == path {
			return true
		}
	}

	return false
}

func main() {
	cfg, err := loadConfig()
	if err !=nil {
		log.Fatal(err)
	}

	log.Println(cfg)

        http.HandleFunc("/",  func(w http.ResponseWriter, r *http.Request) {
		bytes, err := httputil.DumpRequest(r, true)
		if err != nil {
			log.Println(err)
			return
		}

		log.Println(string(bytes))
		if strings.ToUpper(r.Method) == "POST" && requestForValidPath(r, cfg) {
			w.WriteHeader(http.StatusOK)
		} else {
			log.Println("Bad request for " + r.URL.Path)
			w.WriteHeader(http.StatusBadRequest)
		}

        })
        log.Fatal(http.ListenAndServe(":80", nil))
}
{'fraction_non_alphanumeric': 0.16048862679022746, 'fraction_numerical': 0.0021061499578770007, 'mean_word_length': 3.0050590219224285, 'pattern_counts': {'":': 2, '<': 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': '3758310', 'n_tokens_mistral': 974, 'n_tokens_neox': 904, 'n_words': 196}