<commit_before>package coreutil

import (
	"net/http"
	"reflect"
)

// ResponseStatus returns the HTTP response status.
// Remember that the status is only set by the server after ResponseWriter.WriteHeader() has been called.
func ResponseStatus(w http.ResponseWriter) int {
	return int(httpResponseStruct(reflect.ValueOf(w)).FieldByName("status").Int())
}

// httpResponseStruct returns the response structure after going trough all the intermediary responseWriter Binders.
func httpResponseStruct(v reflect.Value) reflect.Value {
	switch v.Type().String() {
	case "core.ResponseWriterBinder":
		return httpResponseStruct(v.FieldByName("ResponseWriter").Elem())
	case "*http.response":
		return v.Elem()
	default:
		panic("coreutil: call of httpResponseStruct on unknown interface type")
	}
}

// SetDetectedContentType detects and sets the correct content type.
func SetDetectedContentType(w http.ResponseWriter, b []byte) {
	if len(w.Header().Get("Content-Type")) == 0 {
		w.Header().Set("Content-Type", http.DetectContentType(b))
	}
}<commit_msg>Get context instead of response writer<commit_after>package coreutil

import (
	"net/http"
	"reflect"

	"github.com/volatile/core"
)

// ResponseStatus returns the HTTP response status.
// Remember that the status is only set by the server after ResponseWriter.WriteHeader() has been called.
func ResponseStatus(c *core.Context) int {
	return int(httpResponseStruct(reflect.ValueOf(c.ResponseWriter)).FieldByName("status").Int())
}

// httpResponseStruct returns the response structure after going trough all the intermediary responseWriter Binders.
func httpResponseStruct(v reflect.Value) reflect.Value {
	switch v.Type().String() {
	case "core.ResponseWriterBinder":
		return httpResponseStruct(v.FieldByName("ResponseWriter").Elem())
	case "*http.response":
		return v.Elem()
	default:
		panic("coreutil: call of httpResponseStruct on unknown interface type")
	}
}

// SetDetectedContentType detects and sets the correct content type.
func SetDetectedContentType(c *core.Context, b []byte) {
	if len(c.ResponseWriter.Header().Get("Content-Type")) == 0 {
		c.ResponseWriter.Header().Set("Content-Type", http.DetectContentType(b))
	}
}
{'fraction_non_alphanumeric': 0.11705532693187014, 'fraction_numerical': 0.0009144947416552355, 'mean_word_length': 5.57057057057057, 'pattern_counts': {'":': 4, '<': 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': '2807236', 'n_tokens_mistral': 642, 'n_tokens_neox': 620, 'n_words': 178}