fix test/code validation issues
This commit is contained in:
parent
738852f932
commit
85d73be641
@ -4,18 +4,19 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/chromedp/cdproto/dom"
|
||||
"github.com/chromedp/cdproto/network"
|
||||
"github.com/chromedp/chromedp"
|
||||
"github.com/geziyor/geziyor/internal"
|
||||
"golang.org/x/net/html/charset"
|
||||
"golang.org/x/text/transform"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/chromedp/cdproto/dom"
|
||||
"github.com/chromedp/cdproto/network"
|
||||
"github.com/chromedp/chromedp"
|
||||
"github.com/geziyor/geziyor/internal"
|
||||
"golang.org/x/net/html/charset"
|
||||
"golang.org/x/text/transform"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -215,10 +216,10 @@ func (c *Client) doRequestChrome(req *Request) (*Response, error) {
|
||||
}
|
||||
|
||||
// Append custom actions to default ones.
|
||||
defaultActions := append(defaultPreActions, req.Actions...)
|
||||
defaultPreActions = append(defaultPreActions, req.Actions...)
|
||||
|
||||
// Run all actions
|
||||
if err := chromedp.Run(taskCtx, defaultActions...); err != nil {
|
||||
if err := chromedp.Run(taskCtx, defaultPreActions...); err != nil {
|
||||
return nil, fmt.Errorf("request getting rendered: %w", err)
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,14 @@ package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/geziyor/geziyor/internal"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/geziyor/geziyor/internal"
|
||||
)
|
||||
|
||||
const ProxyURLKey = 0
|
||||
type ProxyURLKey int
|
||||
|
||||
type roundRobinProxy struct {
|
||||
proxyURLs []*url.URL
|
||||
@ -20,7 +21,7 @@ func (r *roundRobinProxy) GetProxy(pr *http.Request) (*url.URL, error) {
|
||||
u := r.proxyURLs[index%uint32(len(r.proxyURLs))]
|
||||
|
||||
// Set proxy url to context
|
||||
ctx := context.WithValue(pr.Context(), ProxyURLKey, u.String())
|
||||
ctx := context.WithValue(pr.Context(), ProxyURLKey(0), u.String())
|
||||
*pr = *pr.WithContext(ctx)
|
||||
return u, nil
|
||||
}
|
||||
|
@ -5,14 +5,15 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/chromedp/cdproto/dom"
|
||||
"github.com/chromedp/chromedp"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/chromedp/cdproto/dom"
|
||||
"github.com/chromedp/chromedp"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/elazarl/goproxy"
|
||||
"github.com/fortytw2/leaktest"
|
||||
@ -162,6 +163,7 @@ func TestGetRenderedCustomActions(t *testing.T) {
|
||||
g.Do(req, g.Opt.ParseFunc)
|
||||
},
|
||||
ParseFunc: func(g *geziyor.Geziyor, r *client.Response) {
|
||||
assert.Equal(t, 200, r.StatusCode)
|
||||
fmt.Println(string(r.Body))
|
||||
fmt.Println(r.Request.URL.String(), r.Header)
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user