Fix response for empty topic/queue by responding with HTTP 204 No Content instead of 404 Not Found (Fixes #25)
Этот коммит содержится в:
родитель
a5ef82800e
Коммит
929cfd3a36
|
@ -93,7 +93,8 @@ func (c *Client) Pull(topic string) (msg *msgbus.Message, err error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if res.StatusCode == http.StatusNotFound {
|
||||
// XXX: StatusNotFound is for backwards compatibility only for older clients.
|
||||
if res.StatusCode == http.StatusNoContent || res.StatusCode == http.StatusNotFound {
|
||||
// Empty queue
|
||||
return nil, nil
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
|||
module git.mills.io/prologic/msgbus
|
||||
|
||||
go 1.17
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
|
|
|
@ -567,8 +567,7 @@ func (mb *MessageBus) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
message, ok := mb.Get(t)
|
||||
|
||||
if !ok {
|
||||
msg := fmt.Sprintf("no messages enqueued for topic: %s", topic)
|
||||
http.Error(w, msg, http.StatusNotFound)
|
||||
http.Error(w, "No Messages", http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ func TestServeHTTPGETEmptyQueue(t *testing.T) {
|
|||
r, _ := http.NewRequest("GET", "/hello", nil)
|
||||
|
||||
mb.ServeHTTP(w, r)
|
||||
assert.Equal(w.Code, http.StatusNotFound)
|
||||
assert.Equal(w.Code, http.StatusNoContent)
|
||||
}
|
||||
|
||||
func TestServeHTTPPOST(t *testing.T) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче