mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-10-08 16:31:20 +02:00
added API Sender test variables
Signed-off-by: RonniSkansing <rskansing@gmail.com>
This commit is contained in:
6 files changed
+384
-32
No files matched your search
@@ -83,6 +83,26 @@ func (c *Common) handleGlobalAuthorization(
|
||||
func (c *Common) handleParseRequest(
|
||||
g *gin.Context,
|
||||
req any,
|
||||
) bool {
|
||||
return c.parseRequest(g, req, false)
|
||||
}
|
||||
|
||||
// handleParseOptionalRequest parses a request body like handleParseRequest but
|
||||
// treats an empty body as no input, leaving req at its zero value. Use it for
|
||||
// endpoints where every field is optional.
|
||||
func (c *Common) handleParseOptionalRequest(
|
||||
g *gin.Context,
|
||||
req any,
|
||||
) bool {
|
||||
return c.parseRequest(g, req, true)
|
||||
}
|
||||
|
||||
// parseRequest reads and unmarshals the request body. When allowEmpty is true an
|
||||
// empty body is accepted and leaves req untouched.
|
||||
func (c *Common) parseRequest(
|
||||
g *gin.Context,
|
||||
req any,
|
||||
allowEmpty bool,
|
||||
) bool {
|
||||
body, err := io.ReadAll(g.Request.Body)
|
||||
if err != nil {
|
||||
@@ -92,6 +112,9 @@ func (c *Common) handleParseRequest(
|
||||
c.Response.BadRequest(g)
|
||||
return false
|
||||
}
|
||||
if allowEmpty && len(bytes.TrimSpace(body)) == 0 {
|
||||
return true
|
||||
}
|
||||
if err := utils.Unmarshal(body, &req); err != nil {
|
||||
c.Logger.Debugw("failed to parse request",
|
||||
"error", err,
|
||||
|
||||
Reference in new issue
Block a user