Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement http.Hijacker for sessionResponseWriter for go1.18 #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}