summaryrefslogtreecommitdiff
path: root/libpod/util.go
diff options
context:
space:
mode:
authorEd Santiago <santiago@redhat.com>2020-08-27 12:57:33 -0600
committerGitHub <noreply@github.com>2020-08-27 12:57:33 -0600
commitb13af4537fea0647c029067c664f1e79e0a6c3e6 (patch)
tree98163cb6467b5742ed73e2dbbc8be77b884fbce2 /libpod/util.go
parent7d3cadcc54cbad9a109471f586c10541544bc7db (diff)
parent2ea9dac5e1d00b2820bd7156e3bea4b9fd98c1e6 (diff)
downloadpodman-b13af4537fea0647c029067c664f1e79e0a6c3e6.tar.gz
podman-b13af4537fea0647c029067c664f1e79e0a6c3e6.tar.bz2
podman-b13af4537fea0647c029067c664f1e79e0a6c3e6.zip
Merge pull request #7451 from mheon/fix_7195
Send HTTP Hijack headers after successful attach
Diffstat (limited to 'libpod/util.go')
-rw-r--r--libpod/util.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/libpod/util.go b/libpod/util.go
index c93ba7919..585b07aca 100644
--- a/libpod/util.go
+++ b/libpod/util.go
@@ -5,6 +5,7 @@ import (
"encoding/binary"
"fmt"
"io"
+ "net/http"
"os"
"os/exec"
"path/filepath"
@@ -257,6 +258,27 @@ func makeHTTPAttachHeader(stream byte, length uint32) []byte {
return header
}
+// writeHijackHeader writes a header appropriate for the type of HTTP Hijack
+// that occurred in a hijacked HTTP connection used for attach.
+func writeHijackHeader(r *http.Request, conn io.Writer) {
+ // AttachHeader is the literal header sent for upgraded/hijacked connections for
+ // attach, sourced from Docker at:
+ // https://raw.githubusercontent.com/moby/moby/b95fad8e51bd064be4f4e58a996924f343846c85/api/server/router/container/container_routes.go
+ // Using literally to ensure compatibility with existing clients.
+ c := r.Header.Get("Connection")
+ proto := r.Header.Get("Upgrade")
+ if len(proto) == 0 || !strings.EqualFold(c, "Upgrade") {
+ // OK - can't upgrade if not requested or protocol is not specified
+ fmt.Fprintf(conn,
+ "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n")
+ } else {
+ // Upraded
+ fmt.Fprintf(conn,
+ "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: %s\r\n\r\n",
+ proto)
+ }
+}
+
// Convert OCICNI port bindings into Inspect-formatted port bindings.
func makeInspectPortBindings(bindings []ocicni.PortMapping) map[string][]define.InspectHostPort {
portBindings := make(map[string][]define.InspectHostPort)