MCPcopy Create free account
hub / github.com/apache/dubbo-go / ReadHeader

Method ReadHeader

protocol/jsonrpc/json.go:288–317  ·  view source on GitHub ↗

ReadHeader reads header and unmarshal to server codec

(header map[string]string, body []byte)

Source from the content-addressed store, hash-verified

286
287// ReadHeader reads header and unmarshal to server codec
288func (c *ServerCodec) ReadHeader(header map[string]string, body []byte) error {
289 if header["HttpMethod"] != "POST" {
290 return &Error{Code: -32601, Message: "Method not found"}
291 }
292
293 // If return error:
294 // - codec will be closed
295 // So, try to send error reply to client before returning error.
296
297 buf := bytes.NewBuffer(body)
298 defer buf.Reset()
299 dec := json.NewDecoder(buf)
300
301 var raw json.RawMessage
302 c.req.reset()
303 if err := dec.Decode(&raw); err != nil {
304 // rspError := &Error{Code: -32700, Message: "Parse error"}
305 // c.resp = serverResponse{Version: Version, ID: &null, Error: rspError}
306 return err
307 }
308 if err := json.Unmarshal(raw, &c.req); err != nil {
309 // if err.Error() == "bad request" {
310 // rspError := &Error{Code: -32600, Message: "Invalid request"}
311 // c.resp = serverResponse{Version: Version, ID: &null, Error: rspError}
312 // }
313 return err
314 }
315
316 return nil
317}
318
319// ReadBody reads @x as request body.
320func (c *ServerCodec) ReadBody(x any) error {

Callers 2

serveRequestFunction · 0.45
TestServerCodecReadFunction · 0.45

Calls 4

ResetMethod · 0.65
DecodeMethod · 0.65
UnmarshalMethod · 0.65
resetMethod · 0.45

Tested by 1

TestServerCodecReadFunction · 0.36