22 lines
568 B
Go
22 lines
568 B
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"go-socket/packages/globals"
|
|
)
|
|
|
|
func postValidCheckWithResponseOnFail(response *http.ResponseWriter, request *http.Request, withFile bool) bool {
|
|
if request.Method != http.MethodPost {
|
|
http.Error(*response, "POST only", http.StatusMethodNotAllowed)
|
|
return false
|
|
}
|
|
if withFile && request.ContentLength > int64(globals.MaxPostWithFileBytes) ||
|
|
!withFile && request.ContentLength > int64(globals.MaxPostBytes) {
|
|
http.Error(*response, "Request too large", http.StatusRequestEntityTooLarge)
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|