Skip to content

Commit

Permalink
Take integer request header values (#11)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Nov 22, 2023
1 parent 14889ae commit ae16866
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/http/include/sourcemeta/hydra/http_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class SOURCEMETA_HYDRA_HTTP_EXPORT Request {
auto capture(std::string header) -> void;
auto capture(std::initializer_list<std::string> headers) -> void;
auto header(std::string_view key, std::string_view value) -> void;
auto header(std::string_view key, int value) -> void;

auto send() -> std::future<Response>;

private:
Expand Down
1 change: 1 addition & 0 deletions src/http/include/sourcemeta/hydra/http_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SOURCEMETA_HYDRA_HTTP_EXPORT Stream {

auto method(const Method method) noexcept -> void;
auto header(std::string_view key, std::string_view value) -> void;
auto header(std::string_view key, int value) -> void;
auto send() -> std::future<Status>;

using DataCallback =
Expand Down
4 changes: 4 additions & 0 deletions src/http/request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ auto Request::header(std::string_view key, std::string_view value) -> void {
this->stream.header(key, value);
}

auto Request::header(std::string_view key, int value) -> void {
this->stream.header(key, value);
}

auto Request::send() -> std::future<Response> {
std::ostringstream output;
this->stream.on_data(
Expand Down
4 changes: 4 additions & 0 deletions src/http/stream_curl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ auto Stream::header(std::string_view key, std::string_view value) -> void {
curl_slist_append(this->internal->headers, result.c_str());
}

auto Stream::header(std::string_view key, int value) -> void {
this->header(key, std::to_string(value));
}

auto Stream::send() -> std::future<Status> {
switch (this->internal->method) {
case Method::GET:
Expand Down

0 comments on commit ae16866

Please sign in to comment.