Skip to content

Commit

Permalink
Merge pull request #45 from sfunkhouser/disablekeepalive
Browse files Browse the repository at this point in the history
Add option to disablekeepalive
  • Loading branch information
cheynearista authored Jul 14, 2021
2 parents 3dab8e0 + ad9d3ef commit 340b280
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions eapilib.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,22 @@ import (
type EapiConnectionEntity interface {
Execute(commands []interface{}, encoding string) (*JSONRPCResponse, error)
SetTimeout(to uint32)
SetDisableKeepAlive(disableKeepAlive bool)
Error() error
}

// EapiConnection represents the base object for implementing an EapiConnection
// type. This clase should not be instantiated directly
type EapiConnection struct {
transport string
err error
url string
host string
port int
path string
auth *url.Userinfo
timeOut uint32
transport string
err error
url string
host string
port int
path string
auth *url.Userinfo
timeOut uint32
disableKeepAlive bool
}

// Execute the list of commands on the destination node. In the case of
Expand Down Expand Up @@ -154,6 +156,11 @@ func (conn *EapiConnection) SetTimeout(timeOut uint32) {
conn.timeOut = val
}

// SetDisableKeepAlive sets disablekeepalive value for Connection
func (conn *EapiConnection) SetDisableKeepAlive(disableKeepAlive bool) {
conn.disableKeepAlive = disableKeepAlive
}

// buildJSONRequest builds a JSON request given a list of commands, encoding
// type of either json or text, and request id. The command list input is made
// up of a list of interface{} types. This is so associative entries and list
Expand Down Expand Up @@ -388,7 +395,7 @@ func NewHTTPEapiConnection(transport string, host string, username string,
if port == UseDefaultPortNum {
port = DefaultHTTPPort
}
conn := EapiConnection{transport: transport, host: host, port: port, timeOut: 60}
conn := EapiConnection{transport: transport, host: host, port: port, timeOut: 60, disableKeepAlive: false}
conn.Authentication(username, password)
return &HTTPEapiConnection{conn}
}
Expand All @@ -410,9 +417,14 @@ func (conn *HTTPEapiConnection) send(data []byte) (*JSONRPCResponse, error) {
return &JSONRPCResponse{}, fmt.Errorf("No Connection")
}

tr := &http.Transport{
DisableKeepAlives: conn.disableKeepAlive,
}

timeOut := time.Duration(time.Duration(conn.timeOut) * time.Second)
client := &http.Client{
Timeout: timeOut,
Timeout: timeOut,
Transport: tr,
}
url := conn.getURL()
resp, err := client.Post(url, "application/json", bytes.NewReader(data))
Expand Down Expand Up @@ -499,7 +511,7 @@ func NewHTTPSEapiConnection(transport string, host string, username string,
}
path := DefaultHTTPSPath

conn := EapiConnection{transport: transport, host: host, port: port, timeOut: 60}
conn := EapiConnection{transport: transport, host: host, port: port, timeOut: 60, disableKeepAlive: false}

conn.Authentication(username, password)
return &HTTPSEapiConnection{path: path, EapiConnection: conn}
Expand All @@ -524,7 +536,8 @@ func (conn *HTTPSEapiConnection) send(data []byte) (*JSONRPCResponse, error) {
timeOut := time.Duration(time.Duration(conn.timeOut) * time.Second)
url := conn.getURL()
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DisableKeepAlives: conn.disableKeepAlive,
}
client := &http.Client{
Timeout: timeOut,
Expand Down

0 comments on commit 340b280

Please sign in to comment.