aboutsummaryrefslogtreecommitdiff
path: root/pkg/api
diff options
context:
space:
mode:
authorEd Santiago <santiago@redhat.com>2020-02-11 15:13:03 -0700
committerEd Santiago <santiago@redhat.com>2020-02-11 15:15:20 -0700
commitba30bb8409c20f370dfc3c5ad1351e62a523706d (patch)
treee4d93ab864b444a48cf1ba273efddddb6a2a547f /pkg/api
parent4bdfeed5bf9c467c8ab53b392747ec722505b179 (diff)
downloadpodman-ba30bb8409c20f370dfc3c5ad1351e62a523706d.tar.gz
podman-ba30bb8409c20f370dfc3c5ad1351e62a523706d.tar.bz2
podman-ba30bb8409c20f370dfc3c5ad1351e62a523706d.zip
HTTP 304 (NotModified) is not an error!
Even after #5169, my test logs kept showing: ERRO[0004] unable to write json: "http: request method or response status code does not allow body" Cause: overly-helpful code trying to treat condition as an error and include a diagnostic message. This is forbidden per rfc2616. This PR fixes the faulty response, as well as three others found via: $ ack 'Error.*NotMod' (4 hits total) $ ack 'Error.*NoCont' (no hits) Signed-off-by: Ed Santiago <santiago@redhat.com>
Diffstat (limited to 'pkg/api')
-rw-r--r--pkg/api/handlers/containers.go8
-rw-r--r--pkg/api/handlers/libpod/pods.go6
2 files changed, 5 insertions, 9 deletions
diff --git a/pkg/api/handlers/containers.go b/pkg/api/handlers/containers.go
index f180fbc2b..d7d040ce2 100644
--- a/pkg/api/handlers/containers.go
+++ b/pkg/api/handlers/containers.go
@@ -41,10 +41,9 @@ func StopContainer(w http.ResponseWriter, r *http.Request) {
utils.InternalServerError(w, errors.Wrapf(err, "unable to get state for Container %s", name))
return
}
- // If the Container is stopped already, send a 302
+ // If the Container is stopped already, send a 304
if state == define.ContainerStateStopped || state == define.ContainerStateExited {
- utils.Error(w, http.StatusText(http.StatusNotModified), http.StatusNotModified,
- errors.Errorf("Container %s is already stopped ", name))
+ utils.WriteResponse(w, http.StatusNotModified, "")
return
}
@@ -134,8 +133,7 @@ func StartContainer(w http.ResponseWriter, r *http.Request) {
return
}
if state == define.ContainerStateRunning {
- msg := fmt.Sprintf("Container %s is already running", name)
- utils.Error(w, msg, http.StatusNotModified, errors.New(msg))
+ utils.WriteResponse(w, http.StatusNotModified, "")
return
}
if err := con.Start(r.Context(), false); err != nil {
diff --git a/pkg/api/handlers/libpod/pods.go b/pkg/api/handlers/libpod/pods.go
index 8fb305290..e9297d91b 100644
--- a/pkg/api/handlers/libpod/pods.go
+++ b/pkg/api/handlers/libpod/pods.go
@@ -202,8 +202,7 @@ func PodStop(w http.ResponseWriter, r *http.Request) {
}
}
if allContainersStopped {
- alreadyStopped := errors.Errorf("pod %s is already stopped", pod.ID())
- utils.Error(w, "Something went wrong", http.StatusNotModified, alreadyStopped)
+ utils.WriteResponse(w, http.StatusNotModified, "")
return
}
@@ -249,8 +248,7 @@ func PodStart(w http.ResponseWriter, r *http.Request) {
}
}
if allContainersRunning {
- alreadyRunning := errors.Errorf("pod %s is already running", pod.ID())
- utils.Error(w, "Something went wrong", http.StatusNotModified, alreadyRunning)
+ utils.WriteResponse(w, http.StatusNotModified, "")
return
}
if _, err := pod.Start(r.Context()); err != nil {