set headers as appropriate
This commit is contained in:
parent
3043841cf5
commit
36788487a7
@ -132,12 +132,26 @@ func (c *rpcCodec) Write(r *codec.Message, b interface{}) error {
|
||||
Id: r.Id,
|
||||
Error: r.Error,
|
||||
Type: r.Type,
|
||||
Header: map[string]string{
|
||||
"X-Micro-Id": r.Id,
|
||||
"X-Micro-Endpoint": r.Endpoint,
|
||||
"X-Micro-Error": r.Error,
|
||||
"Content-Type": c.req.Header["Content-Type"],
|
||||
},
|
||||
Header: map[string]string{},
|
||||
}
|
||||
|
||||
// set request id
|
||||
if len(r.Id) > 0 {
|
||||
m.Header["X-Micro-Id"] = r.Id
|
||||
}
|
||||
|
||||
// set target
|
||||
if len(r.Target) > 0 {
|
||||
m.Header["X-Micro-Service"] = r.Target
|
||||
}
|
||||
|
||||
// set request endpoint
|
||||
if len(r.Endpoint) > 0 {
|
||||
m.Header["X-Micro-Endpoint"] = r.Endpoint
|
||||
}
|
||||
|
||||
if len(r.Error) > 0 {
|
||||
m.Header["X-Micro-Error"] = r.Error
|
||||
}
|
||||
|
||||
// the body being sent
|
||||
@ -163,6 +177,11 @@ func (c *rpcCodec) Write(r *codec.Message, b interface{}) error {
|
||||
body = c.buf.wbuf.Bytes()
|
||||
}
|
||||
|
||||
// Set content type if theres content
|
||||
if len(body) > 0 {
|
||||
m.Header["Content-Type"] = c.req.Header["Content-Type"]
|
||||
}
|
||||
|
||||
// send on the socket
|
||||
return c.socket.Send(&transport.Message{
|
||||
Header: m.Header,
|
||||
|
@ -381,7 +381,7 @@ func (router *router) readHeader(cc codec.Reader) (service *service, mtype *meth
|
||||
|
||||
serviceMethod := strings.Split(req.msg.Endpoint, ".")
|
||||
if len(serviceMethod) != 2 {
|
||||
err = errors.New("rpc: service/method request ill-formed: " + req.msg.Endpoint)
|
||||
err = errors.New("rpc: service/endpoint request ill-formed: " + req.msg.Endpoint)
|
||||
return
|
||||
}
|
||||
// Look up the request.
|
||||
@ -389,12 +389,12 @@ func (router *router) readHeader(cc codec.Reader) (service *service, mtype *meth
|
||||
service = router.serviceMap[serviceMethod[0]]
|
||||
router.mu.Unlock()
|
||||
if service == nil {
|
||||
err = errors.New("rpc: can't find service " + req.msg.Endpoint)
|
||||
err = errors.New("rpc: can't find service " + serviceMethod[0])
|
||||
return
|
||||
}
|
||||
mtype = service.method[serviceMethod[1]]
|
||||
if mtype == nil {
|
||||
err = errors.New("rpc: can't find method " + req.msg.Endpoint)
|
||||
err = errors.New("rpc: can't find method " + serviceMethod[1])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user