flaresolverr

package module
v0.0.0-...-3826fdd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2023 License: GPL-3.0 Imports: 9 Imported by: 1

README

go-flaresolverr

Go client for https://github.com/FlareSolverr/FlareSolverr

Documentation

Index

Constants

View Source
const (
	// CommandSessionscreate is a command of type sessions.create.
	CommandSessionscreate command = "sessions.create"
	// CommandSessionslist is a command of type sessions.list.
	CommandSessionslist command = "sessions.list"
	// CommandSessionsdestroy is a command of type sessions.destroy.
	CommandSessionsdestroy command = "sessions.destroy"
	// CommandRequestget is a command of type request.get.
	CommandRequestget command = "request.get"
	// CommandRequestpost is a command of type request.post.
	CommandRequestpost command = "request.post"
)

Variables

View Source
var (
	// ErrRequestTimeout when timeout reached before flaresolverr can answer.
	ErrRequestTimeout = errors.New("maximum timeout reached")

	// ErrUnexpectedError .
	ErrUnexpectedError = errors.New("unexpected error from FlareSolverr server")
)
View Source
var ErrInvalidcommand = errors.New("not a valid command")

Functions

func Parsecommand

func Parsecommand(name string) (command, error)

Parsecommand attempts to convert a string to a command.

Types

type Client

type Client interface {
	// CreateSession launch a new browser instance
	// which will retain cookies until you destroy it with sessions.destroy.
	//
	// This comes in handy, so you don't have to keep solving challenges over
	// and over, and you won't need to keep sending cookies for the browser to use.
	//
	// This also speeds up the requests since it won't have to launch a new browser instance for every request.
	CreateSession(ctx context.Context, session uuid.UUID, proxy ...string) (*Response, error)
	// ListSessions Returns a list of all the active sessions.
	// More for debugging if you are curious to see how many sessions are running.
	// You should always make sure to properly close each session
	// when you are done using them as too many may slow your computer down.
	ListSessions(ctx context.Context) (*Response, error)
	// DestroySession will properly shut down a browser instance
	// and remove all files associated with it to free up resources for a new session.
	// When you no longer need to use a session you should make sure to close it.
	DestroySession(ctx context.Context, session uuid.UUID) error
	// Get makes an HTTP GET request using flaresolverr proxy
	// Session can be nil.
	Get(ctx context.Context, u string, session uuid.UUID, proxy ...string) (*Response, error)
	// Post makes an HTTP POST request using flaresolverr proxy
	// data must be an application/x-www-form-urlencoded string.
	Post(ctx context.Context, u string, session uuid.UUID, data string, proxy ...string) (*Response, error)
}

Client interface describes wrapped Flaresolverr client.

func New

func New(baseURL string, timeout time.Duration, httpClient *http.Client) Client

New creates a Flaresolverr client. Uses the default http client if not provided.

type Response

type Response struct {
	Status         string            `json:"status"`
	Message        string            `json:"message"`
	StartTimestamp int64             `json:"startTimestamp"`
	EndTimestamp   int64             `json:"endTimestamp"`
	Version        string            `json:"version"`
	Session        string            `json:"session"`
	Sessions       []uuid.UUID       `json:"sessions"`
	Solution       *ResponseSolution `json:"solution"`
}

type ResponseSolution

type ResponseSolution struct {
	URL     string `json:"url"`
	Status  int    `json:"status"`
	Headers struct {
		Status              string `json:"status"`
		Date                string `json:"date"`
		ContentType         string `json:"content-type"`
		Expires             string `json:"expires"`
		CacheControl        string `json:"cache-control"`
		Pragma              string `json:"pragma"`
		XFrameOptions       string `json:"x-frame-options"`
		XContentTypeOptions string `json:"x-content-type-options"`
		CfCacheStatus       string `json:"cf-cache-status"`
		ExpectCt            string `json:"expect-ct"`
		ReportTo            string `json:"report-to"`
		Nel                 string `json:"nel"`
		Server              string `json:"server"`
		CfRay               string `json:"cf-ray"`
		ContentEncoding     string `json:"content-encoding"`
		AltSvc              string `json:"alt-svc"`
	} `json:"headers"`
	Response string `json:"response"`
	Cookies  []struct {
		Name     string  `json:"name"`
		Value    string  `json:"value"`
		Domain   string  `json:"domain"`
		Path     string  `json:"path"`
		Expires  float64 `json:"expires"`
		Size     int     `json:"size"`
		HTTPOnly bool    `json:"httpOnly"`
		Secure   bool    `json:"secure"`
		Session  bool    `json:"session"`
		SameSite string  `json:"sameSite,omitempty"`
	} `json:"cookies"`
	UserAgent string `json:"userAgent"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL