<commit_before>package config

import (
	"github.com/mholt/caddy/middleware"
	"github.com/mholt/caddy/middleware/browse"
	"github.com/mholt/caddy/middleware/extensionless"
	"github.com/mholt/caddy/middleware/fastcgi"
	"github.com/mholt/caddy/middleware/gzip"
	"github.com/mholt/caddy/middleware/headers"
	"github.com/mholt/caddy/middleware/log"
	"github.com/mholt/caddy/middleware/markdown"
	"github.com/mholt/caddy/middleware/proxy"
	"github.com/mholt/caddy/middleware/redirect"
	"github.com/mholt/caddy/middleware/rewrite"
	"github.com/mholt/caddy/middleware/websockets"
)

// This init function registers middleware. Register middleware
// in the order they should be executed during a request.
// Middleware execute in this order: A-B-C-*-C-B-A
// assuming they call the Next handler in the chain.
func init() {
	register("gzip", gzip.New)
	register("header", headers.New)
	register("log", log.New)
	register("rewrite", rewrite.New)
	register("redirect", redirect.New)
	register("ext", extensionless.New)
	register("proxy", proxy.New)
	register("fastcgi", fastcgi.New)
	register("websocket", websockets.New)
	register("markdown", markdown.New)
	register("browse", browse.New)
}

// registry stores the registered middleware:
// both the order and the directives to which they
// are bound.
var registry = struct {
	directiveMap map[string]middleware.Generator
	ordered      []string
}{
	directiveMap: make(map[string]middleware.Generator),
}

// register binds a middleware generator (outer function)
// to a directive. Upon each request, middleware will be<commit_msg>Better middleware godoc, fixed ordering too<commit_after>package config

import (
	"github.com/mholt/caddy/middleware"
	"github.com/mholt/caddy/middleware/browse"
	"github.com/mholt/caddy/middleware/errors"
	"github.com/mholt/caddy/middleware/extensionless"
	"github.com/mholt/caddy/middleware/fastcgi"
	"github.com/mholt/caddy/middleware/gzip"
	"github.com/mholt/caddy/middleware/headers"
	"github.com/mholt/caddy/middleware/log"
	"github.com/mholt/caddy/middleware/markdown"
	"github.com/mholt/caddy/middleware/proxy"
	"github.com/mholt/caddy/middleware/redirect"
	"github.com/mholt/caddy/middleware/rewrite"
	"github.com/mholt/caddy/middleware/websockets"
)

// This init function registers middleware. Register
// middleware in the order they should be executed
// during a request (A, B, C...). Middleware execute
// in the order A-B-C-*-C-B-A, assuming they call
// the Next handler in the chain.
//
// Note: Ordering is VERY important. Every middleware
// will feel the effects of all other middleware below
// (after) them, but must not care what middleware above
// them are doing.
//
// For example, log needs to know the status code and exactly
// how many bytes were written to the client, which every
// other middleware can affect, so it gets registered first.
// The errors middleware does not care if gzip or log modifies
// its response, so it gets registered below them. Gzip, on the
// other hand, DOES care what errors does to the response since
// it must compress every output to the client, even error pages,
// so it must be registered before the errors middleware and any
// others that would write to the response.
func init() {
	register("log", log.New)
	register("gzip", gzip.New)
	register("errors", errors.New)
	register("header", headers.New)
	register("rewrite", rewrite.New)
	register("redirect", redirect.New)
	register("ext", extensionless.New)
	register("proxy", proxy.New)
	register("fastcgi", fastcgi.New)
	register("websocket", websockets.New)
	register("markdown", markdown.New)
	register("browse", browse.New)
}

// registry stores the registered middleware:
// both the order and the directives to which they
// are bound.
var registry = struct {
	directiveMap map[string]middleware.Generator
	ordered      []string
}{
	directiveMap: make(map[string]middleware.Generator),
}

// register binds a middleware generator (outer function)
// to a directive. Upon each request, middleware will be
{'fraction_non_alphanumeric': 0.12234706616729088, 'fraction_numerical': 0.0, 'mean_word_length': 4.533149171270718, 'pattern_counts': {'":': 0, '<': 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': '1029191', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1265, 'n_words': 354}