Skip to content

Commit 5cdd483

Browse files
committed
metadata.FromContext => metadata.FromOutgoingContext
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
1 parent 01b5e1d commit 5cdd483

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

http.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,18 @@ func newRequest(addr string, req client.Request, ct string, cf codec.Codec, msg
9898
return nil, errors.BadRequest("go.micro.client", err.Error())
9999
}
100100

101-
// marshal request is struct not empty
102-
if nmsg != nil {
103-
var b []byte
101+
var b []byte
102+
103+
if ct == "x-www-form-urlencoded" {
104+
fmt.Printf("XXXXX %#+v\n", nmsg)
105+
} else if nmsg != nil {
104106
b, err = cf.Marshal(nmsg)
105107
if err != nil {
106108
return nil, errors.BadRequest("go.micro.client", err.Error())
107109
}
110+
}
111+
112+
if len(b) > 0 {
108113
hreq.Body = ioutil.NopCloser(bytes.NewBuffer(b))
109114
hreq.ContentLength = int64(len(b))
110115
}
@@ -114,7 +119,7 @@ func newRequest(addr string, req client.Request, ct string, cf codec.Codec, msg
114119

115120
func (h *httpClient) call(ctx context.Context, addr string, req client.Request, rsp interface{}, opts client.CallOptions) error {
116121
header := make(http.Header, 2)
117-
if md, ok := metadata.FromContext(ctx); ok {
122+
if md, ok := metadata.FromOutgoingContext(ctx); ok {
118123
for k, v := range md {
119124
header.Set(k, v)
120125
}
@@ -127,8 +132,16 @@ func (h *httpClient) call(ctx context.Context, addr string, req client.Request,
127132
// set the content type for the request
128133
header.Set("Content-Type", ct)
129134

135+
var cf codec.Codec
136+
var err error
130137
// get codec
131-
cf, err := h.newCodec(ct)
138+
switch ct {
139+
case "x-www-form-urlencoded":
140+
cf, err = h.newCodec(DefaultContentType)
141+
default:
142+
cf, err = h.newCodec(ct)
143+
}
144+
132145
if err != nil {
133146
return errors.InternalServerError("go.micro.client", err.Error())
134147
}
@@ -164,7 +177,7 @@ func (h *httpClient) call(ctx context.Context, addr string, req client.Request,
164177
func (h *httpClient) stream(ctx context.Context, addr string, req client.Request, opts client.CallOptions) (client.Stream, error) {
165178
var header http.Header
166179

167-
if md, ok := metadata.FromContext(ctx); ok {
180+
if md, ok := metadata.FromOutgoingContext(ctx); ok {
168181
header = make(http.Header, len(md)+2)
169182
for k, v := range md {
170183
header.Set(k, v)
@@ -255,8 +268,8 @@ func (h *httpClient) NewMessage(topic string, msg interface{}, opts ...client.Me
255268
return newHTTPMessage(topic, msg, h.opts.ContentType, opts...)
256269
}
257270

258-
func (h *httpClient) NewRequest(service, method string, req interface{}, reqOpts ...client.RequestOption) client.Request {
259-
return newHTTPRequest(service, method, req, h.opts.ContentType, reqOpts...)
271+
func (h *httpClient) NewRequest(service, method string, req interface{}, opts ...client.RequestOption) client.Request {
272+
return newHTTPRequest(service, method, req, h.opts.ContentType, opts...)
260273
}
261274

262275
func (h *httpClient) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
@@ -525,7 +538,7 @@ func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...cli
525538
func (h *httpClient) Publish(ctx context.Context, p client.Message, opts ...client.PublishOption) error {
526539
options := client.NewPublishOptions(opts...)
527540

528-
md, ok := metadata.FromContext(ctx)
541+
md, ok := metadata.FromOutgoingContext(ctx)
529542
if !ok {
530543
md = metadata.New(2)
531544
}

0 commit comments

Comments
 (0)