allow to set content type with charset
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
9
http.go
9
http.go
@@ -11,6 +11,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/broker"
|
"github.com/unistack-org/micro/v3/broker"
|
||||||
@@ -147,9 +148,9 @@ func (h *httpClient) call(ctx context.Context, addr string, req client.Request,
|
|||||||
// get codec
|
// get codec
|
||||||
switch ct {
|
switch ct {
|
||||||
case "application/x-www-form-urlencoded":
|
case "application/x-www-form-urlencoded":
|
||||||
cf, err = h.newCodec(DefaultContentType)
|
cf, err = h.newCodec(strings.Split(DefaultContentType, ";")[0])
|
||||||
default:
|
default:
|
||||||
cf, err = h.newCodec(ct)
|
cf, err = h.newCodec(strings.Split(ct, ";")[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -207,7 +208,7 @@ func (h *httpClient) stream(ctx context.Context, addr string, req client.Request
|
|||||||
header.Set("Content-Type", ct)
|
header.Set("Content-Type", ct)
|
||||||
|
|
||||||
// get codec
|
// get codec
|
||||||
cf, err := h.newCodec(req.ContentType())
|
cf, err := h.newCodec(strings.Split(req.ContentType(), ";")[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
||||||
}
|
}
|
||||||
@@ -559,7 +560,7 @@ func (h *httpClient) Publish(ctx context.Context, p client.Message, opts ...clie
|
|||||||
md["Content-Type"] = p.ContentType()
|
md["Content-Type"] = p.ContentType()
|
||||||
md["Micro-Topic"] = p.Topic()
|
md["Micro-Topic"] = p.Topic()
|
||||||
|
|
||||||
cf, err := h.newCodec(p.ContentType())
|
cf, err := h.newCodec(strings.Split(p.ContentType(), ";")[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.InternalServerError("go.micro.client", err.Error())
|
return errors.InternalServerError("go.micro.client", err.Error())
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,6 @@ type httpRequest struct {
|
|||||||
|
|
||||||
func newHTTPRequest(service, method string, request interface{}, contentType string, opts ...client.RequestOption) client.Request {
|
func newHTTPRequest(service, method string, request interface{}, contentType string, opts ...client.RequestOption) client.Request {
|
||||||
options := client.NewRequestOptions(opts...)
|
options := client.NewRequestOptions(opts...)
|
||||||
|
|
||||||
if len(options.ContentType) == 0 {
|
if len(options.ContentType) == 0 {
|
||||||
options.ContentType = contentType
|
options.ContentType = contentType
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user