Return error 400 if mandatory param is missing in HTTP request
This commit is contained in:
parent
af21b300ea
commit
283946aa22
|
|
@ -51,6 +51,7 @@ GET /auth?jid=user%40host%2fresource&domain=example.org&method=POST&transaction_
|
|||
|
||||
This will send a request to the given JID, then return HTTP code depending on what appended.
|
||||
* 200 : User accept the request
|
||||
* 400 : One or more mandatory parameter(s) is missing
|
||||
* 401 : User deny the request
|
||||
* 504 : User do not provide an answer (timeout)
|
||||
* 520 : Unknown error append
|
||||
|
|
|
|||
11
http/http.go
11
http/http.go
|
|
@ -53,10 +53,17 @@ func authHandler(w http.ResponseWriter, r *http.Request) {
|
|||
jid := strings.Join(r.Form[PARAM_JID], "")
|
||||
method := strings.Join(r.Form[METHOD_ACCESS], "")
|
||||
domain := strings.Join(r.Form[DOMAIN_ACCESS], "")
|
||||
|
||||
if jid == "" || method == "" || domain == "" {
|
||||
// If mandatory params is missing
|
||||
log.Printf("%sMandatory params is missing", LogInfo)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
transaction := strings.Join(r.Form[TRANSACTION_ID], "")
|
||||
timeoutStr := strings.Join(r.Form[TIMEOUTE], "")
|
||||
log.Printf("%sAuth %s", LogDebug, jid)
|
||||
|
||||
log.Printf("%sAuth %s", LogInfo, jid)
|
||||
timeout, err := strconv.Atoi(timeoutStr)
|
||||
if err != nil || timeout <= 0 {
|
||||
timeout = TimeoutSec
|
||||
|
|
|
|||
4
main.go
4
main.go
|
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
Version = "v0.2"
|
||||
Version = "v0.3"
|
||||
configurationFilePath = "httpAuth.cfg"
|
||||
|
||||
default_xmpp_server_address = "127.0.0.1"
|
||||
|
|
@ -27,6 +27,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
log.Printf("Running HTTP-Auth %v", Version)
|
||||
|
||||
err := cfg.Load(configurationFilePath, mapConfig)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to load configuration file.", err)
|
||||
|
|
|
|||
Loading…
Reference in New Issue