diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-06 17:29:41 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-06 17:29:41 -0600 |
| commit | 602cf1603e6be9e961e5512ca770f6765fcb9b91 (patch) | |
| tree | 14acb809365211d80ef1a19b7af53200d613fff2 /src/lib.rs | |
| parent | c4ebba06ec707a3bbc7323eb0f378710a178604c (diff) | |
feat: add debug logging support for Rust backend
- Implement debug logging in RustConnection that matches Net::HTTP format
- Add log_request and log_response methods with detailed HTTP transaction logs
- Update Rust client to properly handle request headers
- Add comprehensive RDoc documentation for logging methods
- Ensure feature parity between Ruby and Rust backends for debugging
Debug output format matches Net::HTTP's set_debug_output:
-> "GET https://api.example.com/users HTTP/1.1"
-> "accept: application/json"
-> ""
<- "HTTP/1.1 200"
<- "content-type: application/json"
<- ""
<- "{\"users\":[...]}"
This maintains the same debugging experience users expect from
the Ruby backend while providing the performance benefits of Rust.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -1,4 +1,4 @@ -use magnus::{define_module, function, method, Error, Module, Object, Value, class}; +use magnus::{define_module, function, method, Error, Module, Object, Value, class, RHash, TryConvert}; use magnus::value::ReprValue; use reqwest::{Client, Method, Response}; use std::collections::HashMap; @@ -59,7 +59,7 @@ impl RustClient { &self, method_str: String, url: String, - _headers: Value, // Simplified - ignore headers for now + headers: Value, body: String, ) -> Result<RustResponse, Error> { let method = match method_str.to_uppercase().as_str() { @@ -74,6 +74,15 @@ impl RustClient { self.runtime.block_on(async { let mut request_builder = self.client.request(method, &url); + // Add headers if provided + if let Ok(headers_hash) = RHash::from_value(headers) { + for (key, value) in headers_hash { + if let (Ok(key_str), Ok(value_str)) = (String::try_convert(key), String::try_convert(value)) { + request_builder = request_builder.header(&key_str, &value_str); + } + } + } + // Add body if not empty if !body.is_empty() { request_builder = request_builder.body(body); |
