Skip to content

Replace fixed header buffer with dynamic ArrayList in sendHttpRequest#4

Merged
dragosv merged 2 commits intounixsocketfrom
copilot/sub-pr-1-again
Mar 5, 2026
Merged

Replace fixed header buffer with dynamic ArrayList in sendHttpRequest#4
dragosv merged 2 commits intounixsocketfrom
copilot/sub-pr-1-again

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

sendHttpRequest used a fixed 4096-byte stack buffer for building HTTP request headers. Requests with long paths or Content-Type values could exhaust the buffer, returning error.NoSpaceLeft instead of sending the request.

Description

Replaces the fixed [4096]u8 + fixedBufferStream with std.ArrayList(u8) that grows on demand. The function gains an allocator: std.mem.Allocator parameter; callers pass their self.allocator.

Before:

fn sendHttpRequest(stream: anytype, ...) !void {
    var hdr_buf: [4096]u8 = undefined;
    var fbs = std.io.fixedBufferStream(&hdr_buf);
    const w = fbs.writer();
    // ...
    try stream.writeAll(fbs.getWritten());
}

After:

fn sendHttpRequest(allocator: std.mem.Allocator, stream: anytype, ...) !void {
    var hdr_buf = std.ArrayList(u8).init(allocator);
    defer hdr_buf.deinit();
    const w = hdr_buf.writer();
    // ...
    try stream.writeAll(hdr_buf.items);
}
  • doRequest, imagePull, and ping updated to pass self.allocator
  • Unit tests updated to pass std.testing.allocator

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring
  • Performance improvement
  • Test addition/modification
  • CI/CD changes

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Testing

  • Unit tests

Existing sendHttpRequest unit tests pass with std.testing.allocator substituted for the removed stack buffer.

Additional Notes

Internal function signature change only — no public API impact.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: dragosv <422243+dragosv@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on using unix sockets from pull request review Replace fixed header buffer with dynamic ArrayList in sendHttpRequest Mar 5, 2026
@dragosv dragosv marked this pull request as ready for review March 5, 2026 06:38
@dragosv dragosv self-requested a review as a code owner March 5, 2026 06:38
@dragosv dragosv merged commit aba10d6 into unixsocket Mar 5, 2026
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.

2 participants