1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-12 22:07:47 +02:00

set headers as appropriate

This commit is contained in:
Asim Aslam
2019-01-11 13:44:47 +00:00
parent 3043841cf5
commit 36788487a7
2 changed files with 28 additions and 9 deletions

View File

@ -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,