good morning!!!!

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

a

parent 9dfe16e1
No related branches found
No related tags found
No related merge requests found
Pipeline #60434 passed
......@@ -37,11 +37,6 @@ func NewCodec(w http.ResponseWriter, r *http.Request) (jsonrpc.ReaderWriter, err
return NewGetCodec(w, r), nil
case http.MethodPost:
return NewPostCodec(w, r)
case "JRPC":
if r.Header.Get("Accept") == "text/event-stream" || r.URL.Query().Has("sse") {
return NewSseCodec(w, r)
}
return NewJrpcCodec(w, r)
default:
http.Error(w, "method not supported", http.StatusMethodNotAllowed)
return nil, errors.New("method not allowed")
......@@ -128,44 +123,6 @@ func NewPostCodec(w http.ResponseWriter, r *http.Request) (*HttpCodec, error) {
return c, nil
}
func NewJrpcCodec(w http.ResponseWriter, r *http.Request) (*HttpCodec, error) {
c := &HttpCodec{
r: r,
w: w,
i: jsonrpc.PeerInfo{
Transport: "http",
RemoteAddr: r.RemoteAddr,
HTTP: r.Clone(r.Context()),
},
}
c.ctx, c.cn = context.WithCancel(r.Context())
flusher, ok := w.(http.Flusher)
if ok {
c.f = flusher
}
data, err := io.ReadAll(r.Body)
if err != nil {
return nil, err
}
method := strings.TrimPrefix(r.URL.Path, "/")
id := r.Header.Get("Jrpc-Request-Id")
if id == "" {
id = "none"
}
c.msgs = &serverutil.Bundle{
Messages: []*jsonrpc.Message{{
ID: jsonrpc.NewId(id),
Method: method,
Params: data,
}},
Batch: false,
}
return c, nil
}
// gets the peer info
func (c *HttpCodec) PeerInfo() jsonrpc.PeerInfo {
return c.i
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment