<commit_before>package neo

import (
	"encoding/json"
	"encoding/xml"
	"net/http"
	"os"
	"path/filepath"
)

// Server response representation.
type Response struct {
	Status  int
	Writer  http.ResponseWriter
	request *http.Request
	Cookie  Cookie
	data    []byte
	// defer file sending
	file       string
	_skipFlush bool
	Header     http.Header
}

// making response representation
func makeResponse(request *http.Request, w http.ResponseWriter) *Response {
	response := &Response{
		request: request,
		Writer:  w,
		Cookie:  Cookie{},
		Header:  w.Header(),
	}

	return response
}

///////////////////////////////////////////////////////////////////
// Creating Responses
///////////////////////////////////////////////////////////////////

// Will produce JSON string representation of passed object,
// and send it to client
func (r *Response) Json(obj interface{}, status int) {
	res, err := json.Marshal(obj)
	if err != nil {
		log.Error(err.Error())
		return
	}

	r.Header.Add("Content-Type", "application/json")
	r.Raw(res, status)
}

// Will produce XML string representation of passed object,
// and send it to client
func (r *Response) Xml(obj interface{}, status int) {
	res, err := xml.Marshal(obj)
	if err != nil {
		log.Error(err.Error())
		return
	}

	r.Header.Add("Content-Type", "application/xml")
	r.Raw(res, status)
}

// Will send provided Text to client.
func (r *Response) Text(text string, status int) {
	r.Header.Add("Content-Type", "text/plain")
	r.Raw([]byte(text), status)
}

// Will look for template, render it, and send rendered HTML to client.
// Second argument is data which will be passed to client.
func (r *Response) Tpl(name string, data interface{}) {
	log.Infof("Rendering template %s", name)

	err := renderTpl(r.Writer, name, data)
	if err != nil {
		log.Error(err.Error())
		r.Status = http.StatusNotFound
	} else {
		r.Status = http.StatusOK
	}

	r.skipFlush()
}

// Send Raw data to client.
func (r *Response) Raw(data []byte, status int) {
	r.Status = status
	r.data = data<commit_msg>writing headers improvement<commit_after>package neo

import (
	"encoding/json"
	"encoding/xml"
	"net/http"
	"os"
	"path/filepath"
)

// Server response representation.
type Response struct {
	Status  int
	Writer  http.ResponseWriter
	request *http.Request
	Cookie  Cookie
	data    []byte
	// defer file sending
	file       string
	_skipFlush bool
	Header     http.Header
}

// making response representation
func makeResponse(request *http.Request, w http.ResponseWriter) *Response {
	response := &Response{
		request: request,
		Writer:  w,
		Cookie:  Cookie{},
		Header:  w.Header(),
	}

	return response
}

///////////////////////////////////////////////////////////////////
// Creating Responses
///////////////////////////////////////////////////////////////////

// Will produce JSON string representation of passed object,
// and send it to client
func (r *Response) Json(obj interface{}, status int) {
	res, err := json.Marshal(obj)
	if err != nil {
		log.Error(err.Error())
		return
	}

	r.Header.Set("Content-Type", "application/json")
	r.Raw(res, status)
}

// Will produce XML string representation of passed object,
// and send it to client
func (r *Response) Xml(obj interface{}, status int) {
	res, err := xml.Marshal(obj)
	if err != nil {
		log.Error(err.Error())
		return
	}

	r.Header.Set("Content-Type", "application/xml")
	r.Raw(res, status)
}

// Will send provided Text to client.
func (r *Response) Text(text string, status int) {
	r.Raw([]byte(text), status)
}

// Will look for template, render it, and send rendered HTML to client.
// Second argument is data which will be passed to client.
func (r *Response) Tpl(name string, data interface{}) {
	log.Infof("Rendering template %s", name)

	err := renderTpl(r.Writer, name, data)
	if err != nil {
		log.Error(err.Error())
		r.Status = http.StatusNotFound
	} else {
		r.Status = http.StatusOK
	}

	r.skipFlush()
}

// Send Raw data to client.
func (r *Response) Raw(data []byte, status int) {
	r.Status = status
	r.data = data
{'fraction_non_alphanumeric': 0.18963807635101637, 'fraction_numerical': 0.0, 'mean_word_length': 2.7154696132596685, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '5950010', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1245, 'n_words': 399}