source_file
comment "// Copyright 2015 Matthew Holt and The Caddy Authors"
comment "//"
comment "// Licensed under the Apache License, Version 2.0 (the \"Lice"...
comment "// you may not use this file except in compliance with the L"...
comment "// You may obtain a copy of the License at"
comment "//"
comment "// http://www.apache.org/licenses/LICENSE-2.0"
comment "//"
comment "// Unless required by applicable law or agreed to in writing"...
comment "// distributed under the License is distributed on an \"AS IS"...
comment "// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expr"...
comment "// See the License for the specific language governing permi"...
comment "// limitations under the License."
package_clause
package "package"
package_identifier "httpcaddyfile"
import_declaration (+80 nodes collapsed)
function_declaration (+42 nodes collapsed)
comment "// App represents the configuration for a non-standard"
comment "// Caddy app module (e.g. third-party plugin) which was"
comment "// parsed from a global options block."
type_declaration
type "type"
type_spec
type_identifier "App"
struct_type
struct "struct"
field_declaration_list
{ "{"
comment "// The JSON key for the app being configured"
field_declaration
field_identifier "Name"
type_identifier "string"
comment "// The raw app config as JSON"
field_declaration
field_identifier "Value"
qualified_type
package_identifier "json"
. "."
type_identifier "RawMessage"
} "}"
comment "// ServerType can set up a config from an HTTP Caddyfile."
type_declaration
type "type"
type_spec
type_identifier "ServerType"
struct_type
struct "struct"
field_declaration_list
{ "{"
} "}"
comment "// Setup makes a config from the tokens."
method_declaration
func "func"
parameter_list
( "("
parameter_declaration
identifier "st"
type_identifier "ServerType"
) ")"
field_identifier "Setup"
parameter_list (+22 nodes collapsed)
parameter_list (+22 nodes collapsed)
block
{ "{"
statement_list
var_declaration
var "var"
var_spec
identifier "warnings"
slice_type
[ "["
] "]"
qualified_type
package_identifier "caddyconfig"
. "."
type_identifier "Warning"
short_var_declaration
expression_list
identifier "gc"
:= ":="
expression_list
composite_literal
type_identifier "counter"
literal_value
{ "{"
literal_element
call_expression
identifier "new"
argument_list
( "("
type_identifier "int"
) ")"
} "}"
short_var_declaration
expression_list
identifier "state"
:= ":="
expression_list
call_expression
identifier "make"
argument_list
( "("
map_type
map "map"
[ "["
type_identifier "string"
] "]"
type_identifier "any"
) ")"
comment "// load all the server blocks and associate them with a \"pil"...
short_var_declaration (+23 nodes collapsed)
for_statement (+122 nodes collapsed)
comment "// apply any global options"
var_declaration
var "var"
var_spec
identifier "err"
type_identifier "error"
assignment_statement
expression_list
identifier "originalServerBlocks"
, ","
identifier "err"
= "="
expression_list
call_expression
selector_expression
identifier "st"
. "."
field_identifier "evaluateGlobalOptionsBlock"
argument_list
( "("
identifier "originalServerBlocks"
, ","
identifier "options"
) ")"
if_statement
if "if"
binary_expression
identifier "err"
!= "!="
nil "nil"
block
{ "{"
statement_list
return_statement
return "return"
expression_list
nil "nil"
, ","
identifier "warnings"
, ","
identifier "err"
} "}"
assignment_statement (+22 nodes collapsed)
if_statement
if "if"
binary_expression
identifier "err"
!= "!="
nil "nil"
block
{ "{"
statement_list
return_statement
return "return"
expression_list
nil "nil"
, ","
identifier "warnings"
, ","
identifier "err"
} "}"
comment "// replace shorthand placeholders (which are convenient"
comment "// when writing a Caddyfile) with their actual placeholder"
comment "// identifiers or variable names"
short_var_declaration
expression_list
identifier "replacer"
:= ":="
expression_list
call_expression
selector_expression
identifier "strings"
. "."
field_identifier "NewReplacer"
argument_list
( "("
variadic_argument
call_expression
identifier "placeholderShorthands"
argument_list
( "("
) ")"
... "..."
) ")"
comment "// these are placeholders that allow a user-defined final"
comment "// parameters, but we still want to provide a shorthand"
comment "// for those, so we use a regexp to replace"
short_var_declaration (+292 nodes collapsed)
for_statement (+746 nodes collapsed)
comment "// map"
short_var_declaration
expression_list
identifier "sbmap"
, ","
identifier "err"
:= ":="
expression_list
call_expression
selector_expression
identifier "st"
. "."
field_identifier "mapAddressToServerBlocks"
argument_list
( "("
identifier "originalServerBlocks"
, ","
identifier "options"
) ")"
if_statement
if "if"
binary_expression
identifier "err"
!= "!="
nil "nil"
block
{ "{"
statement_list
return_statement
return "return"
expression_list
nil "nil"
, ","
identifier "warnings"
, ","
identifier "err"
} "}"
comment "// reduce"
short_var_declaration
expression_list
identifier "pairings"
:= ":="
expression_list
call_expression
selector_expression
identifier "st"
. "."
field_identifier "consolidateAddrMappings"
argument_list
( "("
identifier "sbmap"
) ")"
comment "// each pairing of listener addresses to list of server"
comment "// blocks is basically a server definition"
short_var_declaration (+24 nodes collapsed)
if_statement
if "if"
binary_expression
identifier "err"
!= "!="
nil "nil"
block
{ "{"
statement_list
return_statement
return "return"
expression_list
nil "nil"
, ","
identifier "warnings"
, ","
identifier "err"
} "}"
comment "// now that each server is configured, make the HTTP app"
short_var_declaration (+112 nodes collapsed)
comment "// then make the TLS app"
short_var_declaration (+22 nodes collapsed)
if_statement
if "if"
binary_expression
identifier "err"
!= "!="
nil "nil"
block
{ "{"
statement_list
return_statement
return "return"
expression_list
nil "nil"
, ","
identifier "warnings"
, ","
identifier "err"
} "}"
comment "// then make the PKI app"
short_var_declaration (+22 nodes collapsed)
if_statement
if "if"
binary_expression
identifier "err"
!= "!="
nil "nil"
block
{ "{"
statement_list
return_statement
return "return"
expression_list
nil "nil"
, ","
identifier "warnings"
, ","
identifier "err"
} "}"
comment "// extract any custom logs, and enforce configured levels"
var_declaration
var "var"
var_spec
identifier "customLogs"
slice_type
[ "["
] "]"
type_identifier "namedCustomLog"
var_declaration
var "var"
var_spec
identifier "hasDefaultLog"
type_identifier "bool"
short_var_declaration (+137 nodes collapsed)
comment "// Apply global log options, when set"
if_statement (+61 nodes collapsed)
if_statement (+107 nodes collapsed)
comment "// Apply server-specific log options"
for_statement (+70 nodes collapsed)
comment "// annnd the top-level config, then we're done!"
short_var_declaration (+29 nodes collapsed)
comment "// loop through the configured options, and if any of"
comment "// them are an httpcaddyfile App, then we insert them"
comment "// into the config as raw Caddy apps"
for_statement (+54 nodes collapsed)
comment "// insert the standard Caddy apps into the config"
if_statement (+46 nodes collapsed)
if_statement (+70 nodes collapsed)
if_statement (+77 nodes collapsed)
if_statement (+84 nodes collapsed)
if_statement (+48 nodes collapsed)
if_statement (+123 nodes collapsed)
if_statement
if "if"
binary_expression
call_expression
identifier "len"
argument_list
( "("
identifier "customLogs"
) ")"
> ">"
int_literal "0"
block
{ "{"
statement_list
if_statement (+53 nodes collapsed)
comment "// Add the default log first if defined, so that it doesn't"
comment "// accidentally get re-created below due to the Exclude logi"...
for_statement (+63 nodes collapsed)
comment "// Add the rest of the custom logs"
for_statement
for "for"
range_clause
expression_list
identifier "_"
, ","
identifier "ncl"
:= ":="
range "range"
identifier "customLogs"
block
{ "{"
statement_list
if_statement (+27 nodes collapsed)
if_statement (+37 nodes collapsed)
comment "// most users seem to prefer not writing access logs"
comment "// to the default log when they are directed to a"
comment "// file or have any other special customization"
if_statement
if "if"
binary_expression (+27 nodes collapsed)
block
{ "{"
statement_list
short_var_declaration (+21 nodes collapsed)
if_statement (+42 nodes collapsed)
assignment_statement (+27 nodes collapsed)
comment "// avoid duplicates by sorting + compacting"
expression_statement
type_conversion_expression
generic_type
qualified_type
package_identifier "slices"
. "."
type_identifier "Sort"
type_arguments
[ "["
type_elem
type_identifier "string"
] "]"
( "("
selector_expression
identifier "defaultLog"
. "."
field_identifier "Exclude"
) ")"
assignment_statement (+31 nodes collapsed)
} "}"
} "}"
comment "// we may have not actually added anything, so remove if emp"...
if_statement (+30 nodes collapsed)
} "}"
return_statement
return "return"
expression_list
identifier "cfg"
, ","
identifier "warnings"
, ","
nil "nil"
} "}"
comment "// evaluateGlobalOptionsBlock evaluates the global options b"...
comment "// which is expected to be the first server block if it has "...
comment "// keys. It returns the updated list of server blocks with t"...
comment "// global options block removed, and updates options accordi"...
method_declaration (+692 nodes collapsed)
comment "// extractNamedRoutes pulls out any named route server block"...
comment "// so they don't get parsed as sites, and stores them in opt"...
comment "// for later."
method_declaration (+584 nodes collapsed)
comment "// serversFromPairings creates the servers for each pairing "...
comment "// to server blocks. Each pairing is essentially a server de"...
method_declaration (+3033 nodes collapsed)
function_declaration (+581 nodes collapsed)
comment "// consolidateConnPolicies sorts any catch-all policy to the"...
comment "// policies, and combines equivalent ones for a cleaner over"...
function_declaration (+1713 nodes collapsed)
comment "// appendSubrouteToRouteList appends the routes in subroute"
comment "// to the routeList, optionally qualified by matchers."
function_declaration (+418 nodes collapsed)
comment "// buildSubroute turns the config values, which are expected"...
comment "// into a clean and orderly subroute that has all the routes"...
function_declaration (+585 nodes collapsed)
comment "// normalizeDirectiveName ensures directives that should be "...
comment "// at the same level are named the same before sorting happe"...
function_declaration (+44 nodes collapsed)
comment "// consolidateRoutes combines routes with the same propertie"...
comment "// (same matchers, same Terminal and Group settings) for a"
comment "// cleaner overall output."
function_declaration (+208 nodes collapsed)
function_declaration (+240 nodes collapsed)
method_declaration (+650 nodes collapsed)
function_declaration (+604 nodes collapsed)
function_declaration (+123 nodes collapsed)
comment "// placeholderShorthands returns a slice of old-new string p"...
comment "// where the left of the pair is a placeholder shorthand tha"...
comment "// be used in the Caddyfile, and the right is the replacemen"...
function_declaration (+301 nodes collapsed)
comment "// WasReplacedPlaceholderShorthand checks if a token string "...
comment "// likely a replaced shorthand of the known Caddyfile placeh"...
comment "// replacement outputs. Useful to prevent some user-defined "...
comment "// output destinations from overlapping with one of the"
comment "// predefined shorthands."
function_declaration (+110 nodes collapsed)
comment "// tryInt tries to convert val to an integer. If it fails,"
comment "// it downgrades the error to a warning and returns 0."
function_declaration (+97 nodes collapsed)
function_declaration (+97 nodes collapsed)
function_declaration (+103 nodes collapsed)
comment "// sliceContains returns true if needle is in haystack."
function_declaration (+53 nodes collapsed)
comment "// listenersUseAnyPortOtherThan returns true if there are an"...
comment "// listeners in addresses that use a port which is not other"...
comment "// Mostly borrowed from unexported method in caddyhttp packa"...
function_declaration (+133 nodes collapsed)
comment "// specificity returns len(s) minus any wildcards (*) and"
comment "// placeholders ({...}). Basically, it's a length count"
comment "// that penalizes the use of wildcards and placeholders."
comment "// This is useful for comparing hostnames and paths."
comment "// However, wildcards in paths are not a sure answer to"
comment "// the question of specificity. For example,"
comment "// '*.example.com' is clearly less specific than"
comment "// 'a.example.com', but is '/a' more or less specific"
comment "// than '/a*'?"
function_declaration (+157 nodes collapsed)
type_declaration
type "type"
type_spec
type_identifier "counter"
struct_type
struct "struct"
field_declaration_list
{ "{"
field_declaration
field_identifier "n"
pointer_type
* "*"
type_identifier "int"
} "}"
method_declaration (+53 nodes collapsed)
type_declaration (+26 nodes collapsed)
comment "// sbAddrAssociation is a mapping from a list of"
comment "// addresses to a list of server blocks that are"
comment "// served on those addresses."
type_declaration (+21 nodes collapsed)
const_declaration
const "const"
const_spec
identifier "matcherPrefix"
= "="
expression_list
interpreted_string_literal
" "\""
interpreted_string_literal_content "@"
" "\""
const_declaration
const "const"
const_spec
identifier "namedRouteKey"
= "="
expression_list
interpreted_string_literal
" "\""
interpreted_string_literal_content "named_route"
" "\""
comment "// Interface guard"
var_declaration (+21 nodes collapsed)