1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-01-05 10:20:53 +02:00

fix 404 bug (#2179)

This commit is contained in:
qm012 2021-06-16 14:56:41 +08:00 committed by GitHub
parent b892efa25f
commit 4deeaff8ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 13 deletions

View File

@ -56,6 +56,8 @@ github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/asim/go-micro v1.18.0 h1:k/qyLA5R175Vr1Owf90Ms1+J/zhBf/aa8aiHGhk0x5s=
github.com/asim/go-micro/plugins/registry/memory/v3 v3.0.0-20210202145831-070250155285 h1:zgDzypD412DKHoXIXW1JwIOWoGcjxzI1iF6JmwtyqHw=
github.com/asim/go-micro/plugins/registry/memory/v3 v3.0.0-20210202145831-070250155285/go.mod h1:AU0vyZvsO1lpuQr/DUG4CnNRvITXqQcJRRAzBATR6Jo=
github.com/asim/go-micro/v3 v2.9.1 h1:+S9koIrNWARjpP6k2TZ7kt0uC9zUJtNXzIdZTZRms7Q=
github.com/asim/go-micro/v3 v2.9.1/go.mod h1:x55ZM3Puy0FyvvkR3e0ha0xsE9DFwfPSUMWAIbFY0SY=
github.com/asim/go-micro/v3 v3.0.0-20210120135431-d94936f6c97c h1:pxZggDV2VJ7aTR7/7xzAJOGam0y8zzrtBgmop1pHAyA=

View File

@ -11,18 +11,19 @@ import (
"net/http"
"net/url"
"os"
"strings"
"sync"
"time"
"github.com/asim/go-micro/v3/broker"
"github.com/asim/go-micro/v3/client"
"github.com/asim/go-micro/v3/selector"
"github.com/asim/go-micro/v3/cmd"
"github.com/asim/go-micro/v3/codec"
raw "github.com/asim/go-micro/v3/codec/bytes"
"github.com/asim/go-micro/v3/cmd"
errors "github.com/asim/go-micro/v3/errors"
"github.com/asim/go-micro/v3/metadata"
"github.com/asim/go-micro/v3/registry"
"github.com/asim/go-micro/v3/selector"
"github.com/asim/go-micro/v3/transport"
)
@ -106,13 +107,22 @@ func (h *httpClient) call(ctx context.Context, node *registry.Node, req client.R
buf := &buffer{bytes.NewBuffer(b)}
defer buf.Close()
// start with / or not
endpoint := req.Endpoint()
if !strings.HasPrefix(endpoint, "/") {
endpoint = "/" + endpoint
}
rawurl := "http://" + address + endpoint
// parse rawurl
URL, err := url.Parse(rawurl)
if err != nil {
return errors.InternalServerError("go.micro.client", err.Error())
}
hreq := &http.Request{
Method: "POST",
URL: &url.URL{
Scheme: "http",
Host: address,
Path: req.Endpoint(),
},
Method: "POST",
URL: URL,
Header: header,
Body: buf,
ContentLength: int64(len(b)),

View File

@ -10,11 +10,11 @@ import (
"net/http"
"testing"
"github.com/asim/go-micro/v3/client"
"github.com/asim/go-micro/v3/selector"
"github.com/asim/go-micro/v3/registry"
"github.com/asim/go-micro/plugins/registry/memory/v3"
"github.com/asim/go-micro/plugins/client/http/v3/test"
"github.com/asim/go-micro/plugins/registry/memory/v3"
"github.com/asim/go-micro/v3/client"
"github.com/asim/go-micro/v3/registry"
"github.com/asim/go-micro/v3/selector"
)
func TestHTTPClient(t *testing.T) {
@ -89,7 +89,11 @@ func TestHTTPClient(t *testing.T) {
Seq: int64(i),
Data: fmt.Sprintf("message %d", i),
}
req := c.NewRequest("test.service", "/foo/bar", msg)
endpoint := "/foo/bar"
if i%2 == 0 {
endpoint = endpoint + "?pageNum=1&pageSize=2"
}
req := c.NewRequest("test.service", endpoint, msg)
rsp := new(test.Message)
err := c.Call(context.TODO(), req, rsp)
if err != nil {