ing
This commit is contained in:
parent
10cadfc5b5
commit
f22f37a6dc
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
// Codec creates a CodecRequest to process each request.
|
||||
type Codec interface {
|
||||
NewRequest(rc io.Reader) CodecRequest
|
||||
NewRequest(rc io.Reader) (CodecRequest, error)
|
||||
}
|
||||
|
||||
// CodecRequest decodes a request and encodes a response using a specific
|
||||
|
|
|
@ -72,7 +72,7 @@ type Codec struct {
|
|||
}
|
||||
|
||||
// NewRequest returns a CodecRequest.
|
||||
func (c *Codec) NewRequest(r io.Reader) protocol.CodecRequest {
|
||||
func (c *Codec) NewRequest(r io.Reader) (protocol.CodecRequest, error) {
|
||||
return newCodecRequest(r, c.encSel.Select(r))
|
||||
}
|
||||
|
||||
|
@ -81,12 +81,13 @@ func (c *Codec) NewRequest(r io.Reader) protocol.CodecRequest {
|
|||
// ----------------------------------------------------------------------------
|
||||
|
||||
// newCodecRequest returns a new CodecRequest.
|
||||
func newCodecRequest(r io.Reader, encoder encode.Encoder) protocol.CodecRequest {
|
||||
func newCodecRequest(r io.Reader, encoder encode.Encoder) (protocol.CodecRequest, error) {
|
||||
// Decode the request body and check if RPC method is valid.
|
||||
req := new(serverRequest)
|
||||
err := json.NewDecoder(r).Decode(req)
|
||||
if err == io.ErrUnexpectedEOF || err == io.EOF {
|
||||
log.Printf("NewRequest err: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
if err != nil {
|
||||
err = &Error{
|
||||
|
@ -103,7 +104,7 @@ func newCodecRequest(r io.Reader, encoder encode.Encoder) protocol.CodecRequest
|
|||
}
|
||||
}
|
||||
|
||||
return &CodecRequest{request: req, err: err, encoder: encoder}
|
||||
return &CodecRequest{request: req, err: err, encoder: encoder}, nil
|
||||
}
|
||||
|
||||
// CodecRequest decodes and encodes a single request.
|
||||
|
|
|
@ -101,7 +101,10 @@ func (rr *rpcRegistry) Invoke(contentType string, r io.Reader, w io.Writer, befo
|
|||
|
||||
log.Print("codec.NewRequest")
|
||||
// Create a new codec request.
|
||||
codecReq := codec.NewRequest(r)
|
||||
codecReq, errNew := codec.NewRequest(r)
|
||||
if nil != errNew {
|
||||
return errNew
|
||||
}
|
||||
// Get service method to be called.
|
||||
log.Printf("codecReq.Method: %v", codecReq)
|
||||
method, errMethod := codecReq.Method()
|
||||
|
|
Loading…
Reference in New Issue
Block a user