Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WithResponseReadSize function to allow SDK users to modify max response read opt #5961

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

meme-lord
Copy link
Contributor

@meme-lord meme-lord commented Jan 7, 2025

Proposed changes

This adds a WithResponseReadSize() function so that SDK users can change the max response read size to suit their needs. I also simplified the WithConcurrency() function to reduce the cognitive complexity of it (no functional change).

Related Github issue: #5895

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • New Features
    • Added a new configuration option to set maximum response read size.
  • Refactor
    • Simplified concurrency option handling by removing unnecessary conditional branches.

@auto-assign auto-assign bot requested a review from dogancanbakir January 7, 2025 16:30
Copy link

coderabbitai bot commented Jan 7, 2025

Walkthrough

The pull request introduces modifications to the configuration handling in the lib/config.go file. The changes simplify the concurrency option assignment process by removing conditional else statements and making option assignments more direct. A new function WithResponseReadSize is added to set the maximum response read size, expanding the configuration capabilities of the NucleiEngine.

Changes

File Change Summary
lib/config.go - Simplified WithConcurrency function by removing conditional branches
- Added new WithResponseReadSize function to set response read size

Poem

🐰 Configs dance with rabbit's grace,
Concurrency flows without a trace
New options bloom, size now defined
Code simplified, elegantly aligned
A configuration melody so bright! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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 (1)
lib/config.go (1)

148-157: LGTM! Clean refactoring of concurrency options.

The simplified assignments improve code readability while maintaining the same validation logic. Good job on reducing cognitive complexity.

Consider using a struct literal assignment for better maintainability:

-		e.opts.TemplateThreads = opts.TemplateConcurrency
-		e.opts.BulkSize = opts.HostConcurrency
-		e.opts.HeadlessBulkSize = opts.HeadlessHostConcurrency
-		e.opts.HeadlessTemplateThreads = opts.HeadlessTemplateConcurrency
-		e.opts.JsConcurrency = opts.JavascriptTemplateConcurrency
-		e.opts.PayloadConcurrency = opts.TemplatePayloadConcurrency
-		e.opts.ProbeConcurrency = opts.ProbeConcurrency
+		e.opts = struct {
+			TemplateThreads         int
+			BulkSize               int
+			HeadlessBulkSize       int
+			HeadlessTemplateThreads int
+			JsConcurrency          int
+			PayloadConcurrency     int
+			ProbeConcurrency       int
+		}{
+			TemplateThreads:         opts.TemplateConcurrency,
+			BulkSize:               opts.HostConcurrency,
+			HeadlessBulkSize:       opts.HeadlessHostConcurrency,
+			HeadlessTemplateThreads: opts.HeadlessTemplateConcurrency,
+			JsConcurrency:          opts.JavascriptTemplateConcurrency,
+			PayloadConcurrency:     opts.TemplatePayloadConcurrency,
+			ProbeConcurrency:       opts.ProbeConcurrency,
+		}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 805cab4 and 834e934.

📒 Files selected for processing (1)
  • lib/config.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Tests (macOS-latest)
  • GitHub Check: Tests (windows-latest)
  • GitHub Check: Tests (ubuntu-latest)
🔇 Additional comments (1)
lib/config.go (1)

159-163: Verify the implementation of response size limit.

Let's verify how this option is used in the HTTP request processing code:

✅ Verification successful

Response size limit implementation is correct and properly integrated.

The option is:

  • Correctly propagated from configuration to HTTP handling
  • Used properly with ResponseChain for efficient reading
  • Has a reasonable default of 10MB
  • Doesn't conflict with other size limits
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for ResponseReadSize usage in the codebase
echo "Searching for ResponseReadSize usage..."
rg -A 5 "ResponseReadSize"

# Search for other response size limits in HTTP handling code
echo "Searching for other response size limits..."
rg -A 5 "response.*size|size.*response"

# Search for HTTP response reading implementation
echo "Searching for HTTP response reading implementation..."
ast-grep --pattern 'func $_(response http.Response) {
  $$$
}'

Length of output: 14015

