What is going wrong here? I am 100% sure I am sending a HTTP POST request, but somehow the OR operator is not working as I am expecting. In the first example the server returns a 405 and in the second example the code continues executing.
not working:
if req.Method != http.MethodPost || req.Method != http.MethodDelete {
http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
return
}
working:
if req.Method != http.MethodPost {
http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
return
}
(Not something) OR (not something else mutually exclusive) is always going to be true isn't it?
If it is method post, it will not be delete and vice versa , you might want && ?
Like Kenny Grant said, you might want to ponder about the logic. Perhaps this is what you meant:
// only allow POST or DELETE
if req.Method != http.MethodPost && req.Method != http.MethodDelete {
http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
return
}