good morning!!!!

Skip to content
Snippets Groups Projects
Verified Commit 6cd956fa authored by a's avatar a
Browse files

noot

parent 0c08abad
Branches
Tags
No related merge requests found
Pipeline #90652 passed
...@@ -4,9 +4,11 @@ import ( ...@@ -4,9 +4,11 @@ import (
"context" "context"
"encoding/base64" "encoding/base64"
"errors" "errors"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"runtime/debug"
"strings" "strings"
"gfx.cafe/open/jrpc/pkg/jsonrpc" "gfx.cafe/open/jrpc/pkg/jsonrpc"
...@@ -96,7 +98,7 @@ func NewPostCodec(w http.ResponseWriter, r *http.Request) (*HttpCodec, error) { ...@@ -96,7 +98,7 @@ func NewPostCodec(w http.ResponseWriter, r *http.Request) (*HttpCodec, error) {
} }
c.ctx, c.cn = context.WithCancel(r.Context()) c.ctx, c.cn = context.WithCancel(r.Context())
flusher, ok := w.(http.Flusher) flusher, ok := w.(http.Flusher)
if ok { if ok && flusher != nil {
c.f = flusher c.f = flusher
} }
...@@ -137,19 +139,33 @@ func (c *HttpCodec) Write(p []byte) (n int, err error) { ...@@ -137,19 +139,33 @@ func (c *HttpCodec) Write(p []byte) (n int, err error) {
} }
func (c *HttpCodec) Flush() error { func (c *HttpCodec) Flush() error {
c.w.Write([]byte{'\n'}) _, err := c.w.Write([]byte{'\n'})
if c.f != nil { if err != nil {
c.f.Flush() return err
} }
c._flush()
return nil return nil
} }
func (c *HttpCodec) Close() error { func (c *HttpCodec) Close() error {
select {
case <-c.ctx.Done():
default:
c._flush()
c.cn()
}
return nil
}
func (c *HttpCodec) _flush() {
defer func() {
if err := recover(); err != nil {
fmt.Println("err", err, "stack: \n"+string(debug.Stack()))
}
}()
if c.f != nil { if c.f != nil {
c.f.Flush() c.f.Flush()
} }
c.cn()
return nil
} }
// Closed returns a channel which is closed when the connection is closed. // Closed returns a channel which is closed when the connection is closed.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment