<commit_before>// Package jest provides a minimal wrapper to net/http for building JSON in/out
// API's. Jest assumes all routes require authorization unless stated otherwise
// and conveniences such as secure response headers and `OPTIONS` responses.
// Jest also respects routes declared on net/http directly.
//
//  package main
//
//  import (
//    "encoding/json"
//    "github.com/daneharrigan/jest"
//    "net/http"
//  )
//
//  func main() {
//    jest.Auth(handleAuth)
//    jest.Get("/", serveIndex)
//    http.ListenAndServe(":5000", jest.Handler())
//  }
//
//  func handleAuth(w http.ResponseWriter, r *http.Request) *jest.Status {
//    if loggedIn() {
//      return jest.OK
//    }
//
//    return jest.Forbidden
//  }
//
//  func serveIndex(w http.ResponseWriter, r *http.Request) *jest.Status {
//    json.NewEncoder(w).Encode(getItems())
//    return jest.OK
//  }
package jest

import (
	"encoding/json"
	"github.com/kr/secureheader"
	"net/http"
	"os"
	"regexp"
	"strings"
)

var (
	config      *secureheader.Config
	routes      []route
	authorize   func(http.ResponseWriter, *http.Request) *Status
	contentType string
)

func init() {
	contentType = "application/json"
	config = secureheader.DefaultConfig
	http.HandleFunc("/", serveResponses)
}

/* public */

// Handler returns an http handler for http.ListenAndServe. The handler is
// provided by github.com/kr/secureheader and decorates HTTP response with
// a series of secure header information.
func Handler() *secureheader.Config {
	config.HTTPSRedirect = os.Getenv("JEST_HTTPS") != "false"
	return config
}

// Auth accepts a method for granting/denying access to protected routes.
// Returning a jest.Status struct is used to determine whether authorization
// should be allowed or denied.
func Auth(fn func(http.ResponseWriter, *http.Request) *Status) {
	authorize = fn
}

func Get(uri string, f func(http.ResponseWriter, *http.Request) *Status) *response {
	return request("GET", uri, f)
}

func Post(uri string, f func(http.ResponseWriter, *http.Request) *Status) *response {
	return request("POST", uri, f)
}

func Put(uri string, f func(http.ResponseWriter, *http.Request) *Status) *response {
	return request("PUT", uri, f)
}

func Patch(uri string, f func(http.ResponseWriter, *http.Request) *Status) *response {
	return request("PATCH", uri, f)
}

func Delete(uri string, f func(http.ResponseWriter, *http.Request) *Status) *response {
	return request("DELETE", uri, f)
}
<commit_msg>read HTTP and JEST_HTTPS<commit_after>// Package jest provides a minimal wrapper to net/http for building JSON in/out
// API's. Jest assumes all routes require authorization unless stated otherwise
// and conveniences such as secure response headers and `OPTIONS` responses.
// Jest also respects routes declared on net/http directly.
//
//  package main
//
//  import (
//    "encoding/json"
//    "github.com/daneharrigan/jest"
//    "net/http"
//  )
//
//  func main() {
//    jest.Auth(handleAuth)
//    jest.Get("/", serveIndex)
//    http.ListenAndServe(":5000", jest.Handler())
//  }
//
//  func handleAuth(w http.ResponseWriter, r *http.Request) *jest.Status {
//    if loggedIn() {
//      return jest.OK
//    }
//
//    return jest.Forbidden
//  }
//
//  func serveIndex(w http.ResponseWriter, r *http.Request) *jest.Status {
//    json.NewEncoder(w).Encode(getItems())
//    return jest.OK
//  }
package jest

import (
	"encoding/json"
	"github.com/kr/secureheader"
	"net/http"
	"os"
	"regexp"
	"strings"
)

var (
	config      *secureheader.Config
	routes      []route
	authorize   func(http.ResponseWriter, *http.Request) *Status
	contentType string
)

func init() {
	contentType = "application/json"
	config = secureheader.DefaultConfig
	http.HandleFunc("/", serveResponses)
}

/* public */

// Handler returns an http handler for http.ListenAndServe. The handler is
// provided by github.com/kr/secureheader and decorates HTTP response with
// a series of secure header information.
func Handler() *secureheader.Config {
	https := os.Getenv("HTTPS")
	if https == "" {
		https = os.Getenv("JEST_HTTPS")
	}

	config.HTTPSRedirect = https != "false"
	return config
}

// Auth accepts a method for granting/denying access to protected routes.
// Returning a jest.Status struct is used to determine whether authorization
// should be allowed or denied.
func Auth(fn func(http.ResponseWriter, *http.Request) *Status) {
	authorize = fn
}

func Get(uri string, f func(http.ResponseWriter, *http.Request) *Status) *response {
	return request("GET", uri, f)
}

func Post(uri string, f func(http.ResponseWriter, *http.Request) *Status) *response {
	return request("POST", uri, f)
}

func Put(uri string, f func(http.ResponseWriter, *http.Request) *Status) *response {
	return request("PUT", uri, f)
}

func Patch(uri string, f func(http.ResponseWriter, *http.Request) *Status) *response {
	return request("PATCH", uri, f)
}

func Delete(uri string, f func(http.ResponseWriter, *http.Request) *Status) *response {
	return request("DELETE", uri, f)
}

{'fraction_non_alphanumeric': 0.14001591089896578, 'fraction_numerical': 0.0015910898965791568, 'mean_word_length': 3.626494940202392, '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': '1227121', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1598, 'n_words': 465}