Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny-Dasilva committed Oct 16, 2023
1 parent e933993 commit 24d4a21
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 39 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/test_golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ jobs:
working-directory: ./cycletls
run: go test --race -v ./...

- name: Start SOCKS5 Proxy (only on ubuntu)
if: matrix.platform == 'ubuntu-latest'
run: |
docker run -d -p 1087:1080 rofl0r/microsocks -i 0.0.0.0 -u abc -P 123
- name: Integration Tests
working-directory: ./cycletls
run: go test --race -v -tags=integration ./...
run: go test --race -v -tags=integration ./...
24 changes: 8 additions & 16 deletions cycletls/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,20 @@ func clientBuilder(browser browser, dialer proxy.ContextDialer, timeout int, dis

// newClient creates a new http client
func newClient(browser browser, timeout int, disableRedirect bool, UserAgent string, proxyURL ...string) (http.Client, error) {
//fix check PR
var dialer proxy.ContextDialer
// Check if a valid proxyURL is provided.
if len(proxyURL) > 0 && len(proxyURL[0]) > 0 {
dialer, err := newConnectDialer(proxyURL[0], UserAgent)
var err error
dialer, err = newConnectDialer(proxyURL[0], UserAgent)
if err != nil {
return http.Client{
Timeout: time.Duration(timeout) * time.Second,
CheckRedirect: disabledRedirect, //fix this fallthrough issue (test for incorrect proxy)
CheckRedirect: disabledRedirect,
}, err
}
return clientBuilder(
browser,
dialer,
timeout,
disableRedirect,
), nil
} else {
dialer = proxy.Direct
}

return clientBuilder(
browser,
proxy.Direct,
timeout,
disableRedirect,
), nil

return clientBuilder(browser, dialer, timeout, disableRedirect), nil
}
2 changes: 1 addition & 1 deletion cycletls/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func newConnectDialer(proxyURLStr string, UserAgent string) (proxy.ContextDialer
}
dialSocksProxy, err := proxy.SOCKS5("tcp", proxyURL.Host, auth, nil)
if err != nil {
return nil, errors.New(fmt.Sprintf("Error creating SOCKS5 proxy, reason %s", err))
return nil, fmt.Errorf("Error creating SOCKS5 proxy, reason %s", err)
}
if contextDialer, ok := dialSocksProxy.(proxy.ContextDialer); ok {
client.Dialer = contextDialer
Expand Down
2 changes: 1 addition & 1 deletion cycletls/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type data struct {
// HTTP response or the Cookie header of an HTTP request.
//
// See https://tools.ietf.org/html/rfc6265 for details.
//Stolen from Net/http/cookies
// Stolen from Net/http/cookies
type Cookie struct {
Name string `json:"name"`
Value string `json:"value"`
Expand Down
1 change: 1 addition & 0 deletions cycletls/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ var upgrader = websocket.Upgrader{
WriteBufferSize: 1024,
}

// WSEndpoint exports the main cycletls function as we websocket connection that clients can connect to
func WSEndpoint(w nhttp.ResponseWriter, r *nhttp.Request) {
upgrader.CheckOrigin = func(r *nhttp.Request) bool { return true }

Expand Down
22 changes: 22 additions & 0 deletions cycletls/tests/integration/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,26 @@ func TestFileWriting(t *testing.T) {
if filesEqual != true {
t.Fatal("Files are not equal", "webp")
}

//gif
resp = GetRequest("https://upload.wikimedia.org/wikipedia/commons/b/b1/Loading_icon.gif", client)
if resp.Status != 200 {
t.Fatalf("Expected %d Got %d for Status", 200, resp.Status)
}
WriteFile(resp.Body, "../../../tests/images/source.gif")
filesEqual = CompareFiles("../../../tests/images/test.gif", "../../../tests/images/source.gif")
if filesEqual != true {
t.Fatal("Files are not equal", "gif")
}

//webp
resp = GetRequest("https://images.unsplash.com/photo-1608481337062-4093bf3ed404", client)
if resp.Status != 200 {
t.Fatalf("Expected %d Got %d for Status", 200, resp.Status)
}
WriteFile(resp.Body, "../../../tests/images/source.avif")
filesEqual = CompareFiles("../../../tests/images/test.avif", "../../../tests/images/source.avif")
if filesEqual != true {
t.Fatal("Files are not equal", "avif")
}
}
40 changes: 20 additions & 20 deletions cycletls/tests/integration/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestProxySuccess(t *testing.T) {

client := cycletls.Init()
resp, err := client.Do("https://ipinfo.io/", cycletls.Options{
resp, err := client.Do("https://ipinfo.io/json", cycletls.Options{
Body: "",
Ja3: "771,4865-4867-4866-49195-49199-52393-52392-49196-49200-49162-49161-49171-49172-51-57-47-53-10,0-23-65281-10-11-35-16-5-51-43-13-45-28-21,29-23-24-25-256-257,0",
UserAgent: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0",
Expand All @@ -31,22 +31,22 @@ func TestProxySuccess(t *testing.T) {
log.Print("Body: " + resp.Body)
}

func TestHttpError(t *testing.T) {

client := cycletls.Init()
resp, err := client.Do("https://ipinfo.io/", cycletls.Options{
Body: "",
Ja3: "771,4865-4867-4866-49195-49199-52393-52392-49196-49200-49162-49161-49171-49172-51-57-47-53-10,0-23-65281-10-11-35-16-5-51-43-13-45-28-21,29-23-24-25-256-257,0",
UserAgent: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0",
Proxy: "http://127.0.0.1:10809",
Headers: map[string]string{
"Accept": "Application/json, text/plain, */*",
},
}, "GET")
if err != nil {
log.Print("Request Failed: " + err.Error())
}
log.Print("Status: " + strconv.Itoa(resp.Status))
log.Print("Body: " + resp.Body)

}
// func TestHttpError(t *testing.T) {

// client := cycletls.Init()
// resp, err := client.Do("https://ipinfo.io/json", cycletls.Options{
// Body: "",
// Ja3: "771,4865-4867-4866-49195-49199-52393-52392-49196-49200-49162-49161-49171-49172-51-57-47-53-10,0-23-65281-10-11-35-16-5-51-43-13-45-28-21,29-23-24-25-256-257,0",
// UserAgent: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0",
// Proxy: "http://127.0.0.1:10809",
// Headers: map[string]string{
// "Accept": "Application/json, text/plain, */*",
// },
// }, "GET")
// if err != nil {
// log.Print("Request Failed: " + err.Error())
// }
// log.Print("Status: " + strconv.Itoa(resp.Status))
// log.Print("Body: " + resp.Body)

// }
3 changes: 3 additions & 0 deletions cycletls/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func DecompressBody(Body []byte, encoding []string, content []string) (parsedBod
"image/webp": true,
"image/jpeg": true,
"image/png": true,
"image/gif": true,
"image/avif": true,
"application/pdf": true,
}
if decodingTypes[content[0]] {
Expand Down Expand Up @@ -272,6 +274,7 @@ func genMap() (extMap map[string]utls.TLSExtension) {

}

// PrettyStruct formats json
func PrettyStruct(data interface{}) (string, error) {
val, err := json.MarshalIndent(data, "", " ")
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# CycleTLS Changelog


## 1.0.22 - (10-15-2023)
### Release Highlights
Support for additional filetypes and memory leak fix

### Enhancements
- [Missing Gif/Avif/... support in Decoding ](https://github.com/Danny-Dasilva/CycleTLS/issues/262)
### Bug Fixes
- [Memory leaks builded package on Docker container](https://github.com/Danny-Dasilva/CycleTLS/issues/157) addressed by @abler98
- [There are lot's of memory leaks, DDoS and infinite loop if any error in NodeJS](https://github.com/Danny-Dasilva/CycleTLS/issues/264) addressed by @abler98
- [is there a way to support socks5 proxy?](https://github.com/Danny-Dasilva/CycleTLS/issues/263) addressed by @ChengHoward
- [Support Socks5/4](https://github.com/Danny-Dasilva/CycleTLS/issues/77) addressed by @ChengHoward


## 1.0.21 - (6-20-2022)
### Release Highlights
Json Parse body in response and Cookie examples
Expand Down
Binary file added tests/images/test.avif
Binary file not shown.
Binary file added tests/images/test.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 24d4a21

Please sign in to comment.