Skip to content

feat/ns http#20

Merged
Vaishnav-Sabari-Girish merged 5 commits into
mainfrom
feat/ns_http
Jun 26, 2026
Merged

feat/ns http#20
Vaishnav-Sabari-Girish merged 5 commits into
mainfrom
feat/ns_http

Conversation

@Vaishnav-Sabari-Girish

@Vaishnav-Sabari-Girish Vaishnav-Sabari-Girish commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Implement memory-safe synchronous HTTP client

Introduces the ns_http module, wrapping Rust's reqwest crate to provide
a modern, synchronous HTTP API to C without the complexity and callback
management of libcurl.

Key additions:

  • Implemented ns_http_get and ns_http_post for standard web requests.
  • Added ns_http_response struct to cleanly capture HTTP status codes and
    pack the response body directly into memory-safe SSO ns_string structs.
  • Introduced the ns_autohttp macro, leveraging the GCC/Clang cleanup
    attribute to provide RAII, automatically freeing HTTP response buffers
    when they fall out of scope.
  • Created 18_http.c example demonstrating fetching
    data and pushing JSON payloads.
  • Registered ns_http crate in the workspace and added reqwest dependency.

Summary by cubic

Adds a new ns_http module with a simple, memory-safe synchronous HTTP client for C. Supports GET/POST with RAII cleanup; POST is binary‑safe and GET/POST now share a unified client configuration.

  • New Features

    • New ns_http crate using blocking reqwest with a browser-like User-Agent.
    • ns_http_get and ns_http_post; results via ns_http_response (status + ns_string body).
    • ns_autohttp macro for auto-free; header include/ns_http.h; example examples/18_http.c; Makefile links -lns_http.
  • Bug Fixes

    • POST: binary-safe payloads (raw bytes) and null payloads return NsError::InvalidInput.
    • GET: response decoding errors now return generic NsError::Any.
    • Centralized client configuration to prevent drift between GET and POST.
    • Makefile uninstall uses LIBS_TO_INSTALL to remove all installed libs.

Written for commit 0323427. Summary will update on new commits.

Review in cubic

Introduces the `ns_http` module, wrapping Rust's `reqwest` crate to provide
a modern, synchronous HTTP API to C without the complexity and callback
management of `libcurl`.

Key additions:
- Implemented `ns_http_get` and `ns_http_post` for standard web requests.
- Added `ns_http_response` struct to cleanly capture HTTP status codes and
  pack the response body directly into memory-safe SSO `ns_string` structs.
- Introduced the `ns_autohttp` macro, leveraging the GCC/Clang cleanup
  attribute to provide RAII, automatically freeing HTTP response buffers
  when they fall out of scope.
- Created `18_http.c` example demonstrating fetching
  data and pushing JSON payloads.
- Registered `ns_http` crate in the workspace and added `reqwest` dependency.

Signed-off-by: Vaishnav Sabari Girish <vaishnav.sabari.girish@gmail.com>
Signed-off-by: Vaishnav Sabari Girish <vaishnav.sabari.girish@gmail.com>
Signed-off-by: Vaishnav Sabari Girish <vaishnav.sabari.girish@gmail.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

5 issues found across 10 files

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

Comment thread crates/ns_http/src/lib.rs Outdated
Comment thread Makefile
Comment thread crates/ns_http/src/lib.rs Outdated
Comment thread crates/ns_http/src/lib.rs Outdated
Comment thread examples/18_http.c Outdated
- ns_http: Replaced `to_string_lossy()` with raw byte extraction (`to_bytes().to_vec()`) for POST payloads to prevent the silent corruption of non-UTF-8 and binary data.
- ns_http: Added explicit UTF-8 validation for GET response bodies, correctly returning `NsError::StringInvalidUtf8` upon failure.
- ns_http: Updated null pointer validation in POST requests to return `NsError::InvalidInput` instead of a generic error.
- ns_http: Also added bot-check bypass for sites protected by bots
- build: Refactored the Makefile `uninstall` target to dynamically sync with `LIBS_TO_INSTALL` (using `addprefix` and `notdir`), fixing the bug where local build caches were targeted instead of system directories.
- examples: Fixed capitalization typo in `18_http.c` console output.

Signed-off-by: Vaishnav Sabari Girish <vaishnav.sabari.girish@gmail.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread crates/ns_http/src/lib.rs Outdated
Comment thread crates/ns_http/src/lib.rs Outdated
…ling

- ns_http: Extracted duplicated `reqwest` client configuration into a single `build_default_client()` helper to prevent config drift between GET and POST requests.
- ns_http: Updated error mapping in `ns_http_get` response text parsing to return the generic `NsError::Any` instead of `NsError::StringInvalidUtf8`.

Signed-off-by: Vaishnav Sabari Girish <vaishnav.sabari.girish@gmail.com>
@Vaishnav-Sabari-Girish Vaishnav-Sabari-Girish merged commit 42f855c into main Jun 26, 2026
6 checks passed
@Vaishnav-Sabari-Girish Vaishnav-Sabari-Girish deleted the feat/ns_http branch June 26, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant