### Install AzureTLS Client Source: https://github.com/noooste/azuretls-client/blob/main/README.md Use 'go get' to install the azuretls-client package. ```bash go get github.com/Noooste/azuretls-client ``` -------------------------------- ### Complete Debugging Example Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/debugging.md A comprehensive example showing how to enable logging, dump HTTP traffic to a file, and implement custom pre-request and post-request hooks for detailed debugging. ```go package main import ( "fmt" "log" "time" "github.com/Noooste/azuretls-client" ) func main() { session := azuretls.NewSession() defer session.Close() // Enable both logging and dumping session.Log() err := session.Dump("/tmp/http_debug") if err != nil { log.Fatal(err) } // Add pre-request hook session.UsePrehookWithContext(func(ctx *azuretls.Context) error { fmt.Printf("\n=== PRE-REQUEST ===\n") fmt.Printf("Time: %v\n", time.Now()) fmt.Printf("URL: %s\n", ctx.Request.Url) fmt.Printf("Method: %s\n", ctx.Request.Method) return nil }) // Add post-request callback session.UseCallbackWithContext(func(ctx *azuretls.Context) { fmt.Printf("\n=== POST-REQUEST ===\n") if ctx.Err != nil { fmt.Printf("Error: %v\n", ctx.Err) return } elapsed := time.Since(ctx.RequestStartTime) fmt.Printf("Duration: %v\n", elapsed) fmt.Printf("Status: %d\n", ctx.Response.StatusCode) fmt.Printf("Body Size: %d bytes\n", len(ctx.Response.Body)) }) // Make request response, err := session.Get("https://api.github.com") if err != nil { log.Fatal(err) } fmt.Printf("\n=== FINAL ===\n") fmt.Printf("Status: %d\n", response.StatusCode) fmt.Printf("Headers:\n") for key, values := range response.Header { for _, value := range values { fmt.Printf(" %s: %s\n", key, value) } } } ``` -------------------------------- ### Complete Context-Based Request Management Example Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/context.md This example demonstrates creating a session with a context timeout, setting up pre-hooks and post-callbacks to monitor request timing, and making multiple requests within the defined context. Use this to manage request lifecycles and observe performance. ```go package main import ( "context" "fmt" "log" "time" "github.com/Noooste/azuretls-client" ) func main() { // Create context with 30-second overall deadline ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() session := azuretls.NewSessionWithContext(ctx) defer session.Close() // Pre-hook to log timing session.UsePrehookWithContext(func(ctx *azuretls.Context) error { deadline, _ := ctx.Request.Context().Deadline() remaining := time.Until(deadline) fmt.Printf("[PRE] Deadline in %v\n", remaining) return nil }) // Post-callback to log timing session.UseCallbackWithContext(func(ctx *azuretls.Context) { elapsed := time.Since(ctx.RequestStartTime) fmt.Printf("[POST] Took %v\n", elapsed) if ctx.Err != nil { fmt.Printf("[POST] Error: %v\n", ctx.Err) } else { fmt.Printf("[POST] Status: %d\n", ctx.Response.StatusCode) } }) // Make multiple requests within the session timeout urls := []string{ "https://httpbin.org/delay/1", "https://httpbin.org/delay/2", "https://httpbin.org/delay/3", } for _, url := range urls { fmt.Printf("\n=== Request to %s ===\n", url) response, err := session.Get(url) if err != nil { log.Printf("Error: %v\n", err) return } fmt.Printf("Status: %d\n", response.StatusCode) } fmt.Println("\nAll requests completed successfully!") } ``` -------------------------------- ### Quick Start with AzureTLS Client Source: https://github.com/noooste/azuretls-client/blob/main/README.md Create a new session and make a GET request to a URL. The session automatically mimics a Chrome browser's TLS and HTTP/2 fingerprint. ```go package main import ( "fmt" "log" "github.com/Noooste/azuretls-client" ) func main() { session := azuretls.NewSession() defer session.Close() response, err := session.Get("https://api.github.com") if err != nil { log.Fatal(err) } fmt.Printf("Status: %d\n", response.StatusCode) fmt.Println(response.String()) } ``` -------------------------------- ### Complete Certificate Pinning Example Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/ssl-pinning.md Demonstrates a complete example of setting up and using certificate pinning with AzureTLS. This includes creating a session, initializing a custom pin manager, adding host pins, and making a request. ```Go package main import ( "fmt" "log" "github.com/Noooste/azuretls-client" ) func main() { session := azuretls.NewSession() defer session.Close() // Create a custom pin manager pinManager := azuretls.NewPinManager() // Option 1: Pin by connecting to the host err := pinManager.AddHost("api.github.com:443", session) if err != nil { log.Fatal("Failed to pin certificate:", err) } // Option 2: Pin manually with known fingerprints // pinManager.GetHost("api.github.com:443").AddPin("X3I7g5T+KcDHwKh8qOBeZDIFF6O/11db5NyGSF/P/PA=") // Set the pin manager on the session session.PinManager = pinManager // Make request - certificate will be verified against pins response, err := session.Get("https://api.github.com") if err != nil { log.Fatal("Request failed:", err) } fmt.Printf("Status: %d\n", response.StatusCode) } ``` -------------------------------- ### Development Setup Commands Source: https://github.com/noooste/azuretls-client/blob/main/CONTRIBUTING.md Commands to set up the development environment, including downloading dependencies and running tests. ```bash go mod download ``` ```bash go test ./... ``` -------------------------------- ### Example HeaderOrder Initialization Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/headers.md Shows how to initialize a HeaderOrder with a specific sequence of header names. ```go headerOrder := azuretls.HeaderOrder{ "user-agent", "accept", "accept-encoding", "accept-language", } ``` -------------------------------- ### Example Usage of GetDefaultPseudoHeaders Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/headers.md Demonstrates how to retrieve and use the default pseudo-header order. ```go defaultOrder := azuretls.GetDefaultPseudoHeaders() // Returns: [":method", ":authority", ":scheme", ":path"] ``` -------------------------------- ### Basic GET Request Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/request.md Demonstrates how to create and execute a simple GET request. ```APIDOC ## GET https://api.example.com/data ### Description Executes a basic GET request to retrieve data from the specified URL. ### Method GET ### Endpoint https://api.example.com/data ### Request Example ```go request := &azuretls.Request{ Method: "GET", Url: "https://api.example.com/data", } response, err := session.Do(request) ``` ``` -------------------------------- ### Make GET Request Source: https://github.com/noooste/azuretls-client/blob/main/examples/README.md Example of making a GET request using the AzureTLS client. It prints the status code and response body. ```go session := azuretls.NewSession() defer session.Close() response, err := session.Get("https://tls.peet.ws/api/all") if err != nil { panic(err) } fmt.Println(response.StatusCode, string(response.Body)) ``` -------------------------------- ### Install Build Tools on Linux Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Install the 'build-essential' package on Debian-based Linux distributions to get essential tools for compiling software. ```bash sudo apt install build-essential ``` -------------------------------- ### Make OPTIONS Request Source: https://github.com/noooste/azuretls-client/blob/main/examples/README.md Example of making an OPTIONS request using the AzureTLS client. ```go session := azuretls.NewSession() defer session.Close() response, err := session.Options("https://tls.peet.ws/api/all") ``` -------------------------------- ### Install AzureTLS CFFI Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Installs the AzureTLS CFFI library system-wide on Unix-like systems. This command requires appropriate permissions. ```bash make install ``` -------------------------------- ### Basic C Usage of AzureTLS Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Demonstrates initializing the library, creating a session with configuration, making a GET request, and cleaning up resources in C. ```c #include "azuretls.h" #include #include int main() { // Initialize library azuretls_init(); // Create session const char* config = "{\"browser\": \"chrome\", \"timeout_ms\": 30000}"; uintptr_t session = azuretls_session_new((char*)config); // Make a request const char* request = "{\"method\": \"GET\", \"url\": \"https://httpbin.org/get\"}"; CFfiResponse* response = azuretls_session_do(session, (char*)request); if (response->error) { printf("Error: %s\n", response->error); } else { printf("Status: %d\n", response->status_code); printf("Body: %s\n", response->body); } // Cleanup azuretls_free_response(response); azuretls_session_close(session); azuretls_cleanup(); return 0; } ``` -------------------------------- ### Make HEAD Request Source: https://github.com/noooste/azuretls-client/blob/main/examples/README.md Example of making a HEAD request using the AzureTLS client. ```go session := azuretls.NewSession() defer session.Close() response, err := session.Head("https://tls.peet.ws/api/all") ``` -------------------------------- ### ClearProxy Function Example Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/proxies.md This example shows how to remove any previously configured proxy settings from a session. After calling this, requests will no longer be routed through a proxy. ```go session.ClearProxy() ``` -------------------------------- ### C# Example using P/Invoke Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Provides a C# example using P/Invoke to call AzureTLS functions. This includes defining a C-compatible struct and using DllImport to link to the native library. ```csharp using System; using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] public struct CFfiResponse { public int status_code; public IntPtr body; public int body_len; public IntPtr headers; public IntPtr url; public IntPtr error; } public static class AzureTLS { const string DLL_NAME = "libazuretls"; [DllImport(DLL_NAME)] public static extern UIntPtr azuretls_session_new(string config); [DllImport(DLL_NAME)] public static extern void azuretls_session_close(UIntPtr sessionId); [DllImport(DLL_NAME)] public static extern IntPtr azuretls_session_do(UIntPtr sessionId, string request); [DllImport(DLL_NAME)] public static extern void azuretls_free_response(IntPtr response); } // Usage var session = AzureTLS.azuretls_session_new("{\"browser\": \"chrome\"}"); var response = AzureTLS.azuretls_session_do(session, "{\"method\": \"GET\", \"url\": \"https://httpbin.org/get\"}"); ``` -------------------------------- ### Session Configuration Example Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Defines the parameters for configuring a client session, including browser emulation, proxy settings, timeouts, and custom headers. ```json { "browser": "chrome|firefox|safari|edge|ios", "user_agent": "Custom User Agent String", "proxy": "http://user:pass@proxy:8080", "timeout_ms": 30000, "max_redirects": 10, "insecure_skip_verify": false, "ordered_headers": [ ["Header-Name", "Header-Value"], ["Another-Header", "Another-Value"] ], "headers": { "Global-Header": "Global-Value" } } ``` -------------------------------- ### SetProxy Example with Authentication Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/proxies.md Demonstrates how to set an HTTP proxy with username and password authentication for a session. Subsequent requests made with this session will use the configured proxy. ```go session := azuretls.NewSession() defer session.Close() // HTTP proxy with authentication err := session.SetProxy("http://user123:password456@proxy.example.com:8080") if err != nil { log.Fatal(err) } response, _ := session.Get("https://api.example.com") fmt.Println(response.StatusCode) ``` -------------------------------- ### Cookie Parsing Example Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/cookies.md Demonstrates accessing specific parsed cookies by name and iterating through raw Set-Cookie headers. ```go response, _ := session.Get("https://api.example.com") // Parsed cookies (simple map) if sessionCookie, exists := response.Cookies["session_id"]; exists { fmt.Printf("Session ID: %s\n", sessionCookie) } // Raw cookie headers (with attributes) for _, cookieHeader := range response.Header["Set-Cookie"] { fmt.Printf("Raw Set-Cookie: %s\n", cookieHeader) } ``` -------------------------------- ### Perform a Basic GET Request Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/README.md Initiates a new TLS session and performs a simple GET request to a specified URL. Handles potential errors during the request and prints the response status code and body. ```go session := azuretls.NewSession() deferr session.Close() response, err := session.Get("https://api.example.com") if err != nil { log.Fatal(err) } fmt.Println(response.StatusCode) fmt.Println(response.String()) ``` -------------------------------- ### Node.js Example using ffi-napi Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Shows how to use the ffi-napi library in Node.js to interact with the AzureTLS library. This includes defining response structures and loading the dynamic library. ```javascript const ffi = require('ffi-napi'); const ref = require('ref-napi'); // Define response structure const CFfiResponse = ref.types.CString; // Load library const azuretls = ffi.Library('./libazuretls', { 'azuretls_session_new': ['pointer', ['string']], 'azuretls_session_do': ['pointer', ['pointer', 'string']], 'azuretls_session_close': ['void', ['pointer']], 'azuretls_free_response': ['void', ['pointer']] }); // Create session const config = JSON.stringify({browser: 'chrome'}); const session = azuretls.azuretls_session_new(config); // Make request const request = JSON.stringify({method: 'GET', url: 'https://httpbin.org/get'}); const response = azuretls.azuretls_session_do(session, request); ``` -------------------------------- ### Get Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/session.md Sends a GET request to the specified URL. Supports optional arguments for headers, timeout, and context. ```APIDOC ## GET ### Description Sends a GET request to the specified URL. Supports optional arguments for headers, timeout, and context. ### Method GET ### Endpoint [URL] ### Parameters #### Path Parameters - **url** (string) - Required - The request URL - **args** (...any) - Optional - Optional arguments (headers, timeout, context) ### Response #### Success Response - **Response** (*Response) - The response object - **error** (error) - An error if the request failed ``` -------------------------------- ### Send GET Request Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/session.md Use this method to send a GET request to a specified URL. Optional arguments can include headers, timeout, and context. ```Go func (s *Session) Get(url string, args ...any) (*Response, error) ``` ```Go response, err := session.Get("https://api.example.com/data") if err != nil { log.Fatal(err) } fmt.Println(response.String()) ``` -------------------------------- ### Python Example using ctypes Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Demonstrates how to load the AzureTLS library and create a new session using Python's ctypes module. Ensure the correct library file is present in the execution path. ```python import ctypes import json import platform # Load library system = platform.system().lower() arch = 'amd64' if platform.machine() == 'x86_64' else platform.machine() lib_name = f"libazuretls_{system}_{arch}" lib = ctypes.CDLL(f"./{lib_name}.{'dll' if system == 'windows' else 'dylib' if system == 'darwin' else 'so'}") # Setup function signatures lib.azuretls_session_new.argtypes = [ctypes.c_char_p] lib.azuretls_session_new.restype = ctypes.c_ulong # Create session and make request session = lib.azuretls_session_new(b'{"browser": "chrome"}') ``` -------------------------------- ### Make PUT Request Source: https://github.com/noooste/azuretls-client/blob/main/examples/README.md Example of making a PUT request. The request body follows the same semantics as the POST request. ```go session := azuretls.NewSession() defer session.Close() // the body follows the same semantics as the POST request. response, err := session.Put("https://tls.peet.ws/api/all", `{"test": "test"}`) ``` -------------------------------- ### Establish Websocket Connection Source: https://github.com/noooste/azuretls-client/blob/main/examples/README.md Use `session.NewWebsocket` to create a websocket connection. Ensure to handle potential errors during connection setup and JSON writing. ```go session := azuretls.NewSession() def session.Close() ws, err := session.NewWebsocket("wss://demo.piesocket.com/v3/channel_123?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV¬ify_self", 1024, 1024, azuretls.OrderedHeaders{ {"User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"}, }, }) if err = ws.WriteJSON(map[string]string{ "event": "new_message", }); err != nil { panic(err) } ``` -------------------------------- ### Example Commit Message Source: https://github.com/noooste/azuretls-client/blob/main/CONTRIBUTING.md An example of a well-structured commit message following the project's conventions. Includes type, subject, body, and footer for clarity. ```text feat: add support for HTTP/2 trailers Implement support for reading and setting HTTP/2 trailers in responses. This enhances the client's compliance with RFC 7540. Closes #123 ``` -------------------------------- ### Install Developer Tools on macOS Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Install the Xcode command-line developer tools on macOS, which are often required for compiling native code and using build utilities. ```bash xcode-select --install ``` -------------------------------- ### Configure and Use an HTTP Proxy Source: https://github.com/noooste/azuretls-client/blob/main/README.md Set up a proxy for the session to route requests through. Supports various proxy types including HTTP, SOCKS4, and SOCKS5 with optional authentication. Errors during proxy setup are logged. ```Go session := azuretls.NewSession() defer session.Close() // One line proxy setup: supports HTTP, HTTPS, SOCKS4, SOCKS5 err := session.SetProxy("http://username:password@proxy.example.com:8080") if err != nil { log.Fatal(err) } response, err := session.Get("https://api.ipify.org") ``` -------------------------------- ### Handle Empty Proxy Chain Error Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/errors.md This example shows how to handle the error that occurs when attempting to set an empty proxy chain. ```Go err := session.SetProxyChain([]string{}) if err != nil { log.Println(err) // "proxy chain cannot be empty" } ``` -------------------------------- ### Complete Browser Profile Usage Example Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/browser-profiles.md Demonstrates how to use different browser profiles (Chrome, Firefox, Safari, iOS) with the azuretls-client library to make HTTP requests. ```go package main import ( "fmt" "log" "github.com/Noooste/azuretls-client" ) func main() { // Chrome profile (default) chrome := azuretls.NewSession() defer chrome.Close() chrome.Browser = azuretls.Chrome resp, _ := chrome.Get("https://api.example.com") fmt.Printf("Chrome: %d\n", resp.StatusCode) // Firefox profile firefox := azuretls.NewSession() defer firefox.Close() firefox.Browser = azuretls.Firefox resp, _ = firefox.Get("https://api.example.com") fmt.Printf("Firefox: %d\n", resp.StatusCode) // Safari profile safari := azuretls.NewSession() defer safari.Close() safari.Browser = azuretls.Safari resp, _ = safari.Get("https://api.example.com") fmt.Printf("Safari: %d\n", resp.StatusCode) // iOS profile ios := azuretls.NewSession() defer ios.Close() ios.Browser = azuretls.Ios resp, _ = ios.Get("https://api.example.com") fmt.Printf("iOS: %d\n", resp.StatusCode) } ``` -------------------------------- ### Complete Cookie Management Example in Go Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/cookies.md This Go code snippet illustrates a full cycle of cookie management. It shows how to initialize a session, log in to set cookies, access protected resources where cookies are sent automatically, view stored cookies, make anonymous requests that bypass cookies, and add custom cookies to specific requests. Ensure the azuretls library is imported. ```go package main import ( "fmt" "log" "net/url" "github.com/Noooste/azuretls-client" ) func main() { session := azuretls.NewSession() defer session.Close() // First request - login (sets cookies) fmt.Println("=== Login Request ===") loginData := map[string]string{ "username": "user@example.com", "password": "password123", } response, err := session.Post("https://api.example.com/login", loginData) if err != nil { log.Fatal(err) } fmt.Printf("Status: %d\n", response.StatusCode) // Check response cookies fmt.Println("Response Cookies:") for name, value := range response.Cookies { fmt.Printf(" %s = %s\n", name, value) } // Second request - access protected resource (cookies sent automatically) fmt.Println("\n=== Protected Resource Request ===") response, err = session.Get("https://api.example.com/user/profile") if err != nil { log.Fatal(err) } fmt.Printf("Status: %d\n", response.StatusCode) // View stored cookies fmt.Println("\n=== Stored Cookies ===") url, _ := url.Parse("https://api.example.com") cookies := session.CookieJar.Cookies(url) for _, cookie := range cookies { fmt.Printf(" %s = %s (Domain: %s, Path: %s)\n", cookie.Name, cookie.Value, cookie.Domain, cookie.Path) } // Make request without cookies fmt.Println("\n=== Anonymous Request (No Cookies) ===") anonymousReq := &azuretls.Request{ Method: "GET", Url: "https://api.example.com/public", NoCookie: true, // Don't send cookies } response, err = session.Do(anonymousReq) if err != nil { log.Fatal(err) } fmt.Printf("Status: %d (without cookies)\n", response.StatusCode) // Manually add cookie to request fmt.Println("\n=== Custom Cookie in Request ===") customCookieReq := &azuretls.Request{ Method: "GET", Url: "https://api.example.com/special", OrderedHeaders: azuretls.OrderedHeaders{ {"Cookie", "custom_token=xyz789"}, }, } response, err = session.Do(customCookieReq) if err != nil { log.Fatal(err) } fmt.Printf("Status: %d\n", response.StatusCode) } ``` -------------------------------- ### Example of Using Sensitive Headers Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/headers.md Demonstrates how to include sensitive headers in an OrderedHeaders collection. Headers marked with 'Sensitive-Headers:' will not be logged. ```go headers := azuretls.OrderedHeaders{ {"User-Agent", "Mozilla/5.0"}, {"Sensitive-Headers:", "Authorization", "Cookie"}, // These won't be logged {"Authorization", "Bearer secret-token"}, } ``` -------------------------------- ### Make PATCH Request Source: https://github.com/noooste/azuretls-client/blob/main/examples/README.md Example of making a PATCH request. The request body follows the same semantics as the POST request. ```go session := azuretls.NewSession() defer session.Close() // the body follows the same semantics as the POST request. response, err := session.Patch("https://tls.peet.ws/api/all", `{"test": "test"}`) ``` -------------------------------- ### Initialize New AzureTLS Session Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/configuration.md Creates a new AzureTLS session with default configurations. This is the starting point for making requests. ```go session := azuretls.NewSession() ``` -------------------------------- ### Chain Full Session Configuration Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/configuration.md Demonstrates chaining multiple configuration options for a session, including browser profile, timeouts, redirects, user agent, ordered headers, proxy settings, and JA3 fingerprinting. This provides a comprehensive setup for making requests. ```go session := azuretls.NewSession() deferr session.Close() // Chain all configuration session.Browser = azuretls.Firefox session.SetTimeout(60 * time.Second) session.MaxRedirects = 5 session.UserAgent = "MyApp/1.0" session.OrderedHeaders = azuretls.OrderedHeaders{ {"User-Agent", "MyApp/1.0"}, {"Accept", "application/json"}, {"Accept-Language", "en-US,en;q=0.9"}, } err := session.SetProxy("http://proxy.example.com:8080") if err != nil { log.Fatal(err) } session.Log() ja3 := "771,4865-4866-4867-49196-49195-52393-49200-49199-49172-49171-157-156-61-60-53-47-10,23-24-25-0-5-10-11-35-16-14-13-45-51-27-20-65281-21,29-23-24,0" err = session.ApplyJa3(ja3, azuretls.Firefox) if err != nil { log.Fatal(err) } // Now make requests with full configuration response, _ := session.Get("https://api.example.com/data") ``` -------------------------------- ### Rust Example using libc Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Illustrates how to call AzureTLS functions from Rust using the libc crate. This involves defining external C functions and a C-compatible struct for responses. ```rust use std::ffi::{CString, CStr}; use std::os::raw::c_char; #[link(name = "azuretls")] extern "C" { fn azuretls_session_new(config: *const c_char) -> usize; fn azuretls_session_close(session_id: usize); fn azuretls_session_do(session_id: usize, request: *const c_char) -> *mut CFfiResponse; fn azuretls_free_response(response: *mut CFfiResponse); } #[repr(C)] struct CFfiResponse { status_code: i32, body: *mut c_char, body_len: i32, headers: *mut c_char, url: *mut c_char, error: *mut c_char, } fn main() { let config = CString::new(r#"{"browser": "chrome"}"#).unwrap(); let session = unsafe { azuretls_session_new(config.as_ptr()) }; let request = CString::new(r#"{"method": "GET", "url": "https://httpbin.org/get"}"#).unwrap(); let response = unsafe { azuretls_session_do(session, request.as_ptr()) }; // Process response... unsafe { azuretls_free_response(response); azuretls_session_close(session); } } ``` -------------------------------- ### Handle Proxy Connection Errors Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/errors.md This snippet demonstrates how to set a proxy and then check for and log proxy connection errors during a GET request. ```Go err := session.SetProxy("http://proxy.example.com:8080") if err != nil { log.Fatal("Proxy setup failed:", err) } response, err := session.Get(url) if err != nil { if strings.Contains(err.Error(), "proxy") { log.Println("Proxy connection failed:", err) } } ``` -------------------------------- ### Request Configuration Example Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Specifies the details for making an HTTP request, including method, URL, body, headers, and various request-specific settings like timeouts and redirect handling. ```json { "method": "GET", "url": "https://example.com", "body": "Request body content", "headers": { "Content-Type": "application/json", "Authorization": "Bearer token" }, "ordered_headers": [ ["User-Agent", "Custom-Agent/1.0"], ["Accept", "application/json"], ["Content-Type", "application/json"] ], "timeout_ms": 5000, "force_http1": false, "force_http3": false, "ignore_body": false, "no_cookie": false, "disable_redirects": false, "max_redirects": 5, "insecure_skip_verify": false } ``` -------------------------------- ### Build Windows Architectures Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Builds the AzureTLS CFFI library for all supported Windows architectures. Ensure Go 1.24+ with CGO enabled, a C compiler, and Make are installed. ```bash make build-windows ``` -------------------------------- ### Send a GET Request with Custom Headers Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/README.md Constructs a request with custom headers, such as Authorization and Accept, before sending it. This allows for fine-grained control over request metadata. ```go headers := azuretls.OrderedHeaders{ {"Authorization", "Bearer token"}, {"Accept", "application/json"}, } request := &azuretls.Request{ Method: "GET", Url: "https://api.example.com", OrderedHeaders: headers, } response, _ := session.Do(request) ``` -------------------------------- ### Build AzureTLS CFFI Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Builds the AzureTLS CFFI library for the current platform. Ensure Go 1.24+ with CGO enabled, a C compiler, and Make are installed. ```bash make ``` -------------------------------- ### Handle DNS Resolution Errors in Go Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/errors.md Identify and log errors when a domain name cannot be resolved. This example specifically checks for 'no such host' in the error message. ```Go response, err := session.Get("https://nonexistent-domain-12345.com") if err != nil { if strings.Contains(err.Error(), "no such host") { log.Println("Domain does not exist") } } ``` -------------------------------- ### Basic GET Request Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/request.md Construct a simple GET request to retrieve data from a specified URL. This is the most basic type of HTTP request. ```go request := &azuretls.Request{ Method: "GET", Url: "https://api.example.com/data", } response, err := session.Do(request) ``` -------------------------------- ### Setting Proxy - Incorrect vs Correct Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/proxies.md Demonstrates the correct way to set a proxy by including the protocol in the proxy URL. Incorrect usage may lead to an 'invalid proxy' error. ```go // Wrong session.SetProxy("proxy.example.com:8080") // Correct session.SetProxy("http://proxy.example.com:8080") ``` -------------------------------- ### Set Up Basic HTTP Proxy Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/proxies.md Configure a simple HTTP proxy for all subsequent requests made by the session. Ensure the proxy URL is correctly formatted. ```go session := azuretls.NewSession() defer session.Close() // Simple HTTP proxy without authentication err := session.SetProxy("http://proxy.example.com:8080") if err != nil { log.Fatal(err) } response, _ := session.Get("https://api.example.com/endpoint") fmt.Println(response.StatusCode) ``` -------------------------------- ### Get Header Value from OrderedHeaders Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/headers.md The Get() method retrieves the first value associated with a specified header field. It returns an empty string if the field is not found. Header names are case-insensitive. ```go headers := azuretls.OrderedHeaders{ {"Content-Type", "application/json", "charset=utf-8"}, } value := headers.Get("Content-Type") // "application/json; charset=utf-8" ``` -------------------------------- ### Set Up a Proxy Chain Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/proxies.md Configure a sequence of proxies for multi-hop connections. Requests are routed through each proxy in the specified order. Ensure all proxy URLs are valid and the chain has at least one proxy. ```go session := azuretls.NewSession() defer session.Close() proxies := []string{ "http://entry.proxy.com:8080", "socks5://intermediate.proxy.com:1080", "http://user:pass@exit.proxy.com:3128", } err := session.SetProxyChain(proxies) if err != nil { log.Fatal(err) } response, _ := session.Get("https://api.example.com") ``` -------------------------------- ### Setting Browser Profile (Simple Selection) Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/browser-profiles.md Demonstrates how to set a browser profile for a new session using a predefined constant. This automatically configures TLS, HTTP/2, and headers. ```go session := azuretls.NewSession() session.Browser = azuretls.Chrome // "chrome" ``` -------------------------------- ### Get Request Context Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/request.md Retrieve the context currently associated with the request. ```go request.Context() ``` -------------------------------- ### Get Session Context Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/context.md Retrieves the context associated with the session. By default, this is context.Background(). ```go func (s *Session) Context() context.Context session := azuretls.NewSession() ctx := session.Context() // ctx is context.Background() by default ``` -------------------------------- ### Create a New Session with Default Configuration Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/session.md Use `NewSession()` to create a session with default settings, including a Chrome browser fingerprint, automatic cookie jar, 30-second timeout, and a limit of 10 redirects. Remember to close the session when done. ```Go session := azuretls.NewSession() defer session.Close() response, err := session.Get("https://api.github.com") if err != nil { log.Fatal(err) } fmt.Println(response.StatusCode) ``` -------------------------------- ### Enable and Test HTTP/3 Source: https://github.com/noooste/azuretls-client/blob/main/examples/README.md Demonstrates how to enable and test HTTP/3 for a request by setting `ForceHTTP3: true`. It includes verification steps to ensure HTTP/3 was used and the response status code is correct. ```go // Create session session := azuretls.NewSession() defer session.Close() // Enable logging session.Log() // Test direct HTTP/3 resp, err := session.Do(&azuretls.Request{ Method: http.MethodGet, Url: "https://cloudflare.com/cdn-cgi/trace", // Cloudflare supports HTTP/3 ForceHTTP3: true, }) if err != nil { panic(err) } // Check response if resp.StatusCode != 200 { panic(fmt.Sprintf("Expected status code 200, got %d", resp.StatusCode)) } // Verify HTTP/3 was used if resp.HttpResponse.Proto != "HTTP/3.0" { panic(fmt.Sprintf("Expected HTTP/3.0, got %s", resp.HttpResponse.Proto)) } ``` -------------------------------- ### Set Up SOCKS5 Proxy with Authentication Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/proxies.md Configure a SOCKS5 proxy that requires username and password authentication. The proxy URL must include credentials. ```go session := azuretls.NewSession() deferr session.Close() // SOCKS5 proxy with username and password err := session.SetProxy("socks5://user123:password456@socks.example.com:1080") if err != nil { log.Fatal(err) } response, _ := session.Get("https://api.example.com/endpoint") ``` -------------------------------- ### Make DELETE Request Source: https://github.com/noooste/azuretls-client/blob/main/examples/README.md Example of making a DELETE request using the AzureTLS client. ```go session := azuretls.NewSession() defer session.Close() response, err := session.Delete("https://tls.peet.ws/api/all") ``` -------------------------------- ### New Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/ssl-pinning.md Establishes a connection to a host and pins the certificate chain. This method is used to initiate a secure connection with SSL pinning enabled. ```APIDOC ## New ### Description Establishes a connection and pins the certificate chain. ### Method ```go func (p *PinHost) New(addr string, session *Session) error ``` ### Parameters #### Path Parameters - **addr** (string) - Yes - Host address (host:port) - **session** (*Session) - Yes - Session to use for connection ### Returns `error` — Error if connection fails ``` -------------------------------- ### Python Usage of AzureTLS Session Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Shows how to create an AzureTLS session in Python with configuration and perform GET and POST requests. ```python from cffi_python import AzureTLSSession # Create session with configuration with AzureTLSSession({"browser": "chrome"}) as session: # Simple GET request response = session.get("https://httpbin.org/get") print(f"Status: {response.status_code}") print(f"Body: {response.body}") # POST with JSON response = session.post( "https://httpbin.org/post", body='{"message": "Hello World"}', headers={"Content-Type": "application/json"} ) ``` -------------------------------- ### TlsSpecifications Struct Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/types.md Defines the TLS handshake configuration parameters for JA3 fingerprinting. Use DefaultTlsSpecifications to get browser-specific defaults. ```go type TlsSpecifications struct { AlpnProtocols []string SignatureAlgorithms []tls.SignatureScheme SupportedVersions []uint16 CertCompressionAlgos []tls.CertCompressionAlgo DelegatedCredentialsAlgorithmSignatures []tls.SignatureScheme PSKKeyExchangeModes []uint8 SignatureAlgorithmsCert []tls.SignatureScheme ApplicationSettingsProtocols []string RenegotiationSupport tls.RenegotiationSupport RecordSizeLimit uint16 } ``` -------------------------------- ### Get Latest Firefox ClientHelloSpec Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/fingerprinting.md Retrieves the ClientHelloSpec for the latest Firefox version. This is useful for emulating Firefox TLS handshakes. ```go func GetLastFirefoxVersion() *tls.ClientHelloSpec { // ... implementation details ... } ``` -------------------------------- ### AddHost(addr string, session *Session) Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/ssl-pinning.md Establishes a connection to the host, retrieves its certificate chain, and pins the public keys. This method is crucial for setting up pinning for a specific host. ```APIDOC ## AddHost(addr string, session *Session) ### Description Establishes a connection to the host, retrieves its certificate chain, and pins the public keys. ### Parameters #### Path Parameters - **addr** (string) - Required - Host address (host:port) - **session** (*Session) - Optional - Session to use for connection (uses TLS config from session) ### Returns - `error` — Error if connection or pinning fails ### Example ```go pinManager := azuretls.NewPinManager() session := azuretls.NewSession() // Pin the certificate from api.github.com err := pinManager.AddHost("api.github.com:443", session) if err != nil { log.Fatal(err) } session.PinManager = pinManager response, _ := session.Get("https://api.github.com") ``` ``` -------------------------------- ### Build All Supported Platforms Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Builds the AzureTLS CFFI library for all supported platforms. Requires Go 1.24+ with CGO enabled, a C compiler, and Make. ```bash make build-all ``` -------------------------------- ### Get AzureTLS Library Version Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Retrieves the version string of the AzureTLS library. The returned string must be freed using `azuretls_free_string`. ```c char* version = azuretls_version(); ``` -------------------------------- ### Get Latest Safari ClientHelloSpec Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/fingerprinting.md Retrieves the ClientHelloSpec for the latest Safari version. Use this to match Safari's TLS configurations. ```go func GetLastSafariVersion() *tls.ClientHelloSpec { // ... implementation details ... } ``` -------------------------------- ### Firefox QUIC Initial Packet Configuration Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/browser-profiles.md Returns QUIC initial packet configuration for Firefox. ```go quic.InitialPacketSpec{ SrcConnIDLength: 3, DestConnIDLength: 8, InitPacketNumberLength: 1, InitPacketNumber: 0, ClientTokenLength: 0, FrameBuilder: quic.QUICFrames{}, } ``` -------------------------------- ### Get Browser ClientHelloSpec Function Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/browser-profiles.md Obtain a function that returns the ClientHelloSpec for a specified browser. This is useful for dynamically setting the ClientHelloSpec on a session. ```Go func GetBrowserClientHelloFunc(browser string) func() *tls.ClientHelloSpec { // ... implementation details ... } ``` ```Go chromeHello := azuretls.GetBrowserClientHelloFunc(azuretls.Chrome) spec := chromeHello() // Use spec session.GetClientHelloSpec = chromeHello ``` -------------------------------- ### Creating OrderedHeaders Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/headers.md Illustrates the creation of OrderedHeaders with multiple values for certain headers. ```go headers := azuretls.OrderedHeaders{ {"User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}, {"Accept", "text/html", "application/xhtml+xml"}, {"Accept-Language", "en-US,en;q=0.9"}, {"Cache-Control", "max-age=0"}, {"Sec-Fetch-Dest", "document"}, {"Sec-Fetch-Mode", "navigate"}, {"Sec-Fetch-Site", "none"}, } ``` -------------------------------- ### Enable Logging and Dump Requests/Responses Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/errors.md Enable session logging and dump request/response details to a specified directory. Check the dump directory for detailed logs when an error occurs. ```go session.Log() session.Dump("/tmp/debug") response, err := session.Get(url) if err != nil { // Check /tmp/debug/ for request/response details log.Fatal(err) } ``` -------------------------------- ### Modifying Headers with OrderedHeaders Methods Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/headers.md Illustrates common operations on OrderedHeaders, including setting, adding, deleting, and getting header values. ```go headers := azuretls.OrderedHeaders{ {"User-Agent", "Chrome"}, {"Accept", "application/json"}, } // Set a header (replaces if exists) headers.Set("X-Custom", "value") // Add to existing header headers.Add("Accept", "text/html") // Remove a header headers = headers.Del("User-Agent") // Get a header value value := headers.Get("Accept") ``` -------------------------------- ### Set Timeout for AzureTLS Session Source: https://github.com/noooste/azuretls-client/blob/main/examples/README.md Configure a request timeout for an AzureTLS session using `SetTimeout`. This example sets a 5-second timeout. ```go session := azuretls.NewSession() deferr session.Close() session.SetTimeout(5 * time.Second) response, err := session.Get("https://tls.peet.ws/api/all") if err != nil { panic(err) } fmt.Println(response.StatusCode, string(response.Body)) ``` -------------------------------- ### Get Latest iOS ClientHelloSpec Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/fingerprinting.md Retrieves the ClientHelloSpec for the latest iOS Safari version. This is ideal for emulating TLS handshakes on iOS devices. ```go func GetLastIosVersion() *tls.ClientHelloSpec { // ... implementation details ... } ``` -------------------------------- ### Import AzureTLS Client Package Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/README.md Import the main package for using the AzureTLS client library. ```go import "github.com/Noooste/azuretls-client" ``` -------------------------------- ### Manage Cookies with AzureTLS Session Source: https://github.com/noooste/azuretls-client/blob/main/examples/README.md Manage cookies for an AzureTLS session using the `CookieJar`. This example sets a 'test' cookie before making a request. ```go session := azuretls.NewSession() deferr session.Close() parsed, err := url.Parse("https://tls.peet.ws/api/all") session.CookieJar.SetCookies(parsed, []*http.Cookie{ { Name: "test", Value: "test", }, }) response, err := session.Get("https://tls.peet.ws/api/all") if err != nil { panic(err) } ``` -------------------------------- ### Modify HTTP/3 Fingerprint Source: https://github.com/noooste/azuretls-client/blob/main/examples/README.md Applies an HTTP/3 fingerprint to the session for specific HTTP/3 configurations. This example also forces the use of HTTP/3 for the request. ```go session := azuretls.NewSession() defer session.Close() if err := session.ApplyHTTP3("1:65536;6:262144;7:100;51:1;GREASE|m,a,s,p"); err != nil { panic(err) } response, err := session.Do(&azuretls.Request{ Method: http.MethodGet, Url: "https://fp.impersonate.pro/api/http3" ForceHTTP3: true, }) if err != nil { panic(err) } fmt.Println(response.StatusCode, response.String()) ``` -------------------------------- ### Chrome QUIC Initial Packet Configuration Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/browser-profiles.md Returns QUIC initial packet configuration for Chrome. ```go quic.InitialPacketSpec{ SrcConnIDLength: 0, DestConnIDLength: 8, InitPacketNumberLength: 1, InitPacketNumber: 1, ClientTokenLength: 0, FrameBuilder: &quic.QUICRandomFrames{ MinPING: 0, MaxPING: 10, MinCRYPTO: 1, MaxCRYPTO: 10, MinPADDING: 3, MaxPADDING: 6, Length: 1231 - 16, }, } ``` -------------------------------- ### Get Public IP Address Source: https://github.com/noooste/azuretls-client/blob/main/cffi/README.md Retrieves the public IP address associated with an AzureTLS session. The returned string must be freed using `azuretls_free_string`. ```c char* ip = azuretls_session_get_ip(session_id); ``` -------------------------------- ### Make POST Request with JSON Body Source: https://github.com/noooste/azuretls-client/blob/main/examples/README.md Demonstrates making a POST request with different types of JSON-compatible bodies, including strings, maps, and byte slices. ```go session := azuretls.NewSession() defer session.Close() response, err := session.Post("https://tls.peet.ws/api/all", `{"test": "test"}`) // or response, err := session.Post("https://tls.peet.ws/api/all", map[string]string{"test": "test"}) // or response, err := session.Post("https://tls.peet.ws/api/all", []byte(`{"test": "test"}`)) ``` -------------------------------- ### Get Public IP Address Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/session.md Retrieves the public IP address of the session by querying an external service. Returns the IP address and any error encountered. ```go func (s *Session) Ip() (ip string, err error) { // ... implementation ... } ``` ```go ip, err := session.Ip() if err != nil { log.Fatal(err) } fmt.Println("IP:", ip) ``` -------------------------------- ### Make CONNECT Request Source: https://github.com/noooste/azuretls-client/blob/main/examples/README.md Demonstrates using session.Connect to establish a TLS handshake and HTTP connection without sending an initial HTTP request. ```go session := azuretls.NewSession() defer session.Close() response, err := session.Connect("https://tls.peet.ws/api/all") ``` -------------------------------- ### Get Latest Chrome ClientHelloSpec for HTTP/3 Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/fingerprinting.md Returns the ClientHelloSpec for the latest Chrome version optimized for HTTP/3. This configuration is specifically tuned for HTTP/3 performance. ```go func GetLastChromeVersionForHTTP3() *tls.ClientHelloSpec { // ... implementation details ... } ``` -------------------------------- ### Establish Connection with Certificate Pinning Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/api-reference/ssl-pinning.md Establishes a new connection to a specified address using the provided session and pins the certificate chain. This method returns an error if the connection fails. ```go pinHost := azuretls.NewPinHost() // ... add pins to pinHost ... err := pinHost.New("example.com:443", session) ``` -------------------------------- ### Perform a GET Request via a Proxy Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/README.md Sets up the TLS session to route requests through a specified HTTP proxy. This is useful for network configurations or anonymity. ```go err := session.SetProxy("http://proxy.example.com:8080") response, _ := session.Get("https://api.example.com") ``` -------------------------------- ### Enable Console Logging Source: https://github.com/noooste/azuretls-client/blob/main/_autodocs/configuration.md Enable console logging for the client. This logs all requests and responses to the standard output. ```go // Enable console logging session.Log() ```