ExCurlImpersonate (ex_curl_impersonate v0.2.0)
View SourceDocumentation for ExCurlImpersonate.
Shared options
:headers- a map of headers to include in the request, defaults to%{"user-agent" => "ex_curl_impersonate/0.1.0"}(not added when:impersonateis set):body- a string to send as the request body, defaults to"":follow_location- if redirects should be followed, defaults totrue:ssl_verifyhost- if SSL certificates should be verified, defaults totrue:ssl_verifypeer- if SSL certificates should be verified, defaults totrue:return_metrics- if request timing metrics should be included in the returned results, defaults tofalse:verbose- if curl should output verbose logs to stdout, useful for debugging. Defaults tofalse:proxy- proxy to use for transfers. Can be hostname or IP address with optional port number. Supports various proxy types (http, https, socks4, socks5). Defaults tonil:timeout_ms- maximum time in milliseconds for the whole request (CURLOPT_TIMEOUT_MS); on expiry the call returns{:error, "OPERATION_TIMEDOUT"}. The call blocks its process (on a dirty IO scheduler) until curl returns, so set this for anything talking to untrusted servers. Defaults tonil(no limit):connect_timeout_ms- maximum time in milliseconds for the connection phase, including DNS, TCP, TLS and proxy handshakes (CURLOPT_CONNECTTIMEOUT_MS). Defaults tonil(curl's default of 300 seconds):interface- outgoing network interface, local IP address or hostname to bind to, like curl's--interface(e.g."eth1","192.0.2.10","if!eth1","host!192.0.2.10"). Returns{:error, "INTERFACE_FAILED"}if it can't be used. Defaults tonil:ip_resolve- which IP version names resolve to (CURLOPT_IPRESOLVE)::v4,:v6or:any. It applies to every name curl resolves for the transfer, the proxy's included, so through a proxy reached over IPv4:v6fails to connect; use:resolveto choose the target's address family there. Defaults tonil(:any):resolve- list of"host:port:address"entries that pin a name to an address, like curl's--resolve(e.g.["www.example.com:443:[2001:db8::1]"]). With asocks5://proxy (notsocks5h://) the pinned address is what the proxy is asked to connect to, which is how to choose IPv4 or IPv6 for a target through a proxy. Defaults tonil:cainfo- path to a PEM CA bundle used to verify peers (curl-impersonate's built-in default is/etc/ssl/certs/ca-certificates.crton Linux,/etc/ssl/cert.pemon macOS); set this on distros that keep it elsewhere, e.g./etc/pki/tls/certs/ca-bundle.crt. Defaults tonil:capath- path to a directory of hashed CA certificates used to verify peers (built-in default is/etc/ssl/certson Linux); set this on distros that keep it elsewhere. Defaults tonil:impersonate- browser to impersonate (TLS, HTTP/2 fingerprint and default headers), e.g."chrome136","safari18_0","firefox135". See the curl-impersonate targets. When set, the defaultuser-agentheader is not added. Defaults tonil:impersonate_default_headers- whether:impersonatealso sends the browser's default headers. Defaults totrue:accept_encoding- encodings to request and transparently decode (CURLOPT_ACCEPT_ENCODING).""means every encoding this build supports (gzip, deflate, br, zstd), like curl's--compressed; a value such as"gzip"limits it;falsedisables decoding and returns the raw body bytes (an impersonated browser still advertises its ownaccept-encoding, so the server may compress anyway). Defaults to"":http_version- one of:http1_0,:http1_1,:http2,:http2_tls,:http2_prior_knowledge,:http3(falls back if HTTP/3 fails) or:http3_only. Defaults tonil(curl's default, or the impersonated browser's)
Fingerprint options
Every option added by curl-impersonate is available, named after the
lowercased CURLOPT_ constant (e.g. CURLOPT_TLS_GREASE → :tls_grease). They default to nil (not set) and are applied
after :impersonate, so they override the preset.
- integer / boolean:
:http2_no_priority,:http2_window_update,:http3_ssl_permute_extensions,:proxy_credential_no_reuse,:quic_initial_packet_number,:split_cookies,:ssl_enable_alps,:ssl_enable_ticket,:ssl_permute_extensions,:stream_exclusive,:tls_grease,:tls_key_shares_limit,:tls_key_usage_no_check,:tls_record_size_limit,:tls_signed_cert_timestamps,:tls_status_request,:tls_use_new_alps_codepoint,:ws_ssl_disable_ticket - string:
:form_boundary,:http2_pseudo_headers_order,:http2_settings,:http2_streams,:http3_httpheader_order,:http3_pseudo_headers_order,:http3_settings,:http3_sig_hash_algs,:http3_ssl_ec_curves,:http3_tls_extension_order,:httpheader_order,:quic_cid_length,:quic_transport_parameters,:ssl_cert_compression,:ssl_sig_hash_algs,:tls_delegated_credentials,:tls_extension_order,:tls_trust_anchors,:ws_httpheader_order,:ws_ssl_cert_compression - list of
"Name: value"strings::httpbaseheader,:http3_httpheader,:ws_httpheader.httpbaseheader: []removes the impersonated browser's default headers.
Error messages
Error messages refer to error codes on the libcurl error codes documentation page.
For example, when we try to send a request to an invalid url:
iex> ExCurlImpersonate.get("https://")
{:error, "URL_MALFORMAT"}The returned error tuple includes the error message "URL_MALFORMAT". This corresponds to the CURLE_URL_MALFORMAT (error code 3) error listed
in the libcurl error codes documentation.
Summary
Functions
Returns the version string of the linked libcurl, e.g. "libcurl/8.22.0-IMPERSONATE BoringSSL/...".
Sends a DELETE request to the given url.
Sends a DELETE request to the given url. Similar to delete/2 but raises ExCurlImpersonate.CurlError if the request fails.
Sends a GET request to the given url.
Sends a GET request to the given url. Similar to get/2 but raises ExCurlImpersonate.CurlError if the request fails.
Sends a PATCH request to the given url.
Sends a PATCH request to the given url. Similar to patch/2 but raises ExCurlImpersonate.CurlError if the request fails.
Sends a POST request to the given url.
Sends a POST request to the given url. Similar to post/2 but raises ExCurlImpersonate.CurlError if the request fails.
Sends a PUT request to the given url.
Sends a PUT request to the given url. Similar to put/2 but raises ExCurlImpersonate.CurlError if the request fails.
Send a request to the url using the provided method and options
Sends a request to the given url using the provided method and options. Similar to request/3 but raises ExCurlImpersonate.CurlError if the request fails.
Functions
Returns the version string of the linked libcurl, e.g. "libcurl/8.22.0-IMPERSONATE BoringSSL/...".
Sends a DELETE request to the given url.
Returns either {:ok, %ExCurlImpersonate.Response{}} or {:error, "CURL_ERROR_MESSAGE"}.
See the "Shared options" section at the module documentation for available options and their defaults.
See the "Error messages" section for details on error messages.
Examples
iex> ExCurlImpersonate.delete("https://httpbin.org/delete", headers: %{"Authorization" => "bearer secret"})
Sends a DELETE request to the given url. Similar to delete/2 but raises ExCurlImpersonate.CurlError if the request fails.
See the "Shared options" section at the module documentation for available options and their defaults.
Examples
iex> ExCurlImpersonate.delete!("https://httpbin.org/delete")
Sends a GET request to the given url.
Returns either {:ok, %ExCurlImpersonate.Response{}} or {:error, "CURL_ERROR_MESSAGE"}.
See the "Shared options" section at the module documentation for available options and their defaults.
See the "Error messages" section for details on error messages.
Examples
iex> {:ok, %ExCurlImpersonate.Response{status_code: status_code}} = ExCurlImpersonate.get("https://google.com", follow_location: false)
iex> status_code
301
Sends a GET request to the given url. Similar to get/2 but raises ExCurlImpersonate.CurlError if the request fails.
See the "Shared options" section at the module documentation for available options and their defaults.
Examples
iex> %ExCurlImpersonate.Response{status_code: status_code} = ExCurlImpersonate.get!("https://google.com")
iex> status_code
200
Sends a PATCH request to the given url.
Returns either {:ok, %ExCurlImpersonate.Response{}} or {:error, "CURL_ERROR_MESSAGE"}.
See the "Shared options" section at the module documentation for available options and their defaults.
See the "Error messages" section for details on error messages.
Examples
iex> ExCurlImpersonate.patch("https://httpbin.org/patch", headers: %{"user-agent" => "custom-user-agent"})
Sends a PATCH request to the given url. Similar to patch/2 but raises ExCurlImpersonate.CurlError if the request fails.
See the "Shared options" section at the module documentation for available options and their defaults.
Examples
iex> ExCurlImpersonate.patch!("https://httpbin.org/patch", body: Jason.encode!(%{"some-value" => true}), headers: %{"content-type" => "application/json"})
Sends a POST request to the given url.
Returns either {:ok, %ExCurlImpersonate.Response{}} or {:error, "CURL_ERROR_MESSAGE"}.
See the "Shared options" section at the module documentation for available options and their defaults.
See the "Error messages" section for details on error messages.
Examples
iex> {:ok, %ExCurlImpersonate.Response{}} = ExCurlImpersonate.post("https://httpbin.org/post", body: "some-value=true")
Sends a POST request to the given url. Similar to post/2 but raises ExCurlImpersonate.CurlError if the request fails.
See the "Shared options" section at the module documentation for available options and their defaults.
Examples
iex> ExCurlImpersonate.post!("https://httpbin.org/post", body: "some-value=true")
Sends a PUT request to the given url.
Returns either {:ok, %ExCurlImpersonate.Response{}} or {:error, "CURL_ERROR_MESSAGE"}.
See the "Shared options" section at the module documentation for available options and their defaults.
See the "Error messages" section for details on error messages.
Examples
iex> ExCurlImpersonate.put("https://httpbin.org/put", body: "some-value=true")
Sends a PUT request to the given url. Similar to put/2 but raises ExCurlImpersonate.CurlError if the request fails.
See the "Shared options" section at the module documentation for available options and their defaults.
Examples
iex> ExCurlImpersonate.put!("https://httpbin.org/put", headers: %{"content-type" => "application/json"}, body: "{}")
Send a request to the url using the provided method and options
Returns either {:ok, %ExCurlImpersonate.Response{}} or {:error, "CURL_ERROR_MESSAGE"}.
See the "Shared options" section at the module documentation for available options and their defaults.
See the "Error messages" section for details on error messages.
Examples
iex> ExCurlImpersonate.request("GET", "https://google.com")
Sends a request to the given url using the provided method and options. Similar to request/3 but raises ExCurlImpersonate.CurlError if the request fails.
See the "Shared options" section at the module documentation for available options and their defaults.