mirror of
https://github.com/eolinker/apinto
synced 2025-09-26 21:01:19 +08:00
1. Fix: error when reading response headers: cannot find whitespace in the first line of response.
2. Fix: the server closed connection before returning the first response byte.
This commit is contained in:
@@ -26,7 +26,7 @@ func (j *jwt) GetUser(ctx http_service.IHttpContext) (*application.UserInfo, boo
|
||||
}
|
||||
name, err := j.doJWTAuthentication(token)
|
||||
if err != nil {
|
||||
log.DebugF("[%s] get user error:%s", driverName, token)
|
||||
log.DebugF("[%s] get user error:%s,err is: %s", driverName, token, err.Error())
|
||||
return nil, false
|
||||
}
|
||||
return j.users.Get(name)
|
||||
|
@@ -510,6 +510,7 @@ func typeOfData(data interface{}) reflect.Kind {
|
||||
// doJWTAuthentication 进行JWT鉴权
|
||||
func (j *jwt) doJWTAuthentication(tokenStr string) (string, error) {
|
||||
tokenStr = strings.TrimPrefix(tokenStr, "Bearer ")
|
||||
tokenStr = strings.TrimPrefix(tokenStr, "bearer ")
|
||||
token, err := decodeToken(tokenStr)
|
||||
if err != nil {
|
||||
return "", errors.New("Bad token; " + err.Error())
|
||||
@@ -554,6 +555,9 @@ func (j *jwt) doJWTAuthentication(tokenStr string) (string, error) {
|
||||
if err = verifyRegisteredClaims(token, j.cfg.ClaimsToVerify); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if j.cfg.Path == "" {
|
||||
return j.cfg.Iss, nil
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(token.Claims)
|
||||
|
||||
|
18
go.mod
18
go.mod
@@ -1,8 +1,8 @@
|
||||
module github.com/eolinker/apinto
|
||||
|
||||
go 1.23.0
|
||||
go 1.24.0
|
||||
|
||||
toolchain go1.23.6
|
||||
toolchain go1.24.7
|
||||
|
||||
require (
|
||||
github.com/IBM/sarama v1.45.2
|
||||
@@ -34,9 +34,9 @@ require (
|
||||
github.com/stretchr/testify v1.10.0
|
||||
github.com/traefik/yaegi v0.16.1
|
||||
github.com/urfave/cli/v2 v2.23.4
|
||||
github.com/valyala/fasthttp v1.59.0
|
||||
golang.org/x/crypto v0.38.0
|
||||
golang.org/x/net v0.40.0
|
||||
github.com/valyala/fasthttp v1.66.0
|
||||
golang.org/x/crypto v0.42.0
|
||||
golang.org/x/net v0.44.0
|
||||
golang.org/x/oauth2 v0.14.0
|
||||
google.golang.org/api v0.149.0
|
||||
google.golang.org/grpc v1.61.0
|
||||
@@ -112,7 +112,7 @@ require (
|
||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.20.0 // indirect
|
||||
golang.org/x/sync v0.14.0 // indirect
|
||||
golang.org/x/sync v0.17.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
|
||||
@@ -123,7 +123,7 @@ require (
|
||||
|
||||
require (
|
||||
dubbo.apache.org/dubbo-go/v3 v3.0.2-0.20220519062747-f6405fa79d5c
|
||||
github.com/andybalholm/brotli v1.1.1
|
||||
github.com/andybalholm/brotli v1.2.0
|
||||
github.com/apache/dubbo-go-hessian2 v1.11.6
|
||||
github.com/armon/go-metrics v0.3.9 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
@@ -196,8 +196,8 @@ require (
|
||||
go.uber.org/atomic v1.9.0
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
go.uber.org/zap v1.23.0
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/text v0.25.0
|
||||
golang.org/x/sys v0.36.0 // indirect
|
||||
golang.org/x/text v0.29.0
|
||||
golang.org/x/time v0.1.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
|
||||
gopkg.in/sourcemap.v1 v1.0.5 // indirect
|
||||
|
@@ -3,6 +3,7 @@ package fasthttp_client
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
@@ -10,7 +11,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
||||
"github.com/eolinker/eosc/eocontext"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
@@ -80,15 +81,15 @@ func GenDialFunc(isTls bool) (fasthttp.DialFunc, error) {
|
||||
}
|
||||
|
||||
func (c *Client) getHostClient(addr string, rewriteHost string) (*fasthttp.HostClient, string, error) {
|
||||
|
||||
|
||||
scheme, nodeAddr := readAddress(addr)
|
||||
host := nodeAddr
|
||||
isTLS := strings.EqualFold(scheme, "https")
|
||||
|
||||
|
||||
if !strings.EqualFold(scheme, "http") && !isTLS {
|
||||
return nil, "", fmt.Errorf("unsupported protocol %q. http and https are supported", scheme)
|
||||
}
|
||||
|
||||
|
||||
c.mLock.RLock()
|
||||
m := c.m
|
||||
if isTLS {
|
||||
@@ -102,7 +103,7 @@ func (c *Client) getHostClient(addr string, rewriteHost string) (*fasthttp.HostC
|
||||
}
|
||||
c.mLock.Lock()
|
||||
defer c.mLock.Unlock()
|
||||
|
||||
|
||||
if isTLS {
|
||||
m = c.ms
|
||||
} else {
|
||||
@@ -114,7 +115,7 @@ func (c *Client) getHostClient(addr string, rewriteHost string) (*fasthttp.HostC
|
||||
return nil, "", err
|
||||
}
|
||||
dialAddr := addMissingPort(nodeAddr, isTLS)
|
||||
|
||||
|
||||
httpAddr := dialAddr
|
||||
if isTLS {
|
||||
if rewriteHost != "" && rewriteHost != nodeAddr {
|
||||
@@ -132,20 +133,29 @@ func (c *Client) getHostClient(addr string, rewriteHost string) (*fasthttp.HostC
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
hc = &fasthttp.HostClient{
|
||||
Addr: httpAddr,
|
||||
IsTLS: isTLS,
|
||||
TLSConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
Dial: dial,
|
||||
StreamResponseBody: true,
|
||||
MaxConns: DefaultMaxConns,
|
||||
MaxConnWaitTimeout: DefaultMaxConnWaitTimeout,
|
||||
RetryIf: func(request *fasthttp.Request) bool {
|
||||
return false
|
||||
|
||||
Dial: dial,
|
||||
StreamResponseBody: true,
|
||||
MaxConns: DefaultMaxConns,
|
||||
MaxIdleConnDuration: 0,
|
||||
|
||||
// 重试配置:针对 ErrConnectionClosed 自动重试
|
||||
MaxIdemponentCallAttempts: 3, // 最大重试次数(默认 3),适用于幂等请求(如 GET)
|
||||
RetryIfErr: func(req *fasthttp.Request, attempts int, err error) (resetTimeout bool, retry bool) {
|
||||
if errors.Is(err, fasthttp.ErrConnectionClosed) { // 针对你的错误重试
|
||||
return true, true // 重试并重置超时
|
||||
}
|
||||
return false, false
|
||||
},
|
||||
|
||||
ConnPoolStrategy: fasthttp.LIFO,
|
||||
}
|
||||
//http2.ConfigureClient(hc, http2.ClientOpts{})
|
||||
m[key] = hc
|
||||
@@ -153,7 +163,7 @@ func (c *Client) getHostClient(addr string, rewriteHost string) (*fasthttp.HostC
|
||||
go c.startCleaner(m)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return hc, scheme, nil
|
||||
}
|
||||
|
||||
@@ -195,14 +205,15 @@ func (c *Client) ProxyTimeout(addr string, host string, req *fasthttp.Request, r
|
||||
resp.SetConnectionClose()
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
client, scheme, err := c.getHostClient(addr, host)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
request.URI().SetScheme(scheme)
|
||||
|
||||
return client.DoTimeout(req, resp, timeout)
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (c *Client) startCleaner(m map[string]*fasthttp.HostClient) {
|
||||
@@ -220,7 +231,7 @@ func (c *Client) startCleaner(m map[string]*fasthttp.HostClient) {
|
||||
delete(m, k)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if len(m) == 0 {
|
||||
mustStop = true
|
||||
}
|
||||
@@ -234,7 +245,7 @@ func (c *Client) startCleaner(m map[string]*fasthttp.HostClient) {
|
||||
|
||||
func (c *Client) mCleaner(m map[string]*fasthttp.HostClient) {
|
||||
mustStop := false
|
||||
|
||||
|
||||
//sleep := c.MaxIdleConnDuration
|
||||
//if sleep < time.Second {
|
||||
// sleep = time.Second
|
||||
@@ -253,9 +264,9 @@ func (c *Client) mCleaner(m map[string]*fasthttp.HostClient) {
|
||||
if len(m) == 0 {
|
||||
mustStop = true
|
||||
}
|
||||
|
||||
|
||||
c.mLock.Unlock()
|
||||
|
||||
|
||||
if mustStop {
|
||||
break
|
||||
}
|
||||
|
Reference in New Issue
Block a user