harparser

package module
v0.0.0-...-e602e13 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

HAR Parser

A packcage that makes easier to parse requests using one click in DevTools. No need for dumping browsers, one click and you are done :).

Install

go get github.com/Wowkoltyy/harparser

Example

package main

import (
	"fmt"
	"github.com/Wowkoltyy/harparser"
)

func main() {
  // parse from curl (DevTools: Copy request as CURL) file
	curl, err := harparser.ParseCURLFile("./assets/request.sh")
	if err != nil {
		panic(err)
	}
	fmt.Println(curl)
  // parse from .HAR file
	har, err := harparser.ParseHARFile("./assets/request.har", curl.URL.String())
	if err != nil {
		panic(err)
	}
	fmt.Println(har)

	fmt.Println(har.ChromeVersion)
	fmt.Println(curl.ChromeVersion)

  // you can also parse bytes

  curl2, err := harparser.ParseCURL([]byte("curl 'https://google.com' \\\n -H 'User-Agent: Mozilla/5.0'"))
	if err != nil {
		panic(err)
	}
	fmt.Println(curl2)

  // should return error, because har is empty
	har2, err := harparser.ParseRequestFromHAR([]byte("{}"), "https://google.com")
	if err == nil {
		panic(har2)
	}
	fmt.Println("err:", err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseCookies

func ParseCookies(rawCookies string) []*http.Cookie

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

func NewErr

func NewErr(err string) *Error

func (*Error) Error

func (e *Error) Error() string

type HAR

type HAR struct {
	Log struct {
		Version string `json:"version"`
		Creator struct {
			Name    string `json:"name"`
			Version string `json:"version"`
		} `json:"creator"`
		Pages   []interface{} `json:"pages"`
		Entries []struct {
			Initiator *struct {
				Type  string `json:"type"`
				Stack struct {
					CallFrames []struct {
						FunctionName string `json:"functionName"`
						ScriptId     string `json:"scriptId"`
						Url          string `json:"url"`
						LineNumber   int    `json:"lineNumber"`
						ColumnNumber int    `json:"columnNumber"`
					} `json:"callFrames"`
				} `json:"stack"`
			} `json:"_initiator"`
			Priority     string `json:"_priority"`
			ResourceType string `json:"_resourceType"`
			Cache        *struct {
			} `json:"cache"`
			Connection string `json:"connection"`
			Request    *struct {
				Method      string `json:"method"`
				Url         string `json:"url"`
				HttpVersion string `json:"httpVersion"`
				Headers     []struct {
					Name  string `json:"name"`
					Value string `json:"value"`
				} `json:"headers"`
				QueryString []interface{} `json:"queryString"`
				Cookies     []*struct {
					Name     string    `json:"name"`
					Value    string    `json:"value"`
					Path     string    `json:"path"`
					Domain   string    `json:"domain"`
					Expires  time.Time `json:"expires"`
					HttpOnly bool      `json:"httpOnly"`
					Secure   bool      `json:"secure"`
					SameSite string    `json:"sameSite"`
				} `json:"cookies"`
				HeadersSize int `json:"headersSize"`
				BodySize    int `json:"bodySize"`
				PostData    *struct {
					MimeType string `json:"mimeType"`
					Text     string `json:"text"`
				} `json:"postData"`
			} `json:"request"`
			Response *struct {
				Status      int    `json:"status"`
				StatusText  string `json:"statusText"`
				HttpVersion string `json:"httpVersion"`
				Headers     []struct {
					Name  string `json:"name"`
					Value string `json:"value"`
				} `json:"headers"`
				Cookies []struct {
					Name     string    `json:"name"`
					Value    string    `json:"value"`
					Path     string    `json:"path"`
					Domain   string    `json:"domain"`
					Expires  time.Time `json:"expires"`
					HttpOnly bool      `json:"httpOnly"`
					Secure   bool      `json:"secure"`
					SameSite string    `json:"sameSite"`
				} `json:"cookies"`
				Content *struct {
					Size     int    `json:"size"`
					MimeType string `json:"mimeType"`
					Text     string `json:"text"`
				} `json:"content"`
				RedirectURL  string      `json:"redirectURL"`
				HeadersSize  int         `json:"headersSize"`
				BodySize     int         `json:"bodySize"`
				TransferSize int         `json:"_transferSize"`
				Error        interface{} `json:"_error"`
			} `json:"response"`
			ServerIPAddress string      `json:"serverIPAddress"`
			StartedDateTime interface{} `json:"startedDateTime"`
			Time            float32     `json:"time"`
			Timings         struct {
				Blocked         float32 `json:"blocked"`
				Dns             float32 `json:"dns"`
				Ssl             float32 `json:"ssl"`
				Connect         float32 `json:"connect"`
				Send            float32 `json:"send"`
				Wait            float32 `json:"wait"`
				Receive         float32 `json:"receive"`
				BlockedQueueing float32 `json:"_blocked_queueing"`
			} `json:"timings"`
		} `json:"entries"`
	} `json:"log"`
}

type HAREntry

type HAREntry struct {
	HARRequest  *HARRequest
	HARResponse *HARResponse
}

type HARRequest

type HARRequest struct {
	Method   string
	URL      string
	Headers  http.Header
	PostData string
}

type HARResponse

type HARResponse struct {
	Content  string
	MimeType string
}

type ParsedHAR

type ParsedHAR []HAREntry

func ParseFullHARFile

func ParseFullHARFile(path string) (ParsedHAR, error)

func ParseHAR

func ParseHAR(data []byte) (ParsedHAR, error)

type RequestInfo

type RequestInfo struct {
	URL           *url.URL
	Header        http.Header
	XHeader       http.Header
	Cookies       []*http.Cookie
	UserAgent     useragent.UserAgent
	ChromeVersion int
}

func ParseCURL

func ParseCURL(data []byte) (*RequestInfo, error)

func ParseCURLFile

func ParseCURLFile(path string) (*RequestInfo, error)

func ParseHARFile

func ParseHARFile(path, requestUrl string) (*RequestInfo, error)

func ParseRequestFromHAR

func ParseRequestFromHAR(data []byte, requestUrl string) (*RequestInfo, error)

ParseRequestFromHAR Parses request given from HAR reader and returns the request by requestUrl info

Jump to

Keyboard shortcuts

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