feat: some refactoring

This commit is contained in:
2025-11-22 22:23:49 +03:00
parent a247e6213e
commit 51f30b516e
29 changed files with 1094 additions and 129 deletions

View File

@@ -0,0 +1,44 @@
package http
import (
"bufio"
"errors"
"net"
"net/http"
"github.com/felixge/httpsnoop"
)
// Custom RW implementation
type ResponseWriter struct {
http.ResponseWriter
code int
Hijacker http.Hijacker
}
// Write status code to header
func (w *ResponseWriter) WriteHeader(statusCode int) {
w.code = statusCode
w.ResponseWriter.WriteHeader(statusCode)
}
// GetStatusCode returns the status code that was written
func (w *ResponseWriter) GetStatusCode() int {
return w.code
}
// Get new RW
func NewResponseWriter(w http.ResponseWriter) *ResponseWriter {
hijacker, _ := w.(http.Hijacker)
return &ResponseWriter{
ResponseWriter: httpsnoop.Wrap(w, httpsnoop.Hooks{}),
Hijacker: hijacker,
}
}
func (w *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if w.Hijacker == nil {
return nil, nil, errors.New("http.Hijacker not implemented by underlying http.ResponseWriter")
}
return w.Hijacker.Hijack()
}