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,
|
Id: r.Id,
|
||||||
Error: r.Error,
|
Error: r.Error,
|
||||||
Type: r.Type,
|
Type: r.Type,
|
||||||
Header: map[string]string{
|
Header: map[string]string{},
|
||||||
"X-Micro-Id": r.Id,
|
}
|
||||||
"X-Micro-Endpoint": r.Endpoint,
|
|
||||||
"X-Micro-Error": r.Error,
|
// set request id
|
||||||
"Content-Type": c.req.Header["Content-Type"],
|
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
|
// the body being sent
|
||||||
@ -163,6 +177,11 @@ func (c *rpcCodec) Write(r *codec.Message, b interface{}) error {
|
|||||||
body = c.buf.wbuf.Bytes()
|
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
|
// send on the socket
|
||||||
return c.socket.Send(&transport.Message{
|
return c.socket.Send(&transport.Message{
|
||||||
Header: m.Header,
|
Header: m.Header,
|
||||||
|
@ -381,7 +381,7 @@ func (router *router) readHeader(cc codec.Reader) (service *service, mtype *meth
|
|||||||
|
|
||||||
serviceMethod := strings.Split(req.msg.Endpoint, ".")
|
serviceMethod := strings.Split(req.msg.Endpoint, ".")
|
||||||
if len(serviceMethod) != 2 {
|
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
|
return
|
||||||
}
|
}
|
||||||
// Look up the request.
|
// Look up the request.
|
||||||
@ -389,12 +389,12 @@ func (router *router) readHeader(cc codec.Reader) (service *service, mtype *meth
|
|||||||
service = router.serviceMap[serviceMethod[0]]
|
service = router.serviceMap[serviceMethod[0]]
|
||||||
router.mu.Unlock()
|
router.mu.Unlock()
|
||||||
if service == nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
mtype = service.method[serviceMethod[1]]
|
mtype = service.method[serviceMethod[1]]
|
||||||
if mtype == nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user