Skip to content

chore: refactor net/rest to use Ferret HTTP client abstraction - #31

Merged
ziflex merged 2 commits into
mainfrom
feat/rest-ferret-http
Jul 9, 2026
Merged

chore: refactor net/rest to use Ferret HTTP client abstraction#31
ziflex merged 2 commits into
mainfrom
feat/rest-ferret-http

Conversation

@ziflex

@ziflex ziflex commented Jul 9, 2026

Copy link
Copy Markdown
Member

This pull request refactors the REST client in the net/rest module to remove its direct dependency on the standard library http.Client and instead use the Ferret network interface (ferretnet.HTTPClient). This enables better testability, greater flexibility for custom network policies, and improved context management. The change is accompanied by updates to the test suite and several new tests to ensure correct behavior and coverage.

The most important changes are:

Core REST client refactor:

  • The Client struct in client.go no longer holds an http.Client; instead, it retrieves a ferretnet.HTTPClient from the context for each request, making the client more flexible and testable. (client.go, execute.go) [1] [2] [3] [4] [5]
  • The request/response pipeline now uses Ferret's HTTP types (ferrethttp.Request and ferrethttp.Response) throughout, including in the codec and response handling logic. (codec.go, response.go) [1] [2] [3] [4]
  • The request body encoder now returns a []byte instead of an io.Reader, reflecting the new Ferret HTTP interface. (codec.go) [1] [2]

Test improvements and coverage:

  • All client tests now use a networkContext() helper to provide the necessary Ferret network in the context. (client_test.go) [1] [2] [3] [4] [5] [6] [7] [8]
  • New tests verify that the client:
    • Correctly uses a Ferret HTTP client injected via context (TestClientUsesFerretHTTPClientFromContext).
    • Errors if no network is present in the context (TestClientRequiresNetworkContext).
    • Honors Ferret's HTTP policy enforcement, blocking forbidden outbound requests (TestModuleHonorsFerretHTTPPolicy). [1] [2]

Test utilities:

  • A new recordingHTTPClient test double is introduced to capture and inspect outgoing Ferret HTTP requests for assertions in tests. (recording_http_client_test.go)

These changes make the REST client more robust, modular, and secure, while improving testability and aligning it with Ferret's network abstraction.

… tests for network context handling, and improve request encoding
Copilot AI review requested due to automatic review settings July 9, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the net/rest module’s internal REST client to use Ferret’s network HTTP client abstraction (context-provided ferretnet.HTTPClient and ferrethttp.{Request,Response}) instead of net/http.Client, aiming to improve policy enforcement and testability.

Changes:

  • Reworked request execution to fetch an HTTP client from the execution context and issue requests via ferrethttp.Request.
  • Updated request/response encoding/decoding to operate on Ferret HTTP types and []byte bodies.
  • Expanded tests with Ferret network context usage, including a new policy enforcement test and a recording HTTP client test double.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
modules/net/rest/core/client.go Removes direct *http.Client storage from the REST client handle.
modules/net/rest/core/execute.go Executes requests via ferretnet.HTTPClientFrom(ctx) and ferrethttp.Request.
modules/net/rest/core/codec.go Changes request body encoding to return []byte (and updates call sites).
modules/net/rest/core/response.go Decodes ferrethttp.Response and builds “full” response objects using the request URL.
modules/net/rest/core/client_test.go Updates tests to provide a Ferret network context and adds new coverage for context-provided HTTP clients.
modules/net/rest/core/recording_http_client_test.go Adds a test double to record outgoing Ferret HTTP requests.
modules/net/rest/http_test.go Adds a module-level test verifying Ferret HTTP policy enforcement blocks outbound requests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 34 to 36
if binary, ok := value.(runtime.Binary); ok {
return bytes.NewReader(binary), "application/octet-stream", nil
return []byte(binary), "application/octet-stream", nil
}
Copilot AI review requested due to automatic review settings July 9, 2026 20:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated no new comments.

@ziflex
ziflex merged commit 61f76ab into main Jul 9, 2026
59 checks passed
@ziflex
ziflex deleted the feat/rest-ferret-http branch July 9, 2026 20:44
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.

2 participants