Skip to content

Commit 588c52c

Browse files
committed
feat(requests): support controlled registry response handling
1 parent ef83430 commit 588c52c

5 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎include/vix/requests/RequestOptions.hpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ namespace vix::requests
4242
*/
4343
using BodySink = std::function<void(std::span<const std::byte> chunk)>;
4444

45+
/** @brief Observes each parsed response head before that response's body delivery. */
46+
using ResponseHeadSink = std::function<void(int statusCode, const Headers &headers)>;
47+
4548
/**
4649
* @brief Basic authentication credentials.
4750
*/
@@ -138,6 +141,9 @@ namespace vix::requests
138141
*/
139142
BodySink body_sink;
140143

144+
/** @brief Optional callback invoked after response headers and before body bytes. */
145+
ResponseHeadSink response_head_sink;
146+
141147
/**
142148
* @brief Checks whether redirects are enabled.
143149
*

‎include/vix/requests/Url.hpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ namespace vix::requests
192192
*/
193193
[[nodiscard]] Url parse_url(std::string_view value);
194194

195+
/** @brief Resolves an absolute or relative URL reference against a base URL. */
196+
[[nodiscard]] std::string resolve_url_reference(
197+
const Url &base, std::string_view reference);
198+
195199
/**
196200
* @brief Appends a query string to an existing URL string.
197201
*

‎src/RequestOptions.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ namespace vix::requests
126126
merged.body_sink = overrideOptions.body_sink;
127127
}
128128

129+
if (overrideOptions.response_head_sink)
130+
{
131+
merged.response_head_sink = overrideOptions.response_head_sink;
132+
}
133+
129134
return merged;
130135
}
131136

‎src/http/HttpParser.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ namespace vix::requests::http
511511

512512
response_ = Response(
513513
finalUrl_, head.statusCode, head.reason, head.headers, {});
514+
if (options_.response_head_sink)
515+
{
516+
options_.response_head_sink(head.statusCode, head.headers);
517+
}
514518
http11_ = head.version == "HTTP/1.1";
515519
bodyInfo_ = detect_body_info(
516520
head.statusCode, head.headers, expectBody_);

‎src/http/RedirectPolicy.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,11 @@ namespace vix::requests::http
293293
}
294294

295295
} // namespace vix::requests::http
296+
297+
namespace vix::requests
298+
{
299+
std::string resolve_url_reference(const Url &base, std::string_view reference)
300+
{
301+
return http::resolve_redirect_url(base, reference);
302+
}
303+
} // namespace vix::requests

0 commit comments

Comments
 (0)