Skip to content

Commit

Permalink
Merge pull request #4 from tarosky/issue/3
Browse files Browse the repository at this point in the history
Return error on invalid IP address
Close #3.
  • Loading branch information
harai authored Apr 3, 2022
2 parents d8f1a96 + 39189ca commit d56df0e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 429.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ func (e *environment) respondWithTooManyRequests(
c.Writer.Flush()
}

func (e *environment) respondWithBadRequest(c *gin.Context, path string) {
e.log.Debug("response",
zap.Int("status", http.StatusBadRequest),
zap.String("path", path))
c.String(http.StatusBadRequest, "")
c.Writer.Flush()
}

func (e *environment) respondWithInternalServerError(
c *gin.Context,
ip, masked net.IP,
Expand Down Expand Up @@ -434,6 +442,10 @@ func (e *environment) trim(series []int64) []int64 {
}

func (e *environment) handleRequest(c *gin.Context, ip net.IP, path string) {
if ip == nil {
e.respondWithBadRequest(c, path)
return
}
masked := e.maskIP(ip)
key := masked.String()
now := time.Now().Unix()
Expand Down

0 comments on commit d56df0e

Please sign in to comment.