Skip to content

Conversation

Autumn-27
Copy link
Contributor

@Autumn-27 Autumn-27 commented Oct 18, 2025

#1445

Summary by CodeRabbit

  • New Features
    • Added --store-response-body and --store-response-body-dir flags to optionally save HTTP response bodies to a custom directory.
    • Stored response body file paths are recorded and included in output results.
    • Specifying a response-body directory automatically enables response-body storage.

Copy link
Contributor

coderabbitai bot commented Oct 18, 2025

Walkthrough

Adds support for storing raw HTTP response bodies: new options and CLI flags, wiring through initialization, auto-enable logic when a body directory is provided, response struct path tracking, and writer logic to create/validate directories and write body files.

Changes

Cohort / File(s) Summary
CLI & top-level Options
cmd/katana/main.go, pkg/types/options.go
Added StoreResponseBody bool and StoreResponseBodyDir string to public Options and bound CLI flags --store-response-body and --store-response-body-dir.
Runner validation
internal/runner/options.go
In validateOptions, auto-enable StoreResponseBody when StoreResponseBodyDir is set (mirrors existing StoreResponse/StoreResponseDir behavior).
Crawler wiring
pkg/types/crawler_options.go
Propagated StoreResponseBody and StoreResponseBodyDir into OutputWriter configuration during crawler options initialization.
Output writer implementation
pkg/output/output.go
Added DefaultResponseBodyDir constant; added writer fields for storeResponseBody and storeResponseBodyDir; initialize/validate body storage directory; write response bodies to files, update Response.StoredResponseBodyPath, and honor NoClobber.
Response model
pkg/navigation/response.go
Added public field StoredResponseBodyPath string with JSON tag json:"stored_response_body_path,omitempty" to the Response struct to track stored body file path.

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI as CLI Parser
    participant Runner as Runner Options
    participant Crawler as Crawler Init
    participant Output as Output Writer
    participant FS as File System
    participant Response as Response Struct

    User->>CLI: provide --store-response-body(-dir)
    CLI->>Runner: readFlags()
    Runner->>Runner: validateOptions()
    alt StoreResponseBodyDir set && not StoreResponseBody
        Runner->>Runner: enable StoreResponseBody
    end
    Runner->>Crawler: NewCrawlerOptions (includes StoreResponseBody)
    Crawler->>Output: init writer with storeResponseBody config
    rect rgb(255,245,235)
      Output->>FS: create/validate storeResponseBodyDir (respect NoClobber)
    end
    Note over Output,Response: On each write when enabled
    Output->>FS: write response body file
    FS-->>Output: file path
    Output->>Response: set StoredResponseBodyPath
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through flags and fields today,
A burrow for bodies in a tidy array;
Dirs created, paths recorded with care,
Now responses rest neatly stored there!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Added srb and srbd parameters to support storing only the response bo…" directly and specifically describes the main change in the changeset. The title correctly identifies the two new CLI parameters being added (srb and srbd for --store-response-body and --store-response-body-dir, respectively) and clearly states their purpose of enabling response body storage. The changes across all modified files consistently implement this feature, including adding configuration fields, CLI flag bindings, and the core logic for storing response bodies to a custom directory. The title is concise, specific, and sufficiently descriptive for a developer scanning PR history to understand the primary change.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc3d54d and aa998b9.

📒 Files selected for processing (1)
  • pkg/navigation/response.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
pkg/navigation/response.go (1)
pkg/navigation/request.go (2)
  • Depth (9-9)
  • Request (12-25)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Test Builds (windows-latest, 1.24.x)
  • GitHub Check: release-test-mac
  • GitHub Check: Functional Test (ubuntu-latest)
  • GitHub Check: Functional Test (macOS-latest)
  • GitHub Check: Functional Test (windows-latest)
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
pkg/navigation/response.go (1)

43-44: Duplicate JSON tag issue fixed — LGTM!