lib/config.go Outdated Show resolved Hide resolved
improved comment, changed casing of param name, added negative input check

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 834e934 and 8e058a3.

📒 Files selected for processing (1)
  • lib/config.go (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Lint
lib/config.go

[failure] 170-170:
syntax error: non-declaration statement outside function body (typecheck)


[failure] 170-170:
expected declaration, found '}' (typecheck)


[failure] 170-170:
syntax error: non-declaration statement outside function body) (typecheck)


[failure] 170-170:
syntax error: non-declaration statement outside function body) (typecheck)


[failure] 170-170:
syntax error: non-declaration statement outside function body) (typecheck)

🪛 golangci-lint (1.62.2)
lib/config.go

170-170: expected declaration, found '}'

(typecheck)

🪛 GitHub Actions: 🔨 Tests
lib/config.go

[error] 170-170: syntax error: non-declaration statement outside function body

🔇 Additional comments (2)
lib/config.go (2)

148-154: Great simplification of the concurrency options assignment!

The removal of conditional branches while maintaining all necessary validation checks makes the code more maintainable and easier to understand.


159-169: Well-implemented response size configuration!

The implementation includes all the essential elements:

  • Clear documentation with units (bytes)
  • Input validation for negative values
  • Recommended value ranges

lib/config.go Outdated
Comment on lines 170 to 171
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove extra closing braces causing syntax errors.

The extra closing braces on these lines are causing compilation failures. They don't belong to any opening brace and should be removed.

Apply this diff to fix the syntax errors:

-	}
-}
🧰 Tools
🪛 GitHub Check: Lint

[failure] 170-170:
syntax error: non-declaration statement outside function body (typecheck)


[failure] 170-170:
expected declaration, found '}' (typecheck)


[failure] 170-170:
syntax error: non-declaration statement outside function body) (typecheck)


[failure] 170-170:
syntax error: non-declaration statement outside function body) (typecheck)


[failure] 170-170:
syntax error: non-declaration statement outside function body) (typecheck)

🪛 golangci-lint (1.62.2)

170-170: expected declaration, found '}'

(typecheck)

🪛 GitHub Actions: 🔨 Tests

[error] 170-170: syntax error: non-declaration statement outside function body

Copy link

@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: 0

🧹 Nitpick comments (1)
lib/config.go (1)

159-167: Implementation looks good and addresses previous review comments.

Consider defining constants for the recommended values to improve maintainability:

+const (
+    // DefaultMinResponseReadSize represents 1MB in bytes
+    DefaultMinResponseReadSize = 1048576
+    // DefaultMaxResponseReadSize represents 10MB in bytes
+    DefaultMaxResponseReadSize = 10485760
+)

// WithResponseReadSize sets the maximum size of response to read in bytes.
-// A value of 0 means no limit. Recommended values: 1MB (1048576) to 10MB (10485760).
+// A value of 0 means no limit. Recommended values: DefaultMinResponseReadSize to DefaultMaxResponseReadSize.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e058a3 and e14b365.

📒 Files selected for processing (1)
  • lib/config.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Tests (macOS-latest)
  • GitHub Check: Tests (windows-latest)
  • GitHub Check: Tests (ubuntu-latest)
🔇 Additional comments (2)
lib/config.go (2)

148-157: Great refactoring of the concurrency options!

The simplified assignments improve readability while maintaining the same validation constraints.


159-167: Verify integration and add test coverage.

  1. Please add unit tests for the new WithResponseReadSize function to verify:

    • Validation of negative values
    • Setting of valid values
    • Default behavior with zero value
  2. Let's verify the integration with the HTTP client:

✅ Verification successful

Implementation verified, tests still needed

The ResponseReadSize option is properly integrated with the HTTP client and the overall system. Please proceed with adding unit tests as originally suggested to ensure the robustness of the implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for HTTP client configurations to ensure ResponseReadSize is properly used
rg -A 5 "ResponseReadSize" --type go

Length of output: 2687

@GeorginaReeder
Copy link

Thanks for your contribution @meme-lord ! :)

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