Skip to content

Commit

Permalink
Implement http.Hijacker for sessionResponseWriter for go1.19
Browse files Browse the repository at this point in the history
Fixes: alexedwards#188 for go1.18
  • Loading branch information
ryanlath committed Feb 19, 2024
1 parent a38e822 commit 54046a9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions session_go118.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build go1.18
// +build go1.18

package scs

import (
"bufio"
"net"
"net/http"
)

func (sw *sessionResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return sw.ResponseWriter.(http.Hijacker).Hijack()
}
36 changes: 36 additions & 0 deletions session_go118_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//go:build go1.18
// +build go1.18

package scs

import (
"fmt"
"net/http"
"testing"
"time"
)

func TestHijacker(t *testing.T) {
t.Parallel()

sessionManager := New()
sessionManager.Lifetime = 500 * time.Millisecond

mux := http.NewServeMux()

mux.HandleFunc("/get", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, ok := w.(http.Hijacker)

fmt.Fprint(w, ok)
}))

ts := newTestServer(t, sessionManager.LoadAndSave(mux))
defer ts.Close()

ts.execute(t, "/put")

_, body := ts.execute(t, "/get")
if body != "true" {
t.Errorf("want %q; got %q", "true", body)
}
}

0 comments on commit 54046a9

Please # to comment.