/
curl.go
66 lines (50 loc) · 1.48 KB
/
curl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package trans
import (
"context"
"net/http"
"github.com/0x726f6f6b6965/go-curl/filetype"
)
type curlRequest struct {
ctx context.Context
request *http.Request
cmd []string
filename string
cleanup func() error
private *privatekey
cert *certificate
ca string
combinedOutput func(ctx context.Context, name string, args ...string) ([]byte, error)
}
type CurlRequest interface {
// GenerateCommand - generate curl command with curl request
GenerateCommand(inscure bool) error
// GetCommands - get the curl command
GetCommands() []string
// GetFilename - get the filename which contains the request body
GetFilename() string
// Execute - execute the curl command
Execute() ([]byte, error)
// Do - execute the curl command and get the http.Response, like http.client.Do
Do() (*http.Response, error)
// AddHeader - add curl header
AddHeader(key, value string) error
// GetHeaders - get all the curl headers
GetHeaders() http.Header
// GetHeader - get the specific header value
GetHeader(key string) []string
// SetPrivateKey - set the private key
SetPrivateKey(fileType filetype.FileType, path string)
// SetCertificate - set the certificate
SetCertificate(fileType filetype.FileType, path, password string)
// SetCA - set the ca file
SetCA(filePath string)
}
type privatekey struct {
fileType string
path string
}
type certificate struct {
fileType string
path string
password string
}