Skip to content

refactor(client): return the response body from DoRequest of client/http - #112

Merged
grubmeshi merged 1 commit into
mainfrom
http-do-request
Nov 25, 2026
Merged

grubmeshi merged 1 commit into
mainfrom
http-do-request

Conversation

@grubmeshi

Copy link
Copy Markdown
Collaborator

What it does

  • http.Client.DoRequest and http.AuthorizedClient.DoRequest return the response body. UnmarshalJsonBody, ReadAllBody and IgnoreResponse read it and close it. The generic DoRequest[R] is gone.
  • Request options set the retry policy (Retryable(RetryOn…)), refuse redirects (WithoutRedirects) and capture the response header (WithCapturedResponseHeader). A GET and a DELETE are retried on every transient failure, any other method on 423, 429 and 503. The retries outlast a restart of meshStack.
  • The debug log shows the first 1024 bytes of a body as they came.
  • An http.Error names the method and URL. http.Authorization is a fmt.Stringer in place of Scope, and a 403 names it. BearerToken.String redacts the token.
  • AuthorizedClient.ProxyTransport replaces internal/tfstate/apiproxy. The state store does not retry a 423, so that tofu sees the holder of a lock at once.
  • client/http/download.go is gone.
  • internal/json is the only importer of encoding/json/v2.

Review carefully

  • client/http/http_client.go, options.go, retry.go, logging.go, auth.go.
  • internal/tfstate/store.go (retry policy of the state calls) and proxy.go.

Temporary glue

client/internal/mesh_object.go, client/raw.go, client/building_block_run_action.go and the RawClient callers adapt to the new DoRequest with as few changes as possible. generic-mesh-object-client deletes all of them. Until apidocs-etag, internal/apidocs downloads the API docs on every command.

Mechanical

The import changes from encoding/json/v2 to internal/json, and the callers of the old options (WithAccept, WithHeaders, WithBody, WithJsonPayload, WithFormPayload).

Place in the stack

3 of 6. Base: profile-resolution. Next: apidocs-etag.

🤖 Generated with Claude Code

@meshcloud-gh-actions

meshcloud-gh-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Coverage of the acceptance run against the meshStack backend, on dd3601fc98d84f5e646d09476e93b4d502a3d361.

Scope Coverage
Unit tests 78.0%
Acceptance tests 52.6%
Combined 82.5%
Uncovered functions
client/api_key.go:52: meshApiKeyClient.Create 0.0%
client/api_key.go:56: meshApiKeyClient.Read 0.0%
client/api_key.go:60: meshApiKeyClient.Update 0.0%
client/api_key.go:64: meshApiKeyClient.Delete 0.0%
client/api_key_permissions.go:20: ApiKeyPermissions.AllCodes 0.0%
client/api_key_permissions.go:33: ApiKeyPermissions.WorkspaceCodes 0.0%
client/api_key_permissions.go:263: AllApiKeyPermissions 0.0%
client/api_key_permissions.go:267: WorkspacePermissionCodes 0.0%
client/binding_status.go:18: *MeshGroupBindingStatus.WaitsForApproval 0.0%
client/binding_status.go:22: *MeshUserBindingStatus.WaitsForApproval 0.0%
client/building_block_definition.go:71: MeshBuildingBlockDefinitionApprovalPolicies.NothingRequiresApproval 0.0%
client/building_block_definition.go:82: DisabledSchedule 0.0%
client/building_block_definition.go:89: MeshBuildingBlockDefinitionSchedule.IsDisabled 0.0%
client/building_block_definition.go:93: MeshBuildingBlockDefinitionSpec.HasNeutralPolicies 0.0%
client/building_block_definition.go:97: MeshBuildingBlockDefinitionSpec.WithNeutralPolicies 0.0%
client/building_block_definition.go:166: meshBuildingBlockDefinitionClient.List 0.0%
client/building_block_definition.go:173: meshBuildingBlockDefinitionClient.Read 0.0%
client/building_block_definition.go:177: meshBuildingBlockDefinitionClient.Create 0.0%
client/building_block_definition.go:181: meshBuildingBlockDefinitionClient.Update 0.0%
client/building_block_definition.go:185: meshBuildingBlockDefinitionClient.Delete 0.0%
client/building_block_definition_version.go:103: MeshBuildingBlockType.TagInputTargets 0.0%
client/building_block_definition_version.go:247: meshBuildingBlockDefinitionVersionClient.Create 0.0%
client/building_block_definition_version.go:256: meshBuildingBlockDefinitionVersionClient.Update 0.0%
client/building_block_definition_version_implementation.go:81: MeshBuildingBlockDefinitionImplementation.InferType 0.0%
client/building_block_definition_version_implementation.go:95: MeshBuildingBlockDefinitionImplementation.MarshalJSONTo 0.0%
... and 139 more

covdata func names a method without its receiver, so an entry can belong to an implementation nothing selects rather than to a function the tests never reached. Open the file and line before reading one as a coverage gap.

@grubmeshi
grubmeshi added this pull request to stack #115 November 25, 2026 10:25
client/http has one DoRequest, which returns the response body, and UnmarshalJsonBody,
ReadAllBody and IgnoreResponse consume it. Request options set the retry policy, refuse
redirects and capture the response header. A GET and a DELETE are retried on every transient
failure, any other method on 423, 429 and 503; the state store of tfstate retries no 423, so
that tofu sees the holder of a lock at once. The debug log shows the first 1024 bytes of a body
as they came.

An http.Error names the method and the URL. An Authorization is a fmt.Stringer, which a 403
names, and BearerToken.String redacts the token. AuthorizedClient.ProxyTransport replaces
internal/tfstate/apiproxy. Download is gone.

internal/json is the only importer of encoding/json/v2.

client/internal, client.RawClient and the run action client adapt to DoRequest only as far as
they need to keep working, and internal/apidocs downloads the API docs on every command: the
next changes replace both.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

Base automatically changed from profile-resolution to main November 25, 2026 15:16
@grubmeshi
grubmeshi merged commit dd3601f into main Nov 25, 2026
15 of 25 checks passed
@grubmeshi
grubmeshi deleted the http-do-request branch November 25, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant