@@ -602,8 +602,8 @@ func (c *Client) SetAuthScheme(scheme string) *Client {
602
602
//
603
603
// NOTE:
604
604
// - On the QOP `auth-int` scenario, the request body is read into memory to
605
- // compute the body hash that consumes additional memory usage.
606
- // - It is recommended to create a dedicated client instance for digest auth,
605
+ // compute the body hash that increases memory usage.
606
+ // - Create a dedicated client instance to use digest auth,
607
607
// as it does digest auth for all the requests raised by the client.
608
608
//
609
609
// [RFC 7616]: https://datatracker.ietf.org/doc/html/rfc7616
@@ -676,16 +676,12 @@ func (c *Client) NewRequest() *Request {
676
676
// SetRequestMiddlewares method allows Resty users to override the default request
677
677
// middlewares sequence
678
678
//
679
- // client := New()
680
- // defer client.Close()
681
- //
682
679
// client.SetRequestMiddlewares(
683
- // CustomRequest1Middleware,
684
- // CustomRequest2Middleware,
685
- // resty.PrepareRequestMiddleware, // after this, Request.RawRequest is available
686
- // resty.GenerateCurlRequestMiddleware,
687
- // CustomRequest3Middleware,
688
- // CustomRequest4Middleware,
680
+ // Custom1RequestMiddleware,
681
+ // Custom2RequestMiddleware,
682
+ // resty.PrepareRequestMiddleware, // after this, `Request.RawRequest` instance is available
683
+ // Custom3RequestMiddleware,
684
+ // Custom4RequestMiddleware,
689
685
// )
690
686
//
691
687
// See, [Client.AddRequestMiddleware]
@@ -703,23 +699,20 @@ func (c *Client) SetRequestMiddlewares(middlewares ...RequestMiddleware) *Client
703
699
// SetResponseMiddlewares method allows Resty users to override the default response
704
700
// middlewares sequence
705
701
//
706
- // client := New()
707
- // defer client.Close()
708
- //
709
702
// client.SetResponseMiddlewares(
710
- // CustomResponse1Middleware ,
711
- // CustomResponse2Middleware ,
712
- // resty.AutoParseResponseMiddleware, // before this, body is not read except on debug flow
713
- // CustomResponse3Middleware ,
714
- // resty.SaveToFileResponseMiddleware, // See, Request.SetOutputFile
715
- // CustomResponse4Middleware ,
716
- // CustomResponse5Middleware ,
703
+ // Custom1ResponseMiddleware ,
704
+ // Custom2ResponseMiddleware ,
705
+ // resty.AutoParseResponseMiddleware, // before this, the body is not read except on the debug flow
706
+ // Custom3ResponseMiddleware ,
707
+ // resty.SaveToFileResponseMiddleware, // See, Request.SetOutputFileName, Request.SetSaveResponse
708
+ // Custom4ResponseMiddleware ,
709
+ // Custom5ResponseMiddleware ,
717
710
// )
718
711
//
719
712
// See, [Client.AddResponseMiddleware]
720
713
//
721
714
// NOTE:
722
- // - It overwrites the existing request middleware list.
715
+ // - It overwrites the existing response middleware list.
723
716
// - Be sure to include Resty response middlewares in the response chain at the appropriate spot.
724
717
func (c * Client ) SetResponseMiddlewares (middlewares ... ResponseMiddleware ) * Client {
725
718
c .lock .Lock ()
@@ -1167,7 +1160,7 @@ func (c *Client) Timeout() time.Duration {
1167
1160
//
1168
1161
// It can be overridden at the request level. See [Request.SetTimeout]
1169
1162
//
1170
- // NOTE: Resty uses [context.WithTimeout] on the request, it does not use [http.Client.Timeout]
1163
+ // NOTE: Resty uses [context.WithTimeout] on the request, it does not use [http.Client] .Timeout
1171
1164
func (c * Client ) SetTimeout (timeout time.Duration ) * Client {
1172
1165
c .lock .Lock ()
1173
1166
defer c .lock .Unlock ()
@@ -1242,7 +1235,7 @@ func (c *Client) RetryCount() int {
1242
1235
// See [Request.SetRetryStrategy]
1243
1236
//
1244
1237
// NOTE:
1245
- // - By default, Resty only does retry on idempotent HTTP methods , [RFC 9110 Section 9.2.2], [RFC 9110 Section 18.2]
1238
+ // - By default, Resty only does retry on idempotent HTTP verb , [RFC 9110 Section 9.2.2], [RFC 9110 Section 18.2]
1246
1239
//
1247
1240
// [RFC 9110 Section 9.2.2]: https://datatracker.ietf.org/doc/html/rfc9110.html#name-idempotent-methods
1248
1241
// [RFC 9110 Section 18.2]: https://datatracker.ietf.org/doc/html/rfc9110.html#name-method-registration
@@ -1380,8 +1373,9 @@ func (c *Client) RetryConditions() []RetryConditionFunc {
1380
1373
// The request will retry if any functions return `true`, otherwise return `false`.
1381
1374
//
1382
1375
// NOTE:
1376
+ // - The default retry conditions are applied first.
1383
1377
// - The client-level retry conditions are applied to all requests.
1384
- // - The request-level retry conditions are executed first before client-level
1378
+ // - The request-level retry conditions are executed first before the client-level
1385
1379
// retry conditions. See [Request.AddRetryConditions], [Request.SetRetryConditions]
1386
1380
func (c * Client ) AddRetryConditions (conditions ... RetryConditionFunc ) * Client {
1387
1381
c .lock .Lock ()
@@ -1422,13 +1416,12 @@ func (c *Client) TLSClientConfig() *tls.Config {
1422
1416
1423
1417
// SetTLSClientConfig method sets TLSClientConfig for underlying client Transport.
1424
1418
//
1425
- // For Example:
1426
- //
1427
- // // One can set a custom root certificate. Refer: http://golang.org/pkg/crypto/tls/#example_Dial
1428
- // client.SetTLSClientConfig(&tls.Config{ RootCAs: roots })
1419
+ // Values supported by https://pkg.go.dev/crypto/tls#Config can be configured.
1429
1420
//
1430
- // // or One can disable security check (https)
1431
- // client.SetTLSClientConfig(&tls.Config{ InsecureSkipVerify: true })
1421
+ // // Disable SSL cert verification for local development
1422
+ // client.SetTLSClientConfig(&tls.Config{
1423
+ // InsecureSkipVerify: true
1424
+ // })
1432
1425
//
1433
1426
// NOTE: This method overwrites existing [http.Transport.TLSClientConfig]
1434
1427
func (c * Client ) SetTLSClientConfig (tlsConfig * tls.Config ) * Client {
@@ -1507,7 +1500,7 @@ func (c *Client) RemoveProxy() *Client {
1507
1500
return c
1508
1501
}
1509
1502
1510
- // SetCertificateFromString method helps to set client certificates into Resty
1503
+ // SetCertificateFromFile method helps to set client certificates into Resty
1511
1504
// from cert and key files to perform SSL client authentication
1512
1505
//
1513
1506
// client.SetCertificateFromFile("certs/client.pem", "certs/client.key")
@@ -1543,8 +1536,8 @@ func (c *Client) SetCertificateFromString(certStr, certKeyStr string) *Client {
1543
1536
return c
1544
1537
}
1545
1538
1546
- // SetCertificates method helps to conveniently set client certificates into Resty
1547
- // to perform SSL client authentication
1539
+ // SetCertificates method helps to conveniently set a slice of client certificates
1540
+ // into Resty to perform SSL client authentication
1548
1541
//
1549
1542
// cert, err := tls.LoadX509KeyPair("certs/client.pem", "certs/client.key")
1550
1543
// if err != nil {
@@ -1566,7 +1559,8 @@ func (c *Client) SetCertificates(certs ...tls.Certificate) *Client {
1566
1559
return c
1567
1560
}
1568
1561
1569
- // SetRootCertificates method helps to add one or more root certificates into the Resty client
1562
+ // SetRootCertificates method helps to add one or more root certificate files
1563
+ // into the Resty client
1570
1564
//
1571
1565
// // one pem file path
1572
1566
// client.SetRootCertificates("/path/to/root/pemFile.pem")
@@ -1592,14 +1586,14 @@ func (c *Client) SetRootCertificates(pemFilePaths ...string) *Client {
1592
1586
return c
1593
1587
}
1594
1588
1595
- // SetRootCertificatesWatcher method enables dynamic reloading of one or more root certificates .
1589
+ // SetRootCertificatesWatcher method enables dynamic reloading of one or more root certificate files .
1596
1590
// It is designed for scenarios involving long-running Resty clients where certificates may be renewed.
1597
1591
//
1598
1592
// client.SetRootCertificatesWatcher(
1599
1593
// &resty.CertWatcherOptions{
1600
1594
// PoolInterval: 24 * time.Hour,
1601
1595
// },
1602
- // "root-ca.crt ",
1596
+ // "root-ca.pem ",
1603
1597
// )
1604
1598
func (c * Client ) SetRootCertificatesWatcher (options * CertWatcherOptions , pemFilePaths ... string ) * Client {
1605
1599
c .SetRootCertificates (pemFilePaths ... )
@@ -1609,7 +1603,7 @@ func (c *Client) SetRootCertificatesWatcher(options *CertWatcherOptions, pemFile
1609
1603
return c
1610
1604
}
1611
1605
1612
- // SetRootCertificateFromString method helps to add one or more root certificates
1606
+ // SetRootCertificateFromString method helps to add root certificate from the string
1613
1607
// into the Resty client
1614
1608
//
1615
1609
// myRootCertStr := `-----BEGIN CERTIFICATE-----
@@ -1622,21 +1616,21 @@ func (c *Client) SetRootCertificateFromString(pemCerts string) *Client {
1622
1616
return c
1623
1617
}
1624
1618
1625
- // SetClientRootCertificates method helps to add one or more client's root
1626
- // certificates into the Resty client
1619
+ // SetClientRootCertificates method helps to add one or more client root
1620
+ // certificate files into the Resty client
1627
1621
//
1628
1622
// // one pem file path
1629
- // client.SetClientCertificates ("/path/to/client/pemFile.pem")
1623
+ // client.SetClientRootCertificates ("/path/to/client-root /pemFile.pem")
1630
1624
//
1631
1625
// // one or more pem file path(s)
1632
- // client.SetClientCertificates (
1633
- // "/path/to/client/pemFile1.pem",
1634
- // "/path/to/client/pemFile2.pem"
1635
- // "/path/to/client/pemFile3.pem"
1626
+ // client.SetClientRootCertificates (
1627
+ // "/path/to/client-root /pemFile1.pem",
1628
+ // "/path/to/client-root /pemFile2.pem"
1629
+ // "/path/to/client-root /pemFile3.pem"
1636
1630
// )
1637
1631
//
1638
1632
// // if you happen to have string slices
1639
- // client.SetClientCertificates (certs...)
1633
+ // client.SetClientRootCertificates (certs...)
1640
1634
func (c * Client ) SetClientRootCertificates (pemFilePaths ... string ) * Client {
1641
1635
for _ , fp := range pemFilePaths {
1642
1636
pemData , err := os .ReadFile (fp )
@@ -1649,14 +1643,14 @@ func (c *Client) SetClientRootCertificates(pemFilePaths ...string) *Client {
1649
1643
return c
1650
1644
}
1651
1645
1652
- // SetClientRootCertificatesWatcher method enables dynamic reloading of one or more client root certificates .
1646
+ // SetClientRootCertificatesWatcher method enables dynamic reloading of one or more client root certificate files .
1653
1647
// It is designed for scenarios involving long-running Resty clients where certificates may be renewed.
1654
1648
//
1655
1649
// client.SetClientRootCertificatesWatcher(
1656
1650
// &resty.CertWatcherOptions{
1657
1651
// PoolInterval: 24 * time.Hour,
1658
1652
// },
1659
- // "root-ca.crt ",
1653
+ // "client- root-ca.pem ",
1660
1654
// )
1661
1655
func (c * Client ) SetClientRootCertificatesWatcher (options * CertWatcherOptions , pemFilePaths ... string ) * Client {
1662
1656
c .SetClientRootCertificates (pemFilePaths ... )
@@ -1666,8 +1660,8 @@ func (c *Client) SetClientRootCertificatesWatcher(options *CertWatcherOptions, p
1666
1660
return c
1667
1661
}
1668
1662
1669
- // SetClientRootCertificateFromString method helps to add one or more clients
1670
- // root certificates into the Resty client
1663
+ // SetClientRootCertificateFromString method helps to add a client root certificate
1664
+ // from the string into the Resty client
1671
1665
//
1672
1666
// myClientRootCertStr := `-----BEGIN CERTIFICATE-----
1673
1667
// ... cert content ...
@@ -1878,12 +1872,13 @@ func (c *Client) SetCloseConnection(close bool) *Client {
1878
1872
}
1879
1873
1880
1874
// SetDoNotParseResponse method instructs Resty not to parse the response body automatically.
1875
+ //
1881
1876
// Resty exposes the raw response body as [io.ReadCloser]. If you use it, do not
1882
1877
// forget to close the body, otherwise, you might get into connection leaks, and connection
1883
1878
// reuse may not happen.
1884
1879
//
1885
- // NOTE: [Response] middlewares are not executed using this option. You have
1886
- // taken over the control of response parsing from Resty.
1880
+ // NOTE: The default [Response] middlewares are not executed when using this option. User
1881
+ // takes over the control of handling response body from Resty.
1887
1882
func (c * Client ) SetDoNotParseResponse (notParse bool ) * Client {
1888
1883
c .lock .Lock ()
1889
1884
defer c .lock .Unlock ()
@@ -2074,7 +2069,8 @@ func (c *Client) SetTrace(t bool) *Client {
2074
2069
// client instance level.
2075
2070
//
2076
2071
// By default, Resty does not log the curl command in the debug log since it has the potential
2077
- // to leak sensitive data unless explicitly enabled via [Client.SetDebugLogCurlCmd].
2072
+ // to leak sensitive data unless explicitly enabled via [Client.SetDebugLogCurlCmd] or
2073
+ // [Request.SetDebugLogCurlCmd].
2078
2074
//
2079
2075
// NOTE: Use with care.
2080
2076
// - Potential to leak sensitive data from [Request] and [Response] in the debug log
@@ -2097,7 +2093,8 @@ func (c *Client) DisableGenerateCurlCmd() *Client {
2097
2093
// client instance level.
2098
2094
//
2099
2095
// By default, Resty does not log the curl command in the debug log since it has the potential
2100
- // to leak sensitive data unless explicitly enabled via [Client.SetDebugLogCurlCmd].
2096
+ // to leak sensitive data unless explicitly enabled via [Client.SetDebugLogCurlCmd] or
2097
+ // [Request.SetDebugLogCurlCmd].
2101
2098
//
2102
2099
// NOTE: Use with care.
2103
2100
// - Potential to leak sensitive data from [Request] and [Response] in the debug log
@@ -2143,7 +2140,7 @@ func (c *Client) ResponseBodyUnlimitedReads() bool {
2143
2140
return c .resBodyUnlimitedReads
2144
2141
}
2145
2142
2146
- // SetResponseBodyUnlimitedReads method is to turn on/off the response body copy
2143
+ // SetResponseBodyUnlimitedReads method is to turn on/off the response body in memory
2147
2144
// that provides an ability to do unlimited reads.
2148
2145
//
2149
2146
// It can be overridden at the request level; see [Request.SetResponseBodyUnlimitedReads]
@@ -2152,7 +2149,7 @@ func (c *Client) ResponseBodyUnlimitedReads() bool {
2152
2149
// - When debug mode is enabled
2153
2150
//
2154
2151
// NOTE: Use with care
2155
- // - Turning on this feature uses additional memory to store a copy of the response body buffer .
2152
+ // - Turning on this feature keeps the response body in memory, which might cause additional memory usage .
2156
2153
func (c * Client ) SetResponseBodyUnlimitedReads (b bool ) * Client {
2157
2154
c .lock .Lock ()
2158
2155
defer c .lock .Unlock ()
@@ -2179,7 +2176,8 @@ func (c *Client) Client() *http.Client {
2179
2176
// - Interface values are not deeply cloned. Thus, both the original and the
2180
2177
// clone will use the same value.
2181
2178
// - It is not safe for concurrent use. You should only use this method
2182
- // when you are sure that any other concurrent process is not using the client.
2179
+ // when you are sure that any other concurrent process is not using the client
2180
+ // or client instance is protected by a mutex.
2183
2181
func (c * Client ) Clone (ctx context.Context ) * Client {
2184
2182
cc := new (Client )
2185
2183
// dereference the pointer and copy the value
0 commit comments