~emersion/public-inbox

kimchi: Support Hijack, Flush when using access logs v1 APPLIED

delthas: 1
 Support Hijack, Flush when using access logs

 1 files changed, 20 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/public-inbox/patches/39767/mbox | git am -3
Learn more about email & git

[PATCH kimchi] Support Hijack, Flush when using access logs Export this patch

This fixes the following error when using WebSockets with access logs
enabled:
    http: proxy error: can't switch protocols using non-Hijacker ResponseWriter type *main.interceptRW

We also add a Hijack method for upcoming (Go 1.20) ResponseController
support.
---
 interceptor.go | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/interceptor.go b/interceptor.go
index 6e2fdbb..17aa1ad 100644
--- a/interceptor.go
+++ b/interceptor.go
@@ -1,6 +1,9 @@
package main

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

@@ -10,6 +13,23 @@ type interceptRW struct {
	size   int
}

func (w *interceptRW) Unwrap() http.ResponseWriter {
	return w.ResponseWriter
}

func (w *interceptRW) Flush() {
	if f, ok := w.ResponseWriter.(http.Flusher); ok {
		f.Flush()
	}
}

func (w *interceptRW) Hijack() (net.Conn, *bufio.ReadWriter, error) {
	if h, ok := w.ResponseWriter.(http.Hijacker); ok {
		return h.Hijack()
	}
	return nil, nil, fmt.Errorf("connection does not support hijacking")
}

func (w *interceptRW) WriteHeader(status int) {
	w.status = status
	w.ResponseWriter.WriteHeader(status)

base-commit: b5c6ce57dba6a7a4b37a7baba7bb1b21c4debe69
-- 
2.39.1
Pushed with two minor edits:

- Fix typo in commit message: s/Hijack/Unwrap/
- Add _ vars to ensure the interfaces are properly implemented

Thanks!