Skip to content

Commit

Permalink
fix bot detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Jul 7, 2023
1 parent 029f7bd commit a68be36
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:

- run: go run github.com/ysmood/golangci-lint@latest

- run: go test -coverprofile=coverage.out ./...
- run: go test ./...
2 changes: 1 addition & 1 deletion service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func New(addr, target string) *Bartender {
}

func (b *Bartender) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet && r.Header.Get("Accept-Language") != "" {
if r.Method == http.MethodGet && r.Header.Get("Accept-Language") == "" {
b.RenderPage(w, r)

return
Expand Down
6 changes: 4 additions & 2 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ func TestBasic(t *testing.T) {
proxy.Mux.HandleFunc("/", bt.ServeHTTP)

{
res := g.Req("", proxy.URL("/test?q=ok"))
// browser
res := g.Req("", proxy.URL("/test?q=ok"), http.Header{"Accept-Language": {"en"}})
g.Has(res.String(), "<body></body>")
}

{
res := g.Req("", proxy.URL("/test?q=ok"), http.Header{"Accept-Language": {"en"}})
// web crawler
res := g.Req("", proxy.URL("/test?q=ok"))
g.Has(res.String(), "/test?q=ok")
}
}

0 comments on commit a68be36

Please sign in to comment.