The duplicate JSON tag issue flagged in the previous review has been resolved. Both fields now use distinct JSON tags:

  • Line 43: stored_response_path
  • Line 44: stored_response_body_path

The new StoredResponseBodyPath field appropriately complements the existing StoredResponsePath field, enabling separate tracking of response body storage locations when the feature is enabled.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (5)
pkg/types/options.go (1)

135-138: Docs polish for new fields (capitalize HTTP, pluralize “body”).

Small comment grammar tweaks improve CLI/docs consistency.

- // StoreResponseBody specifies if katana should store http responses body
+ // StoreResponseBody specifies if katana should store HTTP response bodies
- // StoreResponseBodyDir specifies if katana should use a custom directory to store http responses body
+ // StoreResponseBodyDir specifies a custom directory to store HTTP response bodies
internal/runner/options.go (1)

47-50: Auto-enable behavior matches ‘sr’; drop trailing newline in log.

Functionality is good. The debug message includes an unnecessary “\n”.

- gologger.Debug().Msgf("store response body directory specified, enabling \"srb\" flag automatically\n")
+ gologger.Debug().Msgf("store response body directory specified, enabling \"srb\" flag automatically")
cmd/katana/main.go (1)

229-231: Help text grammar (plural, HTTP, article).

Clarify flag descriptions for user-facing help.

- flagSet.BoolVarP(&options.StoreResponseBody, "store-response-body", "srb", false, "store http responses body"),
- flagSet.StringVarP(&options.StoreResponseBodyDir, "store-response-body-dir", "srbd", "", "store http responses body to custom directory"),
+ flagSet.BoolVarP(&options.StoreResponseBody, "store-response-body", "srb", false, "store HTTP response bodies"),
+ flagSet.StringVarP(&options.StoreResponseBodyDir, "store-response-body-dir", "srbd", "", "store HTTP response bodies to a custom directory"),
pkg/output/output.go (2)

225-236: Clarify error messages: say “response body”.

These errors belong to the body-only storage path—message should reflect that.

- if err := fileWriter.Write([]byte(result.Response.Body)); err != nil {
-   return errkit.Wrap(err, "output: could not store response")
+ if err := fileWriter.Write([]byte(result.Response.Body)); err != nil {
+   return errkit.Wrap(err, "output: could not store response body")

152-164: Parity with response index (optional).

You create an index.txt for StoreResponse but not for StoreResponseBody. If index is intended, consider adding it for the body dir too; if not used, consider removing it from both for consistency.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64a99ad and cc3d54d.

📒 Files selected for processing (7)
  • cmd/katana/main.go (1 hunks)
  • internal/runner/options.go (1 hunks)
  • pkg/navigation/response.go (1 hunks)
  • pkg/output/options.go (1 hunks)
  • pkg/output/output.go (5 hunks)
  • pkg/types/crawler_options.go (1 hunks)
  • pkg/types/options.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
pkg/output/output.go (1)
pkg/navigation/response.go (1)
  • Response (30-45)
🪛 GitHub Actions: 🔨 Build Test
pkg/navigation/response.go

[error] 43-44: govet: structtag: struct field StoredResponseBodyPath repeats json tag 'stored_response_path' (also at response.go:43).

🪛 GitHub Check: Lint
pkg/navigation/response.go

[failure] 44-44:
structtag: struct field StoredResponseBodyPath repeats json tag "stored_response_path" also at response.go:43 (govet)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Functional Test (windows-latest)
  • GitHub Check: Functional Test (macOS-latest)
  • GitHub Check: Functional Test (ubuntu-latest)
  • GitHub Check: release-test-mac
  • GitHub Check: release-test-linux
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
pkg/output/options.go (1)

15-15: Wiring LGTM.

Fields align with types.Options and writer usage.

Also applies to: 23-23

pkg/types/crawler_options.go (1)

81-82: Propagation LGTM.

StoreResponseBody and StoreResponseBodyDir correctly flow into output.Options.

Also applies to: 86-87

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