bogdanfinn / tls-client

net/http.Client like HTTP Client with options to select specific client TLS Fingerprints to use for requests.
BSD 4-Clause "Original" or "Old" License
670 stars 133 forks source link

Feature Request - add/export addCookieToSession method #19

Closed toman-tom closed 1 year ago

toman-tom commented 1 year ago

Hi!

I'd love to see functionality whereby I can simply call a method to add cookies to the internal cookie jar. Yes I know I can send additional cookies in the requestCookies array, but better functionality (IMO) would be to have a function that I can call to add the additional cookies, without having to send them as part of the request.

bogdanfinn commented 1 year ago

@toman-tom fine for me. will include that in the next version.

bogdanfinn commented 1 year ago

Should work like this now :-)

const tlsClientLibrary = ffi.Library('./../dist/tls-client-darwin-amd64-1.2.0.dylib', {
    'request': ['string', ['string']],
    'getCookiesFromSession': ['string', ['string']],
    'addCookiesToSession': ['string', ['string']],
    'freeMemory': ["void", ['string']],
    'destroyAll': ['string', []],
    'destroySession': ['string', ['string']]
});

const payload = {
    sessionId: 'my-session-id',
    url: "https://example.com/",
    cookies: [{
        "name": "myCookieName",
        "value": "myCookieValue",
    }]
}

const resp = tlsClientLibrary.addCookiesToSession(JSON.stringify(payload))
toman-tom commented 1 year ago

Looks great! Thank you @bogdanfinn