Skip to content

Commit

Permalink
Fix reading of txn.path on http-request keywords #102
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmoraisjr committed Mar 10, 2018
1 parent 74b53f8 commit ffa195d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
6 changes: 4 additions & 2 deletions pkg/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,14 @@ func (cfg *haConfig) newHAProxyLocations(server *ingress.Server) ([]*types.HAPro
haRootLocation = &haLocation
} else {
otherPaths = otherPaths + " " + location.Path
haLocation.HAMatchPath = " { var(txn.path) -m beg " + haLocation.Path + " }"
haLocation.HAMatchPath = " { path -m beg " + haLocation.Path + " }"
haLocation.HAMatchTxnPath = " { var(txn.path) -m beg " + haLocation.Path + " }"
}
haLocations[i] = &haLocation
}
if haRootLocation != nil && otherPaths != "" {
haRootLocation.HAMatchPath = " !{ var(txn.path) -m beg " + otherPaths + " }"
haRootLocation.HAMatchPath = " !{ path -m beg " + otherPaths + " }"
haRootLocation.HAMatchTxnPath = " !{ var(txn.path) -m beg " + otherPaths + " }"
}
return haLocations, haRootLocation
}
Expand Down
1 change: 1 addition & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ type (
Proxy proxy.Configuration `json:"proxy,omitempty"`
RateLimit ratelimit.RateLimit `json:"rateLimit,omitempty"`
HAMatchPath string `json:"haMatchPath"`
HAMatchTxnPath string `json:"haMatchTxnPath"`
HAWhitelist string `json:"whitelist,omitempty"`
HARateLimitWhiteList string `json:"rateLimitWhiteList,omitempty"`
}
Expand Down
28 changes: 14 additions & 14 deletions rootfs/etc/haproxy/template/haproxy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,25 @@ frontend httpfront-{{ $host }}
option forwardfor if-none
{{- end }}

{{- range $location := $server.Locations }}
{{- $rewriteTarget := $location.Rewrite.Target }}
{{- if ne $rewriteTarget "" }}
{{- if eq $rewriteTarget "/" }}
reqrep ^([^\ :]*)\ {{ $location.Path }}/?(.*$) \1\ {{ $rewriteTarget }}\2 if { var(txn.path) -m beg {{ $location.Path }} }
{{- else }}
reqrep ^([^\ :]*)\ {{ $location.Path }}(.*$) \1\ {{ $rewriteTarget }}{{ if hasSuffix $location.Path "/" }}/{{ end }}\2 if { var(txn.path) -m beg {{ $location.Path }} }
{{- end }}
{{- end }}
{{- end }}

{{- if $server.IsDefaultServer }}

{{- if $server.SSLRedirect }}
redirect scheme https if !from-https
{{- else }}
{{- range $location := $server.Locations }}
{{- if $location.Rewrite.SSLRedirect }}
redirect scheme https if{{ $location.HAMatchPath }} !from-https
redirect scheme https if{{ $location.HAMatchTxnPath }} !from-https
{{- end }}
{{- end }}
{{- end }}
Expand All @@ -352,7 +363,7 @@ frontend httpfront-{{ $host }}
{{- else }}
{{- range $location := $server.Locations }}
{{- if $location.Rewrite.SSLRedirect }}
redirect scheme https if{{ $location.HAMatchPath }} !from-https
redirect scheme https if{{ $location.HAMatchTxnPath }} !from-https
{{- end }}
{{- end }}
{{- end }}
Expand Down Expand Up @@ -385,17 +396,6 @@ frontend httpfront-{{ $host }}
{{- end }}
{{- end }}

{{- range $location := $server.Locations }}
{{- $rewriteTarget := $location.Rewrite.Target }}
{{- if ne $rewriteTarget "" }}
{{- if eq $rewriteTarget "/" }}
reqrep ^([^\ :]*)\ {{ $location.Path }}/?(.*$) \1\ {{ $rewriteTarget }}\2 if { var(txn.path) -m beg {{ $location.Path }} }
{{- else }}
reqrep ^([^\ :]*)\ {{ $location.Path }}(.*$) \1\ {{ $rewriteTarget }}{{ if hasSuffix $location.Path "/" }}/{{ end }}\2 if { var(txn.path) -m beg {{ $location.Path }} }
{{- end }}
{{- end }}
{{- end }}

{{- if $sslconn }}
{{- if $server.HSTS }}
{{- $hsts := $server.HSTS }}
Expand All @@ -406,7 +406,7 @@ frontend httpfront-{{ $host }}
{{- range $location := $server.Locations }}
{{- $hsts := $location.HSTS }}
{{- if $hsts.Enable }}
http-response set-header Strict-Transport-Security "max-age={{ $hsts.MaxAge }}{{ if $hsts.Subdomains }}; includeSubDomains{{ end }}{{ if $hsts.Preload }}; preload{{ end }}" if from-https{{ $location.HAMatchPath }}
http-response set-header Strict-Transport-Security "max-age={{ $hsts.MaxAge }}{{ if $hsts.Subdomains }}; includeSubDomains{{ end }}{{ if $hsts.Preload }}; preload{{ end }}" if from-https{{ $location.HAMatchTxnPath }}
{{- end }}
{{- end }}
{{- end }}
Expand Down

0 comments on commit ffa195d

Please sign in to comment.