Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8b24a843b |
No files matched your search
+2453
-4
File diff suppressed because it is too large.
Load diff
File renamed without changes.
@@ -48,17 +48,7 @@ type RProxy struct {
|
|||||||
settings []slog.Attr
|
settings []slog.Attr
|
||||||
}
|
}
|
||||||
|
|
||||||
// defaultUpstreamURL is the default of SWRP_UPSTREAM_URL.
|
|
||||||
const defaultUpstreamURL = "http://127.0.0.1:8081"
|
|
||||||
|
|
||||||
// privateRanges are the private address ranges, the default trusted
|
|
||||||
// proxies.
|
|
||||||
const privateRanges = "10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errNotUpstreamURL = errors.New(
|
|
||||||
"is not a URL with only a scheme, a host and an optional port, " +
|
|
||||||
"such as http://127.0.0.1:8081")
|
|
||||||
errNeedsWAFBackend = errors.New(
|
errNeedsWAFBackend = errors.New(
|
||||||
"is required: it is waf's URL, such as http://waf:8080")
|
"is required: it is waf's URL, such as http://waf:8080")
|
||||||
errNotDisposition = errors.New("is not allow or deny")
|
errNotDisposition = errors.New("is not allow or deny")
|
||||||
@@ -152,14 +142,6 @@ func (c *RProxy) LogValue() slog.Value {
|
|||||||
return slog.GroupValue(c.settings...)
|
return slog.GroupValue(c.settings...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// appURL reads a setting that is the app's URL.
|
|
||||||
func (e *environment) appURL(name, defaultValue string) *url.URL {
|
|
||||||
upstream, err := parseUpstreamURL(e.value(name, defaultValue))
|
|
||||||
e.check(name, err)
|
|
||||||
|
|
||||||
return upstream
|
|
||||||
}
|
|
||||||
|
|
||||||
// wafBackend reads the setting that is waf's URL, which must be set.
|
// wafBackend reads the setting that is waf's URL, which must be set.
|
||||||
func (e *environment) wafBackend(name string) *url.URL {
|
func (e *environment) wafBackend(name string) *url.URL {
|
||||||
value := e.value(name, "")
|
value := e.value(name, "")
|
||||||
@@ -228,33 +210,3 @@ func parseMilliseconds(value string) (time.Duration, bool) {
|
|||||||
|
|
||||||
return time.Duration(n) * time.Millisecond, true
|
return time.Duration(n) * time.Millisecond, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseUpstreamURL reads the app's URL: http or https, a host and an
|
|
||||||
// optional port from 1 to 65535, and nothing else, since the request's
|
|
||||||
// own path and query go to the app unchanged.
|
|
||||||
func parseUpstreamURL(value string) (*url.URL, error) {
|
|
||||||
upstream, err := url.Parse(value)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("%q %w", value, errNotUpstreamURL)
|
|
||||||
}
|
|
||||||
|
|
||||||
onlySchemeAndHost := (upstream.Scheme == "http" || upstream.Scheme == "https") &&
|
|
||||||
upstream.Hostname() != "" &&
|
|
||||||
upstream.User == nil &&
|
|
||||||
upstream.Opaque == "" &&
|
|
||||||
(upstream.Path == "" || upstream.Path == "/") &&
|
|
||||||
upstream.RawQuery == "" &&
|
|
||||||
upstream.Fragment == ""
|
|
||||||
if !onlySchemeAndHost {
|
|
||||||
return nil, fmt.Errorf("%q %w", value, errNotUpstreamURL)
|
|
||||||
}
|
|
||||||
|
|
||||||
if upstream.Port() != "" {
|
|
||||||
port, err := strconv.ParseUint(upstream.Port(), 10, 16)
|
|
||||||
if err != nil || port == 0 {
|
|
||||||
return nil, fmt.Errorf("%q %w", value, errNotUpstreamURL)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return upstream, nil
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large.
Load diff
+2
-8
@@ -41,15 +41,9 @@ main() {
|
|||||||
golines="$(golines_path)"
|
golines="$(golines_path)"
|
||||||
gofmt -w cmd internal
|
gofmt -w cmd internal
|
||||||
# One golines pass can leave a line that the next pass splits
|
# One golines pass can leave a line that the next pass splits
|
||||||
# further, so run it until it would change nothing. The check is
|
# further, so run it until it would change nothing.
|
||||||
# not the while condition, where set -e would ignore a golines
|
|
||||||
# failure.
|
|
||||||
passes=0
|
passes=0
|
||||||
while true; do
|
while [ -n "$("$golines" -m 77 -l cmd internal)" ]; do
|
||||||
unformatted="$("$golines" -m 77 -l cmd internal)"
|
|
||||||
if [ -z "$unformatted" ]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
passes=$((passes + 1))
|
passes=$((passes + 1))
|
||||||
if [ "$passes" -gt 5 ]; then
|
if [ "$passes" -gt 5 ]; then
|
||||||
echo "fmt: golines -m 77 still changes files after 5 passes" >&2
|
echo "fmt: golines -m 77 still changes files after 5 passes" >&2
|
||||||
|
|||||||
Reference in new issue
Block a user