Skip to content

Commit 52780f6

Browse files
Fix content-type matching for debug endpoints
The debug endpoints (/api/index/v1/debug/*) return 'application/json' without the 'charset=UTF-8' parameter, but the generated SDK code was checking for an exact match with 'application/json; charset=UTF-8'. This caused the SDK to return 'unknown content-type received' errors even though the response was valid JSON and the status was 200. Changed the content-type pattern from 'application/json; charset=UTF-8' to 'application/json' in: - Datasource.Status() - /api/index/v1/debug/{datasource}/status - People.Debug() - /api/index/v1/debug/{datasource}/user The MatchContentType() function already handles charset parameters correctly via mime.ParseMediaType(), so this change allows it to match both 'application/json' and 'application/json; charset=UTF-8'. Fixes: #84
1 parent 7d3d235 commit 52780f6

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

datasource.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import (
66
"bytes"
77
"context"
88
"fmt"
9+
"net/http"
10+
911
"github.com/gleanwork/api-client-go/internal/config"
1012
"github.com/gleanwork/api-client-go/internal/hooks"
1113
"github.com/gleanwork/api-client-go/internal/utils"
1214
"github.com/gleanwork/api-client-go/models/apierrors"
1315
"github.com/gleanwork/api-client-go/models/components"
1416
"github.com/gleanwork/api-client-go/models/operations"
1517
"github.com/gleanwork/api-client-go/retry"
16-
"net/http"
1718
)
1819

1920
type Datasource struct {
@@ -200,7 +201,7 @@ func (s *Datasource) Status(ctx context.Context, datasource string, opts ...oper
200201
switch {
201202
case httpRes.StatusCode == 200:
202203
switch {
203-
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json; charset=UTF-8`):
204+
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
204205
rawBody, err := utils.ConsumeRawBody(httpRes)
205206
if err != nil {
206207
return nil, err

people.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ import (
66
"bytes"
77
"context"
88
"fmt"
9+
"net/http"
10+
"net/url"
11+
912
"github.com/gleanwork/api-client-go/internal/config"
1013
"github.com/gleanwork/api-client-go/internal/hooks"
1114
"github.com/gleanwork/api-client-go/internal/utils"
1215
"github.com/gleanwork/api-client-go/models/apierrors"
1316
"github.com/gleanwork/api-client-go/models/components"
1417
"github.com/gleanwork/api-client-go/models/operations"
1518
"github.com/gleanwork/api-client-go/retry"
16-
"net/http"
17-
"net/url"
1819
)
1920

2021
type People struct {
@@ -209,7 +210,7 @@ func (s *People) Debug(ctx context.Context, datasource string, debugUserRequest
209210
switch {
210211
case httpRes.StatusCode == 200:
211212
switch {
212-
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json; charset=UTF-8`):
213+
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
213214
rawBody, err := utils.ConsumeRawBody(httpRes)
214215
if err != nil {
215216
return nil, err

0 commit comments

Comments
 (0)