Nitpick Headers to Header
This commit is contained in:
parent
cd9801891e
commit
d306559d8f
@ -105,17 +105,17 @@ func newRpcPlusCodec(req *transport.Message, client transport.Client, c codec.Ne
|
|||||||
func (c *rpcPlusCodec) WriteRequest(req *request, body interface{}) error {
|
func (c *rpcPlusCodec) WriteRequest(req *request, body interface{}) error {
|
||||||
c.buf.wbuf.Reset()
|
c.buf.wbuf.Reset()
|
||||||
m := &codec.Message{
|
m := &codec.Message{
|
||||||
Id: req.Seq,
|
Id: req.Seq,
|
||||||
Target: req.Service,
|
Target: req.Service,
|
||||||
Method: req.ServiceMethod,
|
Method: req.ServiceMethod,
|
||||||
Type: codec.Request,
|
Type: codec.Request,
|
||||||
Headers: map[string]string{},
|
Header: map[string]string{},
|
||||||
}
|
}
|
||||||
if err := c.codec.Write(m, body); err != nil {
|
if err := c.codec.Write(m, body); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.req.Body = c.buf.wbuf.Bytes()
|
c.req.Body = c.buf.wbuf.Bytes()
|
||||||
for k, v := range m.Headers {
|
for k, v := range m.Header {
|
||||||
c.req.Header[k] = v
|
c.req.Header[k] = v
|
||||||
}
|
}
|
||||||
return c.client.Send(c.req)
|
return c.client.Send(c.req)
|
||||||
|
@ -33,10 +33,10 @@ type Codec interface {
|
|||||||
// the communication, likely followed by the body.
|
// the communication, likely followed by the body.
|
||||||
// In the case of an error, body may be nil.
|
// In the case of an error, body may be nil.
|
||||||
type Message struct {
|
type Message struct {
|
||||||
Id uint64
|
Id uint64
|
||||||
Type MessageType
|
Type MessageType
|
||||||
Target string
|
Target string
|
||||||
Method string
|
Method string
|
||||||
Error string
|
Error string
|
||||||
Headers map[string]string
|
Header map[string]string
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ func newRpcPlusCodec(req *transport.Message, socket transport.Socket, c codec.Ne
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *rpcPlusCodec) ReadRequestHeader(r *request, first bool) error {
|
func (c *rpcPlusCodec) ReadRequestHeader(r *request, first bool) error {
|
||||||
m := codec.Message{Headers: c.req.Header}
|
m := codec.Message{Header: c.req.Header}
|
||||||
|
|
||||||
if !first {
|
if !first {
|
||||||
var tm transport.Message
|
var tm transport.Message
|
||||||
@ -73,7 +73,7 @@ func (c *rpcPlusCodec) ReadRequestHeader(r *request, first bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Headers = tm.Header
|
m.Header = tm.Header
|
||||||
}
|
}
|
||||||
|
|
||||||
err := c.codec.ReadHeader(&m, codec.Request)
|
err := c.codec.ReadHeader(&m, codec.Request)
|
||||||
@ -89,19 +89,19 @@ func (c *rpcPlusCodec) ReadRequestBody(b interface{}) error {
|
|||||||
func (c *rpcPlusCodec) WriteResponse(r *response, body interface{}, last bool) error {
|
func (c *rpcPlusCodec) WriteResponse(r *response, body interface{}, last bool) error {
|
||||||
c.buf.wbuf.Reset()
|
c.buf.wbuf.Reset()
|
||||||
m := &codec.Message{
|
m := &codec.Message{
|
||||||
Method: r.ServiceMethod,
|
Method: r.ServiceMethod,
|
||||||
Id: r.Seq,
|
Id: r.Seq,
|
||||||
Error: r.Error,
|
Error: r.Error,
|
||||||
Type: codec.Response,
|
Type: codec.Response,
|
||||||
Headers: map[string]string{},
|
Header: map[string]string{},
|
||||||
}
|
}
|
||||||
if err := c.codec.Write(m, body); err != nil {
|
if err := c.codec.Write(m, body); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Headers["Content-Type"] = c.req.Header["Content-Type"]
|
m.Header["Content-Type"] = c.req.Header["Content-Type"]
|
||||||
return c.socket.Send(&transport.Message{
|
return c.socket.Send(&transport.Message{
|
||||||
Header: m.Headers,
|
Header: m.Header,
|
||||||
Body: c.buf.wbuf.Bytes(),
|
Body: c.buf.wbuf.Bytes(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user