1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
12 "git.arvados.org/arvados.git/sdk/go/ctxlog"
15 func (sshconn ContainerSSHConnection) ServeHTTP(w http.ResponseWriter, req *http.Request) {
16 hj, ok := w.(http.Hijacker)
18 http.Error(w, "ResponseWriter does not support connection upgrade", http.StatusInternalServerError)
21 w.Header().Set("Connection", "upgrade")
22 w.Header().Set("Upgrade", "ssh")
23 w.WriteHeader(http.StatusSwitchingProtocols)
24 conn, bufrw, err := hj.Hijack()
26 ctxlog.FromContext(req.Context()).WithError(err).Error("error hijacking ResponseWriter")
31 ctx, cancel := context.WithCancel(context.Background())
34 _, err := io.CopyN(conn, sshconn.Bufrw, int64(sshconn.Bufrw.Reader.Buffered()))
36 _, err = io.Copy(conn, sshconn.Conn)
39 ctxlog.FromContext(req.Context()).WithError(err).Error("error copying downstream")
44 _, err := io.CopyN(sshconn.Conn, bufrw, int64(bufrw.Reader.Buffered()))
46 _, err = io.Copy(sshconn.Conn, conn)
49 ctxlog.FromContext(req.Context()).WithError(err).Error("error copying upstream")