Skip to content

Commit

Permalink
Added debug information option (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkijkuit authored Oct 26, 2021
1 parent dd457e6 commit e4097ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Supported configurations per header
| contains | boolean | If set to true (default false), the request is allowed if the rtequest header value contains the value specified in the configuration |
| required | boolean | If set to false (default true), the request is allowed if the header is absent or the value is empty|
| urldecode | boolean | If set to true (default false), the value of the request header will be URL decoded before further processing with the plugin. This is useful when using this plugin with the [PassTLSClientCert](https://doc.traefik.io/traefik/middlewares/passtlsclientcert/) middleware that Traefik offers.
| debug | boolean | If set to true (default false), the request headers, values and validation will be printed to the console|

#
## Example 1 config
Expand Down
14 changes: 14 additions & 0 deletions header_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type SingleHeader struct {
Required *bool `json:"required,omitempty"`
Contains *bool `json:"contains,omitempty"`
URLDecode *bool `json:"urldecode,omitempty"`
Debug *bool `json:"debug,omitempty"`
}

// Config the plugin configuration.
Expand Down Expand Up @@ -99,6 +100,10 @@ func (a *HeaderMatch) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
headersValid = checkRequired(&reqHeaderVal, &vHeader)
}

if vHeader.IsDebug() {
fmt.Println("checkheaders (debug):\n\tHeaders valid:", headersValid, "\n\tRequest headers:", reqHeaderVal, "\n\tConfigured headers:", vHeader.Values)
}

if !headersValid {
break
}
Expand Down Expand Up @@ -156,6 +161,15 @@ func (s *SingleHeader) IsURLDecode() bool {
return true
}

//IsDebug checks whether a header value should print debug information in the log
func (s *SingleHeader) IsDebug() bool {
if s.Debug == nil || *s.Debug == false {
return false
}

return true
}

//IsContains checks whether a header value should contain the configured value
func (s *SingleHeader) IsContains() bool {
if s.Contains == nil || *s.Contains == false {
Expand Down

0 comments on commit e4097ff

Please sign in to comment.