@@ -62,9 +62,10 @@ class Client : public Object {
6262 bool enable_proxy = false ;
6363 std::string_view uds_path; // If set, Unix Domain Socket will be used instead of TCP.
6464 // URL should still be the format of http://localhost/xxx
65- IStream* body_stream = nullptr ; // use body_stream as body
66- using BodyWriter = Delegate<ssize_t , Request*>; // or call body_writer if body_stream
67- BodyWriter body_writer = {}; // is not set
65+
66+ IStream* body_stream = nullptr ; // priority: set_body > body_stream > body_writer
67+ using BodyWriter = Delegate<ssize_t , Request*>;
68+ BodyWriter body_writer = {};
6869
6970 static Operation* create (Client* c, Verb v, std::string_view url,
7071 uint16_t buf_size = 64 * 1024 - 1 ) {
@@ -91,9 +92,22 @@ class Client : public Object {
9192 uds_path = unix_socket_path;
9293 return _client->call (this );
9394 }
95+ // set body buffer and set content length automatically
96+ void set_body (const void *buf, size_t size) {
97+ body_buffer = buf;
98+ body_buffer_size = size;
99+ req.headers .content_length (size);
100+ }
101+ void set_body (std::string_view buf) {
102+ set_body (buf.data (), buf.length ());
103+ }
104+
94105
95106 protected:
96107 Client* _client;
108+ const void *body_buffer = nullptr ;
109+ size_t body_buffer_size = 0 ;
110+
97111 char _buf[0 ];
98112 Operation (Client* c, Verb v, std::string_view url, uint16_t buf_size)
99113 : req(_buf, buf_size, v, url, c->has_proxy ()),
@@ -106,6 +120,8 @@ class Client : public Object {
106120 explicit Operation (uint16_t buf_size) : req(_buf, buf_size), _client(nullptr ) {}
107121 Operation () = delete;
108122 ~Operation () = default ;
123+
124+ friend class ClientImpl ;
109125 };
110126
111127 template <uint16_t BufferSize = UINT16_MAX >
0 commit comments