Skip to content

Commit 5797fa0

Browse files
committed
Improvements
1 parent 936a740 commit 5797fa0

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<p align="center"><a href="#readme"><img src="https://gh.kaos.st/sslscan.svg"/></a></p>
22

33
<p align="center">
4-
<a href="https://pkg.go.dev/pkg.re/essentialkaos/sslscan.v12"><img src="https://gh.kaos.st/godoc.svg" alt="PkgGoDev"></a>
4+
<a href="https://pkg.re/essentialkaos/sslscan.v13?docs"><img src="https://gh.kaos.st/godoc.svg" alt="PkgGoDev"></a>
55
<a href="https://goreportcard.com/report/github.com/essentialkaos/sslscan"><img src="https://goreportcard.com/badge/github.com/essentialkaos/sslscan"></a>
66
<a href="https://codebeat.co/projects/github-com-essentialkaos-sslscan"><img src="https://codebeat.co/badges/59a17b0e-b974-425e-a442-b9bcc3ccf7c0"></a>
77
<a href="https://github.com/essentialkaos/sslscan/actions"><img src="https://github.com/essentialkaos/sslscan/workflows/CI/badge.svg" alt="GitHub Actions Status" /></a>
@@ -20,13 +20,13 @@ Package for Go for working with [SSLLabs](https://www.ssllabs.com) public API.
2020
To build the SSLScan from scratch, make sure you have a working Go 1.14+ workspace ([instructions](https://golang.org/doc/install)), then:
2121

2222
```
23-
go get pkg.re/essentialkaos/sslscan.v12
23+
go get pkg.re/essentialkaos/sslscan.v13
2424
```
2525

2626
If you want update SSLScan package to latest stable release, do:
2727

2828
```
29-
go get -u pkg.re/essentialkaos/sslscan.v12
29+
go get -u pkg.re/essentialkaos/sslscan.v13
3030
```
3131

3232
### Build Status

sslscan.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,14 @@ const (
149149
)
150150

151151
// VERSION is current package version
152-
const VERSION = "12.0.0"
152+
const VERSION = "13.0.0"
153153

154154
// ////////////////////////////////////////////////////////////////////////////////// //
155155

156156
type API struct {
157-
Info *Info
158-
Client *fasthttp.Client
157+
RequestTimeout time.Duration
158+
Info *Info
159+
Client *fasthttp.Client
159160
}
160161

161162
type AnalyzeParams struct {
@@ -506,8 +507,21 @@ type HTTPHeader struct {
506507
Value string `json:"value"`
507508
}
508509

509-
// RequestTimeout is request timeout in seconds
510-
var RequestTimeout = 10.0
510+
// ////////////////////////////////////////////////////////////////////////////////// //
511+
512+
type HTTPError struct {
513+
StatusCode int
514+
ResponseData string
515+
}
516+
517+
func (e *HTTPError) Error() string {
518+
return fmt.Sprintf("API returned HTTP code %d", e.StatusCode)
519+
}
520+
521+
// ////////////////////////////////////////////////////////////////////////////////// //
522+
523+
// RequestTimeout is default request timeout
524+
var RequestTimeout = 10 * time.Second
511525

512526
// ////////////////////////////////////////////////////////////////////////////////// //
513527

@@ -518,11 +532,10 @@ func NewAPI(app, version string) (*API, error) {
518532
}
519533

520534
api := &API{
535+
RequestTimeout: RequestTimeout,
521536
Client: &fasthttp.Client{
522537
Name: getUserAgent(app, version),
523538
MaxIdleConnDuration: 5 * time.Second,
524-
ReadTimeout: time.Duration(RequestTimeout) * time.Second,
525-
WriteTimeout: time.Duration(RequestTimeout) * time.Second,
526539
MaxConnsPerHost: 100,
527540
},
528541
}
@@ -624,6 +637,8 @@ func (ap *AnalyzeProgress) GetEndpointInfo(ip string, fromCache bool) (*Endpoint
624637

625638
// doRequest sends request through http client
626639
func (api *API) doRequest(uri string, result interface{}) error {
640+
var err error
641+
627642
req := fasthttp.AcquireRequest()
628643
resp := fasthttp.AcquireResponse()
629644

@@ -632,7 +647,11 @@ func (api *API) doRequest(uri string, result interface{}) error {
632647
defer fasthttp.ReleaseRequest(req)
633648
defer fasthttp.ReleaseResponse(resp)
634649

635-
err := api.Client.Do(req, resp)
650+
if api.RequestTimeout == 0 {
651+
err = api.Client.Do(req, resp)
652+
} else {
653+
err = api.Client.DoTimeout(req, resp, api.RequestTimeout)
654+
}
636655

637656
if err != nil {
638657
return err
@@ -641,7 +660,7 @@ func (api *API) doRequest(uri string, result interface{}) error {
641660
statusCode := resp.StatusCode()
642661

643662
if statusCode != 200 {
644-
return fmt.Errorf("API return HTTP code %d", statusCode)
663+
return &HTTPError{StatusCode: statusCode, ResponseData: resp.String()}
645664
}
646665

647666
if result == nil {

sslscan_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
// ////////////////////////////////////////////////////////////////////////////////// //
1919

20-
const _TESTER_VERSION = "9.0.0"
20+
const _TESTER_VERSION = "10.0.0"
2121

2222
// ////////////////////////////////////////////////////////////////////////////////// //
2323

@@ -34,7 +34,7 @@ var _ = check.Suite(&SSLLabsSuite{})
3434
func (s *SSLLabsSuite) TestInfo(c *check.C) {
3535
api, err := NewAPI("SSLScanTester", _TESTER_VERSION)
3636

37-
RequestTimeout = 3.0
37+
api.RequestTimeout = 5 * time.Second
3838

3939
c.Assert(err, check.IsNil)
4040
c.Assert(api, check.NotNil)
@@ -46,7 +46,7 @@ func (s *SSLLabsSuite) TestInfo(c *check.C) {
4646
func (s *SSLLabsSuite) TestAnalyze(c *check.C) {
4747
api, err := NewAPI("SSLScanTester", _TESTER_VERSION)
4848

49-
RequestTimeout = 3.0
49+
api.RequestTimeout = 5 * time.Second
5050

5151
c.Assert(err, check.IsNil)
5252
c.Assert(api, check.NotNil)

0 commit comments

Comments
 (0)