diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-09-18 09:46:41 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-18 09:46:41 -0400 |
commit | 5b7509c562e040ab8ed17990299c0b6eb52cecee (patch) | |
tree | 0390fdb1f00c65f2a52b72eec062b55873e35ab5 /pkg | |
parent | fc3daaef83b666b83cdc4578723bbfbe8b6f2b05 (diff) | |
parent | e1ac8d9aa22e11c223691f66331e6832c145996d (diff) | |
download | podman-5b7509c562e040ab8ed17990299c0b6eb52cecee.tar.gz podman-5b7509c562e040ab8ed17990299c0b6eb52cecee.tar.bz2 podman-5b7509c562e040ab8ed17990299c0b6eb52cecee.zip |
Merge pull request #7660 from ashley-cui/logs
Fix remote logs
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/api/handlers/compat/containers_logs.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/pkg/api/handlers/compat/containers_logs.go b/pkg/api/handlers/compat/containers_logs.go index f6d4a518e..d24b7d959 100644 --- a/pkg/api/handlers/compat/containers_logs.go +++ b/pkg/api/handlers/compat/containers_logs.go @@ -105,6 +105,18 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) { var frame strings.Builder header := make([]byte, 8) + + writeHeader := true + // Docker does not write stream headers iff the container has a tty. + if !utils.IsLibpodRequest(r) { + inspectData, err := ctnr.Inspect(false) + if err != nil { + utils.InternalServerError(w, errors.Wrapf(err, "Failed to obtain logs for Container '%s'", name)) + return + } + writeHeader = !inspectData.Config.Tty + } + for line := range logChannel { if _, found := r.URL.Query()["until"]; found { if line.Time.After(until) { @@ -138,10 +150,13 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) { } frame.WriteString(line.Msg) - binary.BigEndian.PutUint32(header[4:], uint32(frame.Len())) - if _, err := w.Write(header[0:8]); err != nil { - log.Errorf("unable to write log output header: %q", err) + if writeHeader { + binary.BigEndian.PutUint32(header[4:], uint32(frame.Len())) + if _, err := w.Write(header[0:8]); err != nil { + log.Errorf("unable to write log output header: %q", err) + } } + if _, err := io.WriteString(w, frame.String()); err != nil { log.Errorf("unable to write frame string: %q", err) } |