Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [2.6.0-beta.1](https://github.com/LerianStudio/lib-auth/compare/v2.5.0...v2.6.0-beta.1) (2026-03-26)


### Bug Fixes

* prevent HTTP/2 hpack panic with shared HTTP client ([0716b6f](https://github.com/LerianStudio/lib-auth/commit/0716b6ffa204f1a38613b1041c6932ae637ce8e8))

## [2.5.0](https://github.com/LerianStudio/lib-auth/compare/v2.4.0...v2.5.0) (2026-03-21)


Expand Down
19 changes: 16 additions & 3 deletions auth/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ const (
pluginName string = "plugin-auth"
)

// sharedHTTPClient is a package-level HTTP client with a custom transport
// that prevents HTTP/2 hpack panics under concurrent access. HTTP clients
// are safe for concurrent use and should be reused across requests.
var sharedHTTPClient = &http.Client{
Timeout: 30 * time.Second,
Transport: &http.Transport{
ForceAttemptHTTP2: false,
MaxIdleConns: 100,
MaxIdleConnsPerHost: 10,
IdleConnTimeout: 90 * time.Second,
},
}

// unmarshalErrorResponse unmarshals a JSON response body into commons.Response,
// tolerating a numeric "code" field (the auth service may return code as a number).
func unmarshalErrorResponse(body []byte) (commons.Response, error) {
Expand Down Expand Up @@ -157,7 +170,7 @@ func NewAuthClient(address string, enabled bool, logger *log.Logger) *AuthClient
}
}

client := &http.Client{}
client := sharedHTTPClient
healthURL := fmt.Sprintf("%s/health", address)

failedToConnectMsg := fmt.Sprintf("Failed to connect to %s: %%v\n", pluginName)
Expand Down Expand Up @@ -257,7 +270,7 @@ func (auth *AuthClient) checkAuthorization(ctx context.Context, sub, resource, a
attribute.String("app.request.request_id", reqID),
)

client := &http.Client{}
client := sharedHTTPClient

token, _, err := new(jwt.Parser).ParseUnverified(accessToken, jwt.MapClaims{})
if err != nil {
Expand Down Expand Up @@ -400,7 +413,7 @@ func (auth *AuthClient) GetApplicationToken(ctx context.Context, clientID, clien
return "", nil
}

client := &http.Client{}
client := sharedHTTPClient

requestBody := map[string]string{
"grantType": "client_credentials",
Expand Down
Loading