Skip to content

Commit

Permalink
Case insensitive host comparison (#565)
Browse files Browse the repository at this point in the history
* Add case-insensitive URL block in the example

* Make a case-insensitive comparation inside DstHostIs
  • Loading branch information
ErikPelli authored Dec 17, 2024
1 parent da3cdee commit f31a87f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ proxy.OnResponse(Some RespConditions).Do(YourRespHandlerFunc())
For example:

```go
// This rejects the HTTPS request to *.reddit.com during HTTP CONNECT phase
proxy.OnRequest(goproxy.ReqHostMatches(regexp.MustCompile("reddit.*:443$"))).HandleConnect(goproxy.AlwaysReject)
// This rejects the HTTPS request to *.reddit.com during HTTP CONNECT phase.
// Reddit URL check is case-insensitive, so the block will work also if the user types something like rEdDit.com.
proxy.OnRequest(goproxy.ReqHostMatches(regexp.MustCompile("(?i)reddit.*:443$"))).HandleConnect(goproxy.AlwaysReject)

// This will NOT reject the HTTPS request with URL ending with gif, due to the fact that proxy
// only got the URL.Hostname and URL.Port during the HTTP CONNECT phase if the scheme is HTTPS, which is
Expand Down
3 changes: 2 additions & 1 deletion dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ func UrlMatches(re *regexp.Regexp) ReqConditionFunc {

// DstHostIs returns a ReqCondition testing wether the host in the request url is the given string
func DstHostIs(host string) ReqConditionFunc {
host = strings.ToLower(host)
return func(req *http.Request, ctx *ProxyCtx) bool {
return req.URL.Host == host
return strings.ToLower(req.URL.Host) == host
}
}

Expand Down

0 comments on commit f31a87f

Please sign in to comment.