Skip to content

Commit

Permalink
feat: request size logging
Browse files Browse the repository at this point in the history
  • Loading branch information
d-led committed Nov 20, 2024
1 parent d5eb01c commit 1ca22fb
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (s *Server) setupRoutes() {

func (s *Server) checkURLs(c *gin.Context) {
infrastructure.GlobalStats().OnIncomingRequest()
request, abort := s.parseURLCheckRequestOrAbort(c)
request, abort := s.parseURLCheckRequestOrAbort(c, false)
if abort {
return
}
Expand Down Expand Up @@ -217,7 +217,7 @@ func (s *Server) checkURLsStream(c *gin.Context) {
infrastructure.GlobalStats().OnIncomingRequest()
infrastructure.GlobalStats().OnIncomingStreamRequest()

request, abort := s.parseURLCheckRequestOrAbort(c)
request, abort := s.parseURLCheckRequestOrAbort(c, true)
if abort {
return
}
Expand Down Expand Up @@ -254,17 +254,19 @@ func (s *Server) checkURLsStream(c *gin.Context) {
})
}

func (s *Server) parseURLCheckRequestOrAbort(c *gin.Context) (CheckURLsRequest, bool) {
func (s *Server) parseURLCheckRequestOrAbort(c *gin.Context, stream bool) (CheckURLsRequest, bool) {
var request CheckURLsRequest
err := c.BindJSON(&request)
if err != nil {
c.String(http.StatusBadRequest, "Could not parse json: %v", err.Error())
return CheckURLsRequest{}, true
}
count := len(request.Urls)
if count > largeRequestLoggingThreshold {
log.Info().Msgf("Large request: %v urls", count)
}
log.Info().
Int("count", count).
Bool("large", count > largeRequestLoggingThreshold).
Bool("stream", stream).
Msg("Link check request")

if s.options.MaxURLsInRequest != 0 && uint(count) > s.options.MaxURLsInRequest {
c.String(http.StatusRequestEntityTooLarge, "Number of URLs in request limit exceeded")
Expand Down

0 comments on commit 1ca22fb

Please sign in to comment.