Skip to content

Commit

Permalink
Add exported go function "cycletls.NewTransport()" to return a custom…
Browse files Browse the repository at this point in the history
… http.Client transport, for use with a custom http.client. (#286)
  • Loading branch information
deoxykev committed Nov 28, 2023
1 parent 963daac commit 4df48e6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,27 @@ func main() {

```

## Example using your own custom http.Client

```go
import (
"github.com/Danny-Dasilva/CycleTLS/cycletls"
http "github.com/Danny-Dasilva/fhttp" // note this is a drop-in replacement for net/http
)

func main() {
ja3 := "771,52393-52392-52244-52243-49195-49199-49196-49200-49171-49172-156-157-47-53-10,65281-0-23-35-13-5-18-16-30032-11-10,29-23-24,0"
ua := "Chrome Version 57.0.2987.110 (64-bit) Linux"

cycleClient := &http.Client{
Transport: cycletls.NewTransport(ja3, ua),
}

resp, err := cycleClient.Get("https://tls.peet.ws/")
...
}
```

## Creating an instance

In order to create a `cycleTLS` instance, you can run the following:
Expand Down
34 changes: 34 additions & 0 deletions cycletls/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,40 @@ func clientBuilder(browser browser, dialer proxy.ContextDialer, timeout int, dis
return client
}

// NewTransport creates a new HTTP client transport that modifies HTTPS requests
// to imitiate a specific JA3 hash and User-Agent.
// # Example Usage
// import (
//
// "github.com/Danny-Dasilva/CycleTLS/cycletls"
// http "github.com/Danny-Dasilva/fhttp" // note this is a drop-in replacement for net/http
//
// )
//
// ja3 := "771,52393-52392-52244-52243-49195-49199-49196-49200-49171-49172-156-157-47-53-10,65281-0-23-35-13-5-18-16-30032-11-10,29-23-24,0"
// ua := "Chrome Version 57.0.2987.110 (64-bit) Linux"
//
// cycleClient := &http.Client{
// Transport: cycletls.NewTransport(ja3, ua),
// }
//
// cycleClient.Get("https://tls.peet.ws/")
func NewTransport(ja3 string, useragent string) http.RoundTripper {
return newRoundTripper(browser{
JA3: ja3,
UserAgent: useragent,
})
}

// NewTransport creates a new HTTP client transport that modifies HTTPS requests
// to imitiate a specific JA3 hash and User-Agent, optionally specifying a proxy via proxy.ContextDialer.
func NewTransportWithProxy(ja3 string, useragent string, proxy proxy.ContextDialer) http.RoundTripper {
return newRoundTripper(browser{
JA3: ja3,
UserAgent: useragent,
}, proxy)
}

// newClient creates a new http client
func newClient(browser browser, timeout int, disableRedirect bool, UserAgent string, proxyURL ...string) (http.Client, error) {
var dialer proxy.ContextDialer
Expand Down

0 comments on commit 4df48e6

Please sign in to comment.