Skip to content

Commit

Permalink
add cookie JSESSIONIDSSO (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
aburtasov authored Nov 11, 2024
1 parent 1c235f2 commit c79f636
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtX
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
23 changes: 20 additions & 3 deletions performance_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"crypto/tls"
"encoding/xml"
"fmt"
log "github.com/sirupsen/logrus"
"net/http"
"net/http/cookiejar"
"time"

log "github.com/sirupsen/logrus"
)

// ApiMonitorClient API client
Expand All @@ -22,20 +24,23 @@ type ApiMonitorClient struct {
// NewApiMonitorClient create new API client with prepared http.Client
func NewApiMonitorClient() *ApiMonitorClient {
var cp ApiMonitorClient

jar, _ := cookiejar.New(nil)

if config.IgnoreCertificate {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
cp = ApiMonitorClient{
client: &http.Client{Transport: tr},
client: &http.Client{Transport: tr, Jar: jar},
requests: 0,
responses: 0,
responseErrors: 0,
session: "",
}
} else {
cp = ApiMonitorClient{
client: &http.Client{},
client: &http.Client{Jar: jar},
requests: 0,
responses: 0,
responseErrors: 0,
Expand All @@ -61,9 +66,11 @@ func (p *ApiMonitorClient) processRequest(name string, inner string) (body strin
log.WithFields(p.logFields(name)).Errorf("problem prepare %s request. Error: %s", name, err)
return "", err
}

ctx, cancel := context.WithTimeout(context.Background(), time.Duration(config.ApiTimeout)*time.Second)
defer cancel()
req = req.WithContext(ctx)

body, resp, err = perfRequestResponse(requestId, p.client, req)
if resp != nil && resp.StatusCode > 299 {
log.WithFields(p.logFields(name)).Errorf("problem read %s response. Status code: %s", name, resp.Status)
Expand All @@ -81,6 +88,16 @@ func (p *ApiMonitorClient) processRequest(name string, inner string) (body strin
p.responseErrors++
return "", err
}

for _, cookie := range resp.Cookies() {
if cookie.Name == "JSESSIONIDSSO" {
p.session = cookie.Value
log.WithFields(p.logFields(name)).Debugf("JSESSIONIDSSO cookie received and stored: %s", p.session)
break
}
log.WithFields(p.logFields(name)).Debugf("no cookie JSESSIONIDSSO")
}

p.responses++
body, err = perfRequestBodyRelevant(body)
if err != nil {
Expand Down

0 comments on commit c79f636

Please sign in to comment.