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

WIP: enable route support for websocket connections #27806

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions modules/context/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package context

import (
"bufio"
"errors"
"net"
"net/http"

web_types "code.gitea.io/gitea/modules/web/types"
Expand All @@ -30,6 +33,14 @@ type Response struct {
status int
befores []func(ResponseWriter)
beforeExecuted bool
hijacker http.Hijacker
}

func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if r.hijacker == nil {
return nil, nil, errors.New("http.Hijacker not implemented by underlying http.ResponseWriter")
}
return r.hijacker.Hijack()
}

// Write writes bytes to HTTP endpoint
Expand Down Expand Up @@ -95,9 +106,11 @@ func WrapResponseWriter(resp http.ResponseWriter) *Response {
if v, ok := resp.(*Response); ok {
return v
}
hijacker, _ := resp.(http.Hijacker)
return &Response{
ResponseWriter: resp,
status: 0,
befores: make([]func(ResponseWriter), 0),
hijacker: hijacker,
}
}