From 03c5a5a20f802f0f852179e83e621f59232d1f7d Mon Sep 17 00:00:00 2001 From: Shinku <17696928+Shinku-Chen@users.noreply.github.com> Date: Fri, 25 Oct 2024 16:29:50 +0800 Subject: [PATCH 1/2] Fix export CreateFormReader function --- colly.go | 6 +++--- request.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/colly.go b/colly.go index ae74b7c3..e769f083 100644 --- a/colly.go +++ b/colly.go @@ -539,7 +539,7 @@ func (c *Collector) Head(URL string) error { // Post starts a collector job by creating a POST request. // Post also calls the previously provided callbacks func (c *Collector) Post(URL string, requestData map[string]string) error { - return c.scrape(URL, "POST", 1, createFormReader(requestData), nil, nil, true) + return c.scrape(URL, "POST", 1, CreateFormReader(requestData), nil, nil, true) } // PostRaw starts a collector job by creating a POST request with raw binary data. @@ -1425,7 +1425,7 @@ func (c *Collector) parseSettingsFromEnv() { } func (c *Collector) checkHasVisited(URL string, requestData map[string]string) (bool, error) { - hash := requestHash(URL, createFormReader(requestData)) + hash := requestHash(URL, CreateFormReader(requestData)) return c.store.IsVisited(hash) } @@ -1444,7 +1444,7 @@ func SanitizeFileName(fileName string) string { ), "-", "_", -1) } -func createFormReader(data map[string]string) io.Reader { +func CreateFormReader(data map[string]string) io.Reader { form := url.Values{} for k, v := range data { form.Add(k, v) diff --git a/request.go b/request.go index 5c80e2bb..fe4d71e3 100644 --- a/request.go +++ b/request.go @@ -128,7 +128,7 @@ func (r *Request) HasVisited(URL string) (bool, error) { // of the previous request. // Post also calls the previously provided callbacks func (r *Request) Post(URL string, requestData map[string]string) error { - return r.collector.scrape(r.AbsoluteURL(URL), "POST", r.Depth+1, createFormReader(requestData), r.Ctx, nil, true) + return r.collector.scrape(r.AbsoluteURL(URL), "POST", r.Depth+1, CreateFormReader(requestData), r.Ctx, nil, true) } // PostRaw starts a collector job by creating a POST request with raw binary data. From fad6e9637ce59db43fd744cd1d15e0da935c251a Mon Sep 17 00:00:00 2001 From: Shinku <17696928+Shinku-Chen@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:35:36 +0800 Subject: [PATCH 2/2] Fix export CreateFormReader function --- colly.go | 1 + 1 file changed, 1 insertion(+) diff --git a/colly.go b/colly.go index e769f083..83fc3403 100644 --- a/colly.go +++ b/colly.go @@ -1444,6 +1444,7 @@ func SanitizeFileName(fileName string) string { ), "-", "_", -1) } +// CreateFormReader creates a form reader from a map. func CreateFormReader(data map[string]string) io.Reader { form := url.Values{} for k, v := range data {