From 08c46ffaeb0ba39dec949015eda3342d465188bf Mon Sep 17 00:00:00 2001 From: meme-lord Date: Tue, 14 Jan 2025 10:05:12 +0000 Subject: [PATCH] Added WithResponseReadSize function to allow SDK users to modify max response read opt (#5961) * added WithResponseReadSize function to allow SDK users to modify max response read opt * Update lib/config.go improved comment, changed casing of param name, added negative input check Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fixing rabbitai commit >:( --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- lib/config.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/config.go b/lib/config.go index 2394f85cfa..c0a9a2dfbb 100644 --- a/lib/config.go +++ b/lib/config.go @@ -126,39 +126,44 @@ func WithConcurrency(opts Concurrency) NucleiSDKOptions { // minimum required is 1 if opts.TemplateConcurrency <= 0 { return errors.New("template threads must be at least 1") - } else { - e.opts.TemplateThreads = opts.TemplateConcurrency } if opts.HostConcurrency <= 0 { return errors.New("host concurrency must be at least 1") - } else { - e.opts.BulkSize = opts.HostConcurrency } if opts.HeadlessHostConcurrency <= 0 { return errors.New("headless host concurrency must be at least 1") - } else { - e.opts.HeadlessBulkSize = opts.HeadlessHostConcurrency } if opts.HeadlessTemplateConcurrency <= 0 { return errors.New("headless template threads must be at least 1") - } else { - e.opts.HeadlessTemplateThreads = opts.HeadlessTemplateConcurrency } if opts.JavascriptTemplateConcurrency <= 0 { return errors.New("js must be at least 1") - } else { - e.opts.JsConcurrency = opts.JavascriptTemplateConcurrency } if opts.TemplatePayloadConcurrency <= 0 { return errors.New("payload concurrency must be at least 1") - } else { - e.opts.PayloadConcurrency = opts.TemplatePayloadConcurrency } if opts.ProbeConcurrency <= 0 { return errors.New("probe concurrency must be at least 1") - } else { - e.opts.ProbeConcurrency = opts.ProbeConcurrency } + 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 + return nil + } +} + +// 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). +func WithResponseReadSize(responseReadSize int) NucleiSDKOptions { + return func(e *NucleiEngine) error { + if responseReadSize < 0 { + return errors.New("response read size must be non-negative") + } + e.opts.ResponseReadSize = responseReadSize return nil } }