MCPcopy Create free account
hub / github.com/PuerNya/git-proxy / requestLimitHandle

Function requestLimitHandle

main.go:548–569  ·  view source on GitHub ↗
(next http.Handler)

Source from the content-addressed store, hash-verified

546}
547
548func requestLimitHandle(next http.Handler) http.Handler {
549 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
550 if RequestLimiter == nil {
551 next.ServeHTTP(w, r)
552 return
553 }
554 ip := M.ParseSocksaddr(r.RemoteAddr).Addr.String()
555 access := RequestLimiter.GetAccess(ip)
556 if !access {
557 log.WarnContext(r.Context(), "Match request limit")
558 w.WriteHeader(http.StatusTooManyRequests)
559 if requestLimit == 1 {
560 w.Write([]byte("You can only initiate 1 request at the same time"))
561 } else {
562 w.Write([]byte(fmt.Sprint("You can only initiate ", requestLimit, " requests at the same time")))
563 }
564 return
565 }
566 next.ServeHTTP(w, r)
567 RequestLimiter.Leave(ip)
568 })
569}
570
571func finalHandle() http.Handler {
572 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 2

GetAccessMethod · 0.80
LeaveMethod · 0.80

Tested by

no test coverage detected