From 793270f55ba74894482a6622f92cf34c879fdcb4 Mon Sep 17 00:00:00 2001 From: Benoit Sigoure Date: Thu, 12 Mar 2026 20:46:57 +0100 Subject: [PATCH] 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: https://github.com/gleanwork/api-client-go/issues/84 --- datasource.go | 5 +++-- indexingdocuments.go | 9 +++++---- people.go | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/datasource.go b/datasource.go index d65759a7..90506dc1 100644 --- a/datasource.go +++ b/datasource.go @@ -6,6 +6,8 @@ import ( "bytes" "context" "fmt" + "net/http" + "github.com/gleanwork/api-client-go/internal/config" "github.com/gleanwork/api-client-go/internal/hooks" "github.com/gleanwork/api-client-go/internal/utils" @@ -13,7 +15,6 @@ import ( "github.com/gleanwork/api-client-go/models/components" "github.com/gleanwork/api-client-go/models/operations" "github.com/gleanwork/api-client-go/retry" - "net/http" ) type Datasource struct { @@ -200,7 +201,7 @@ func (s *Datasource) Status(ctx context.Context, datasource string, opts ...oper switch { case httpRes.StatusCode == 200: switch { - case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json; charset=UTF-8`): + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): rawBody, err := utils.ConsumeRawBody(httpRes) if err != nil { return nil, err diff --git a/indexingdocuments.go b/indexingdocuments.go index a3325636..1899bcf5 100644 --- a/indexingdocuments.go +++ b/indexingdocuments.go @@ -6,6 +6,9 @@ import ( "bytes" "context" "fmt" + "net/http" + "net/url" + "github.com/gleanwork/api-client-go/internal/config" "github.com/gleanwork/api-client-go/internal/hooks" "github.com/gleanwork/api-client-go/internal/utils" @@ -13,8 +16,6 @@ import ( "github.com/gleanwork/api-client-go/models/components" "github.com/gleanwork/api-client-go/models/operations" "github.com/gleanwork/api-client-go/retry" - "net/http" - "net/url" ) type IndexingDocuments struct { @@ -1223,7 +1224,7 @@ func (s *IndexingDocuments) Debug(ctx context.Context, datasource string, debugD switch { case httpRes.StatusCode == 200: switch { - case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json; charset=UTF-8`): + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): rawBody, err := utils.ConsumeRawBody(httpRes) if err != nil { return nil, err @@ -1448,7 +1449,7 @@ func (s *IndexingDocuments) DebugMany(ctx context.Context, datasource string, de switch { case httpRes.StatusCode == 200: switch { - case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json; charset=UTF-8`): + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): rawBody, err := utils.ConsumeRawBody(httpRes) if err != nil { return nil, err diff --git a/people.go b/people.go index 979803b0..44d3baed 100644 --- a/people.go +++ b/people.go @@ -6,6 +6,9 @@ import ( "bytes" "context" "fmt" + "net/http" + "net/url" + "github.com/gleanwork/api-client-go/internal/config" "github.com/gleanwork/api-client-go/internal/hooks" "github.com/gleanwork/api-client-go/internal/utils" @@ -13,8 +16,6 @@ import ( "github.com/gleanwork/api-client-go/models/components" "github.com/gleanwork/api-client-go/models/operations" "github.com/gleanwork/api-client-go/retry" - "net/http" - "net/url" ) type People struct { @@ -209,7 +210,7 @@ func (s *People) Debug(ctx context.Context, datasource string, debugUserRequest switch { case httpRes.StatusCode == 200: switch { - case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json; charset=UTF-8`): + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): rawBody, err := utils.ConsumeRawBody(httpRes) if err != nil { return nil, err