MCPcopy
hub / github.com/labstack/echo / ProxyConfig

Struct ProxyConfig

middleware/proxy.go:29–90  ·  view source on GitHub ↗

TODO: Handle TLS proxy ProxyConfig defines the config for Proxy middleware.

Source from the content-addressed store, hash-verified

27
28// ProxyConfig defines the config for Proxy middleware.
29type ProxyConfig struct {
30 // Skipper defines a function to skip middleware.
31 Skipper Skipper
32
33 // Balancer defines a load balancing technique.
34 // Required.
35 Balancer ProxyBalancer
36
37 // RetryCount defines the number of times a failed proxied request should be retried
38 // using the next available ProxyTarget. Defaults to 0, meaning requests are never retried.
39 RetryCount int
40
41 // RetryFilter defines a function used to determine if a failed request to a
42 // ProxyTarget should be retried. The RetryFilter will only be called when the number
43 // of previous retries is less than RetryCount. If the function returns true, the
44 // request will be retried. The provided error indicates the reason for the request
45 // failure. When the ProxyTarget is unavailable, the error will be an instance of
46 // echo.HTTPError with a code of http.StatusBadGateway. In all other cases, the error
47 // will indicate an internal error in the Proxy middleware. When a RetryFilter is not
48 // specified, all requests that fail with http.StatusBadGateway will be retried. A custom
49 // RetryFilter can be provided to only retry specific requests. Note that RetryFilter is
50 // only called when the request to the target fails, or an internal error in the Proxy
51 // middleware has occurred. Successful requests that return a non-200 response code cannot
52 // be retried.
53 RetryFilter func(c *echo.Context, e error) bool
54
55 // ErrorHandler defines a function which can be used to return custom errors from
56 // the Proxy middleware. ErrorHandler is only invoked when there has been
57 // either an internal error in the Proxy middleware or the ProxyTarget is
58 // unavailable. Due to the way requests are proxied, ErrorHandler is not invoked
59 // when a ProxyTarget returns a non-200 response. In these cases, the response
60 // is already written so errors cannot be modified. ErrorHandler is only
61 // invoked after all retry attempts have been exhausted.
62 ErrorHandler func(c *echo.Context, err error) error
63
64 // Rewrite defines URL path rewrite rules. The values captured in asterisk can be
65 // retrieved by index e.g. $1, $2 and so on.
66 // Examples:
67 // "/old": "/new",
68 // "/api/*": "/$1",
69 // "/js/*": "/public/javascripts/$1",
70 // "/users/*/orders/*": "/user/$1/order/$2",
71 Rewrite map[string]string
72
73 // RegexRewrite defines rewrite rules using regexp.Rexexp with captures
74 // Every capture group in the values can be retrieved by index e.g. $1, $2 and so on.
75 // Example:
76 // "^/old/[0.9]+/": "/new",
77 // "^/api/.+?/(.*)": "/v2/$1",
78 RegexRewrite map[*regexp.Regexp]string
79
80 // Context key to store selected ProxyTarget into context.
81 // Optional. Default value "target".
82 ContextKey string
83
84 // To customize the transport to remote.
85 // Examples: If custom TLS certificates are required.
86 Transport http.RoundTripper

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected