Skip to content

Commit

Permalink
code: bypass cloudflare 5s
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdneilsfield committed Dec 31, 2023
1 parent ad41b7b commit d3c0540
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"crypto/tls"
"encoding/json"
"flag"
"fmt"
Expand All @@ -27,6 +28,8 @@ var configFile = flag.String("config", "config.json", "Path to config file")

var config = DeepLXBalancerConfig{}

var client *http.Client

func LoadConfig(path string) {
// open config file
file, err := os.Open(path)
Expand Down Expand Up @@ -82,11 +85,13 @@ func DoRequest(endpoint DeepLXEndpoint, body []byte) (*http.Response, error) {
req.Header.Add("Sec-Ch-Ua-Mobile", "?0")
req.Header.Add("Sec-Ch-Ua-Platform", "\"macOS\"")
req.Header.Add("Upgrade-Insecure-Requests", "1")
req.Header.Add("Authority", "www.deepl.com")
req.Header.Add("Pragma", "no-cache")
if endpoint.Token != "" {
req.Header.Add("Authorization", "Bearer "+endpoint.Token)
}
// send request
return http.DefaultClient.Do(req)
return client.Do(req)
}

func enableCors(w *http.ResponseWriter) {
Expand Down Expand Up @@ -190,6 +195,18 @@ func main() {
// Load config
LoadConfig(*configFile)

defaultCipherSuites := []uint16{0xc02f, 0xc030, 0xc02b, 0xc02c, 0xcca8, 0xcca9, 0xc013, 0xc009,
0xc014, 0xc00a, 0x009c, 0x009d, 0x002f, 0x0035, 0xc012, 0x000a}
client = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
CipherSuites: append(defaultCipherSuites[8:], defaultCipherSuites[:8]...),
MaxVersion: tls.VersionTLS12,
},
ForceAttemptHTTP2: false,
},
}

// Start balancer
// StartBalancer(config)
http.HandleFunc("/", HelloworldHandler)
Expand Down

0 comments on commit d3c0540

Please sign in to comment.