<commit_before>package cache

import (
	"net/http"
)

/**
* Streamed Recorder is really similar to http.httpRecorder
* But this implementation is created with a ResponseWriter
* And sends the response to downstream at the same time
* the response is being recorded avoiding having to wait to
* have all the response.
 */

type StreamedRecorder struct {
	Code      int         // the HTTP response code from WriteHeader
	HeaderMap http.Header // the HTTP response headers
	Body      StorageContent
	Flushed   bool

	result      *http.Response // cache of Result's return value
	snapHeader  http.Header    // snapshot of HeaderMap at first Write
	wroteHeader bool

	w http.ResponseWriter // This is the downstream

	calledWriteListener bool
	firstWriteListener  func(int, http.Header) error
}

// NewRecorder returns an initialized StreamedRecorder.
func NewStreamedRecorder(w http.ResponseWriter) *StreamedRecorder {
	return &StreamedRecorder{
		HeaderMap:           w.Header(),
		Body:                nil,
		Code:                200,
		firstWriteListener:  nil,
		w:                   w,
		calledWriteListener: false,
	}
}

// DefaultRemoteAddr is the default remote address to return in RemoteAddr if
// an explicit DefaultRemoteAddr isn't set on StreamedRecorder.
const DefaultRemoteAddr = "1.2.3.4"

// Header returns the response headers.
func (rw *StreamedRecorder) Header() http.Header {
	return rw.w.Header()
}

// writeHeader writes a header if it was not written yet and
// detects Content-Type if needed.
//
// bytes or str are the beginning of the response body.
// We pass both to avoid unnecessarily generate garbage
// in rw.WriteString which was created for performance reasons.
// Non-nil bytes win.
func (rw *StreamedRecorder) writeHeader(b []byte, str string) {
	if rw.wroteHeader {
		return
	}
	if len(str) > 512 {
		str = str[:512]
	}

	m := rw.Header()

	_, hasType := m["Content-Type"]
	hasTE := m.Get("Transfer-Encoding") != ""
	if !hasType && !hasTE {
		if b == nil {<commit_msg> fix fix StreamRecorder is not CloseNotify  issue<commit_after>package cache

import (
	"net/http"
)

/**
* Streamed Recorder is really similar to http.httpRecorder
* But this implementation is created with a ResponseWriter
* And sends the response to downstream at the same time
* the response is being recorded avoiding having to wait to
* have all the response.
 */

type StreamedRecorder struct {
	Code      int         // the HTTP response code from WriteHeader
	HeaderMap http.Header // the HTTP response headers
	Body      StorageContent
	Flushed   bool

	result      *http.Response // cache of Result's return value
	snapHeader  http.Header    // snapshot of HeaderMap at first Write
	wroteHeader bool

	w http.ResponseWriter // This is the downstream

	calledWriteListener bool
	firstWriteListener  func(int, http.Header) error
}

// NewRecorder returns an initialized StreamedRecorder.
func NewStreamedRecorder(w http.ResponseWriter) *StreamedRecorder {
	return &StreamedRecorder{
		HeaderMap:           w.Header(),
		Body:                nil,
		Code:                200,
		firstWriteListener:  nil,
		w:                   w,
		calledWriteListener: false,
	}
}

// DefaultRemoteAddr is the default remote address to return in RemoteAddr if
// an explicit DefaultRemoteAddr isn't set on StreamedRecorder.
const DefaultRemoteAddr = "1.2.3.4"

// Header returns the response headers.
func (rw *StreamedRecorder) Header() http.Header {
	return rw.w.Header()
}

// fix StreamRecorder is not CloseNotify
func (rw *StreamedRecorder) CloseNotify() <-chan bool {
	 return rw.w.(http.CloseNotifier).CloseNotify()
}


// writeHeader writes a header if it was not written yet and
// detects Content-Type if needed.
//
// bytes or str are the beginning of the response body.
// We pass both to avoid unnecessarily generate garbage
// in rw.WriteString which was created for performance reasons.
// Non-nil bytes win.
func (rw *StreamedRecorder) writeHeader(b []byte, str string) {
	if rw.wroteHeader {
		return
	}
	if len(str) > 512 {
		str = str[:512]
	}

	m := rw.Header()

	_, hasType := m["Content-Type"]
	hasTE := m.Get("Transfer-Encoding") != ""
	if !hasType && !hasTE {
		if b == nil {
{'fraction_non_alphanumeric': 0.08611641221374046, 'fraction_numerical': 0.006202290076335878, 'mean_word_length': 3.243927125506073, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5750292', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1192, 'n_words': 460}