<commit_before>// Copyright (c) 2014-2019 <NAME>
// Licensed under the MIT license

package http

import (
	"net/http"
	"net/url"
)

// RequestType defines the type of the request
type RequestType int

// SecureOption is the type that defines TLS requirements
type SecureOption int

const (
	STANDARD RequestType = iota
	MIRRORLIST
	FILESTATS
	MIRRORSTATS
	CHECKSUM

	UNDEFINED SecureOption = iota
	WITHTLS
	WITHOUTTLS
)

// Context represents the context of a request
type Context struct {
	r             *http.Request
	w             http.ResponseWriter
	t             Templates
	v             url.Values
	typ           RequestType
	isMirrorList  bool
	isMirrorStats bool
	isFileStats   bool
	isChecksum    bool
	isPretty      bool
	secureOption  SecureOption
}

// NewContext returns a new instance of Context
func NewContext(w http.ResponseWriter, r *http.Request, t Templates) *Context {
	c := &Context{r: r, w: w, t: t, v: r.URL.Query()}

	if c.paramBool("mirrorlist") {
		c.typ = MIRRORLIST
		c.isMirrorList = true
	} else if c.paramBool("stats") {
		c.typ = FILESTATS
		c.isFileStats = true
	} else if c.paramBool("mirrorstats") {
		c.typ = MIRRORSTATS
		c.isMirrorStats = true
	} else if c.paramBool("md5") || c.paramBool("sha1") || c.paramBool("sha256") {
		c.typ = CHECKSUM
		c.isChecksum = true
	} else {
		c.typ = STANDARD
	}

	if c.paramBool("pretty") {
		c.isPretty = true
	}

	// Check for HTTPS requirements
	v, ok := c.v["https"]<commit_msg>require https based on X-Forwarded-Proto header<commit_after>// Copyright (c) 2014-2019 <NAME>
// Licensed under the MIT license

package http

import (
	"net/http"
	"net/url"
	"strings"
)

// RequestType defines the type of the request
type RequestType int

// SecureOption is the type that defines TLS requirements
type SecureOption int

const (
	STANDARD RequestType = iota
	MIRRORLIST
	FILESTATS
	MIRRORSTATS
	CHECKSUM

	UNDEFINED SecureOption = iota
	WITHTLS
	WITHOUTTLS
)

// Context represents the context of a request
type Context struct {
	r             *http.Request
	w             http.ResponseWriter
	t             Templates
	v             url.Values
	typ           RequestType
	isMirrorList  bool
	isMirrorStats bool
	isFileStats   bool
	isChecksum    bool
	isPretty      bool
	secureOption  SecureOption
}

// NewContext returns a new instance of Context
func NewContext(w http.ResponseWriter, r *http.Request, t Templates) *Context {
	c := &Context{r: r, w: w, t: t, v: r.URL.Query()}

	if c.paramBool("mirrorlist") {
		c.typ = MIRRORLIST
		c.isMirrorList = true
	} else if c.paramBool("stats") {
		c.typ = FILESTATS
		c.isFileStats = true
	} else if c.paramBool("mirrorstats") {
		c.typ = MIRRORSTATS
		c.isMirrorStats = true
	} else if c.paramBool("md5") || c.paramBool("sha1") || c.paramBool("sha256") {
		c.typ = CHECKSUM
		c.isChecksum = true
	} else {
		c.typ = STANDARD
	}

	if c.paramBool("pretty") {
		c.isPretty = true
	}

	// Check for HTTPS requirements
	proto := r.Header.Get("X-Forwarded-Proto")
	if strings.ToLower(proto) == "https" {
		c.secureOption = WITHTLS
	}

	v, ok := c.v["https"]
{'fraction_non_alphanumeric': 0.1017555266579974, 'fraction_numerical': 0.008452535760728219, 'mean_word_length': 3.0486842105263157, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6837634', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1081, 'n_words': 308}