Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cffi_dist/example_typescript/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export class TLSClient implements TLSClientInstance {
const createWrapper = (): LibraryObject<never> => {
const sharedLibraryPath = join(__dirname, './../../dist/');
const sharedLibraryFilename = platform() === 'win32'
? `tls-client-windows-64-1.7.2.dll`
? `tls-client-windows-64-1.12.1.dll`
: arch() === 'arm64'
? `tls-client-darwin-arm64-1.7.2.dylib`
: `tls-client-darwin-amd64-1.7.2.dylib`;
? `tls-client-darwin-arm64-1.12.1.dylib`
: `tls-client-darwin-amd64-1.12.1.dylib`;

return Library(join(sharedLibraryPath, sharedLibraryFilename), {
request: ['string', ['string']],
Expand Down
1 change: 1 addition & 0 deletions cffi_dist/example_typescript/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface TLSClientRequestPayload {
followRedirects?: boolean;
insecureSkipVerify?: boolean;
isByteResponse?: boolean;
euckrResponse?: boolean;
withoutCookieJar?: boolean;
withRandomTLSExtensionOrder?: boolean;
timeoutSeconds?: number;
Expand Down
15 changes: 15 additions & 0 deletions cffi_src/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"sync"

"github.com/bogdanfinn/tls-client/profiles"
"golang.org/x/text/encoding/korean"
"golang.org/x/text/transform"

http "github.com/bogdanfinn/fhttp"
"github.com/bogdanfinn/fhttp/cookiejar"
Expand Down Expand Up @@ -201,6 +203,7 @@ func BuildResponse(sessionId string, withSession bool, resp *http.Response, cook
defer resp.Body.Close()

isByteResponse := input.IsByteResponse
euckrResponse := input.EuckrResponse

ce := resp.Header.Get("Content-Encoding")

Expand Down Expand Up @@ -233,6 +236,14 @@ func BuildResponse(sessionId string, withSession bool, resp *http.Response, cook
finalResponse = base64Encoding
}

if euckrResponse {
var bufs bytes.Buffer
wr := transform.NewWriter(&bufs, korean.EUCKR.NewDecoder())
wr.Write(respBodyBytes)
wr.Close()
finalResponse = bufs.String()
}

response := Response{
Id: uuid.New().String(),
Status: resp.StatusCode,
Expand Down Expand Up @@ -399,6 +410,10 @@ func getTlsClient(requestInput RequestInput, sessionId string, withSession bool)
options = append(options, tls_client.WithServerNameOverwrite(*requestInput.ServerNameOverwrite))
}

if requestInput.EuckrResponse {
options = append(options, tls_client.WithEnableEuckrResponse())
}

proxy := proxyUrl

if proxy != nil && *proxy != "" {
Expand Down
1 change: 1 addition & 0 deletions cffi_src/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type RequestInput struct {
WithCustomCookieJar bool `json:"withCustomCookieJar"`
WithoutCookieJar bool `json:"withoutCookieJar"`
WithRandomTLSExtensionOrder bool `json:"withRandomTLSExtensionOrder"`
EuckrResponse bool `json:"euckrResponse"`
}

// CustomTlsClient contains custom TLS specifications to construct a client from.
Expand Down
14 changes: 13 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/bogdanfinn/tls-client/bandwidth"
"github.com/bogdanfinn/tls-client/profiles"
"golang.org/x/net/proxy"
"golang.org/x/text/encoding/korean"
"golang.org/x/text/transform"
)

var defaultRedirectFunc = func(req *http.Request, via []*http.Request) error {
Expand Down Expand Up @@ -393,7 +395,17 @@ func (c *httpClient) Do(req *http.Request) (*http.Response, error) {

responseBody := io.NopCloser(bytes.NewBuffer(buf))

c.logger.Debug("response body payload: %s", string(buf))
finalResponse := string(buf)

if c.config.euckrResponse {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your korean encoding transformation is only happening in debug here (check line 383)
I think what you want is to do it always and transform the resp.Body if the option for euckr response is enabled

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, actually I'm using the client in typescript, and the library is already encoding and transferring body values normally

I'm not used to golang because I don't use it professionally
As you said, if the euckr option is enabled, it should always be reflected in the result

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahnse0 do you have an example url which i can use for testing your change if everything works?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var bufs bytes.Buffer
wr := transform.NewWriter(&bufs, korean.EUCKR.NewDecoder())
wr.Write(buf)
wr.Close()
finalResponse = bufs.String()
}

c.logger.Debug("response body payload: %s", finalResponse)

resp.Body = responseBody
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to set the finalResponse here or am i wrong?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a log to check if it's encoded normally

}
Expand Down
7 changes: 7 additions & 0 deletions client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type httpClientConfig struct {
disableIPV4 bool

enabledBandwidthTracker bool
euckrResponse bool
}

// WithProxyUrl configures a HTTP client to use the specified proxy URL.
Expand Down Expand Up @@ -288,3 +289,9 @@ func WithConnectHeaders(headers http.Header) HttpClientOption {
config.connectHeaders = headers
}
}

func WithEnableEuckrResponse() HttpClientOption {
return func(config *httpClientConfig) {
config.euckrResponse = true
}
}