mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Remove dependency on httputil for client hijack test
Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
@@ -8,10 +8,10 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/server/httputils"
|
||||
"github.com/docker/docker/api/types"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
@@ -26,28 +26,33 @@ func TestTLSCloseWriter(t *testing.T) {
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
chErr = make(chan error, 1)
|
||||
defer close(chErr)
|
||||
if err := httputils.ParseForm(req); err != nil {
|
||||
|
||||
if err := req.ParseForm(); err != nil && !strings.HasPrefix(err.Error(), "mime:") {
|
||||
chErr <- fmt.Errorf("error parsing form: %w", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
r, rw, err := httputils.HijackConnection(w)
|
||||
|
||||
conn, _, err := w.(http.Hijacker).Hijack()
|
||||
if err != nil {
|
||||
chErr <- fmt.Errorf("error hijacking connection: %w", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer r.Close()
|
||||
defer conn.Close()
|
||||
|
||||
fmt.Fprint(rw, "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\n")
|
||||
// Flush the options to make sure the client sets the raw mode
|
||||
_, _ = conn.Write([]byte{})
|
||||
|
||||
fmt.Fprint(conn, "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\n")
|
||||
|
||||
buf := make([]byte, 5)
|
||||
_, err = r.Read(buf)
|
||||
_, err = conn.Read(buf)
|
||||
if err != nil {
|
||||
chErr <- fmt.Errorf("error reading from client: %w", err)
|
||||
return
|
||||
}
|
||||
_, err = rw.Write(buf)
|
||||
_, err = conn.Write(buf)
|
||||
if err != nil {
|
||||
chErr <- fmt.Errorf("error writing to client: %w", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user