Skip to content

Commit

Permalink
Merge pull request #49 from sashamelentyev/feat/redirect-handler
Browse files Browse the repository at this point in the history
feat: add check status code in http.RedirectHandler
  • Loading branch information
sashamelentyev committed Aug 15, 2022
2 parents 7c6dfe6 + 407243e commit 40aae56
Show file tree
Hide file tree
Showing 3 changed files with 517 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/analyzer/analyzer.go
Expand Up @@ -116,6 +116,15 @@ func run(pass *analysis.Pass) (interface{}, error) {
if basicLit := getBasicLitFromArgs(n.Args, 4, 3, token.INT); basicLit != nil {
checkHTTPStatusCode(pass, basicLit)
}

case "RedirectHandler":
if !lookupFlag(pass, HTTPStatusCodeFlag) {
return
}

if basicLit := getBasicLitFromArgs(n.Args, 2, 1, token.INT); basicLit != nil {
checkHTTPStatusCode(pass, basicLit)
}
}
default:
if selectorExpr.Sel.Name == "WriteHeader" {
Expand Down
12 changes: 12 additions & 0 deletions pkg/analyzer/internal/template/test-httpstatuscode.go.tmpl
Expand Up @@ -114,3 +114,15 @@ func _() {
http.Redirect(w, r, "", {{ $value }})
}
{{ end -}}

{{ range $key, $value := .Mapping }}
func _() {
http.RedirectHandler("", {{ $key }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
}
{{ end -}}

{{ range $key, $value := .Mapping }}
func _() {
http.RedirectHandler("", {{ $value }})
}
{{ end -}}

0 comments on commit 40aae56

Please sign in to comment.