mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-02-12 16:12:44 +00:00
extend request deadline for applicatoin update
Signed-off-by: Ronni Skansing <rskansing@gmail.com>
This commit is contained in:
@@ -480,7 +480,7 @@ func setupRoutes(
|
||||
GET(ROUTE_V1_VERSION, middleware.SessionHandler, controllers.Version.Get).
|
||||
// update
|
||||
GET(ROUTE_V1_UPDATE, middleware.SessionHandler, controllers.Update.GetUpdateDetails).
|
||||
POST(ROUTE_V1_UPDATE, middleware.SessionHandler, controllers.Update.RunUpdate).
|
||||
POST(ROUTE_V1_UPDATE, middleware.ExtendedTimeout(3*time.Minute), middleware.SessionHandler, controllers.Update.RunUpdate).
|
||||
// backup
|
||||
POST(ROUTE_V1_BACKUP_CREATE, middleware.SessionHandler, controllers.Backup.CreateBackup).
|
||||
GET(ROUTE_V1_BACKUP_LIST, middleware.SessionHandler, controllers.Backup.ListBackups).
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/phishingclub/phishingclub/config"
|
||||
"github.com/phishingclub/phishingclub/middleware"
|
||||
@@ -41,3 +43,8 @@ func NewMiddlewares(
|
||||
SessionHandler: sessionHandler,
|
||||
}
|
||||
}
|
||||
|
||||
// ExtendedTimeout returns a middleware that extends the write deadline for long-running operations.
|
||||
func (m *Middlewares) ExtendedTimeout(timeout time.Duration) gin.HandlerFunc {
|
||||
return middleware.ExtendedTimeout(timeout)
|
||||
}
|
||||
|
||||
23
backend/middleware/timeout.go
Normal file
23
backend/middleware/timeout.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// ExtendedTimeout creates a middleware that extends the write deadline for long-running operations.
|
||||
// this is necessary because the server's default WriteTimeout may be too short for operations
|
||||
// like downloading updates.
|
||||
func ExtendedTimeout(timeout time.Duration) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// get the underlying connection and extend the write deadline
|
||||
rc := http.NewResponseController(c.Writer)
|
||||
if err := rc.SetWriteDeadline(time.Now().Add(timeout)); err != nil {
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
@@ -306,7 +306,7 @@ func (u *Update) RunUpdate(
|
||||
req.Header.Set("User-Agent", "PhishingClub-Client")
|
||||
|
||||
client := &http.Client{
|
||||
Timeout: 60 * time.Second, // Longer timeout for downloads
|
||||
Timeout: 3 * time.Minute, // extended timeout for downloads
|
||||
}
|
||||
|
||||
if !build.Flags.Production {
|
||||
|
||||
Reference in New Issue
Block a user