Skip to content

Add buffer_response for return to client images from buffer#368

Open
akrabad wants to merge 1 commit intoetr:masterfrom
akrabad:dev_buff_response
Open

Add buffer_response for return to client images from buffer#368
akrabad wants to merge 1 commit intoetr:masterfrom
akrabad:dev_buff_response

Conversation

@akrabad
Copy link

@akrabad akrabad commented Feb 27, 2026

Description of the Change

libhttpserver can fill responce with image from file on disk. But not from buffer.
I read from camera jpeg file that stored in buffer. I don't want to save this file to disk and read from disk. To many read/write operations (>5 per/sec)

Possible Drawbacks

Nothing. Use template of nullptr 0 size byte response (if file on disk dosent exist)

Verification Process

Read data from camera. Store it to my buffer. And read from buffer if get request for image

etr pushed a commit that referenced this pull request Feb 27, 2026
The existing string_response already supports binary content (std::string
can hold arbitrary bytes), but this was not documented or demonstrated
anywhere. This gap caused users to believe a new response type was needed
(see PR #368).

- Add a note to the README's string_response description clarifying
  binary data support
- Add a new "Serving binary data from memory" section with inline example
- Add examples/binary_buffer_response.cpp as a complete, buildable example
  that serves a PNG image from an in-memory buffer
- Register the new example in examples/Makefile.am

https://claude.ai/code/session_01S3BvBrSoNvUhpYTyhPYCjJ
@etr
Copy link
Owner

etr commented Feb 27, 2026

Hi @akrabad, thank you for opening this PR and surfacing this use case! Serving binary data (like camera frames) directly from memory without disk I/O is a completely valid need.
The existing string_response already supports this — std::string in C++ can hold arbitrary binary data including null bytes, so it works for images and other binary content out of the box. For example:

std::string jpeg_data(reinterpret_cast<const char*>(camera_buffer), buffer_size);
auto resp = std::make_shared<string_response>(std::move(jpeg_data), 200, "image/jpeg");

That said, the fact that this wasn’t obvious is entirely a documentation gap on our side — the docs and examples only ever showed text usage, so your assumption that a new class was needed was very reasonable.
To address this, #369 adds:
∙ A note in the README clarifying that string_response handles binary data
∙ A new “Serving binary data from memory” documentation section with an example
∙ A complete buildable example (examples/binary_buffer_response.cpp) demonstrating the pattern
Could you take a look at #369 and let us know if that covers your use case? We want to make sure the documentation would have answered your question had it

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