From 3dceb6412a7450d9004762c5ed4b55e56ade209c Mon Sep 17 00:00:00 2001 From: Arsham Date: Fri, 30 Aug 2024 18:25:43 +0330 Subject: [PATCH] add:set headers & update:transport skip verify --- headers.go | 32 ++++++++++++++++++++++++++++++++ transport.go | 4 ++-- utils.go | 3 +++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 headers.go create mode 100644 utils.go diff --git a/headers.go b/headers.go new file mode 100644 index 0000000..353ba2c --- /dev/null +++ b/headers.go @@ -0,0 +1,32 @@ +package scrapify + +import "net/http" + +var defaultHeaders = map[string]string{ + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "en-US,en;q=0.9", + "Cache-Control": "no-cache", + "Connection": "keep-alive", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0", + "Upgrade-Insecure-Requests": "1", + "sec-ch-ua": `"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"`, + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": "Windows", + "sec-fetch-user": "?1", + "sec-fetch-dest": "empty", + "sec-fetch-mode": "cors", + "sec-fetch-site": "same-origin", + "Priority": "u=0, i", +} + +func SetHeaders(req *http.Request, headers M) { + for k, v := range defaultHeaders { + req.Header.Set(k, v) + } + if headers != nil { + for k, v := range headers { + req.Header.Set(k, v) + } + } +} diff --git a/transport.go b/transport.go index a465f90..6ab80d2 100644 --- a/transport.go +++ b/transport.go @@ -5,12 +5,12 @@ import ( "net/http" ) -func NewTransport(browser Browser, debug bool) http.RoundTripper { +func NewTransport(browser Browser) http.RoundTripper { tlsConfig := &tls.Config{ MinVersion: tls.VersionTLS12, MaxVersion: tls.VersionTLS13, CipherSuites: MapBrowserToCipher[browser], - InsecureSkipVerify: debug, + InsecureSkipVerify: true, } return &http.Transport{ TLSClientConfig: tlsConfig, diff --git a/utils.go b/utils.go new file mode 100644 index 0000000..507dcc2 --- /dev/null +++ b/utils.go @@ -0,0 +1,3 @@ +package scrapify + +type M map[string]string