Skip to content

Commit 055d4f4

Browse files
bmehta001Copilot
andcommitted
WinRt: map cancel to Aborted and clear partial body on rejection (round 4)
Address Copilot review round 4: HttpResponseDecoder processes any non-empty response body regardless of HttpResult (processBody runs when GetBody() is non-empty), so a partial body left on a rejected streamed response could be parsed for kill-switch/stats. In the WinRt streaming reader: - Map a caller-initiated cancellation (task_status::canceled, from cancel()) to HttpResult_Aborted instead of NetworkFailure. - Clear response->m_body on every non-success path (cancel, read failure, over-cap, and streaming exceptions) so no partial body is processed. (WinInet and Apple never attach a partial body to the response on rejection, so they need no change.) Files: - lib/http/HttpClient_WinRt.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0d61e8f commit 055d4f4

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

‎lib/http/HttpClient_WinRt.cpp‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,27 +228,32 @@ namespace MAT_NS_BEGIN {
228228
{
229229
auto streamOp = m_httpResponseMessage->Content->ReadAsInputStreamAsync();
230230
auto streamTask = create_task(streamOp, m_cancellationTokenSource.get_token());
231-
if (streamTask.wait() == task_status::completed)
231+
auto status = streamTask.wait();
232+
if (status == task_status::completed)
232233
{
233234
inputStream = streamTask.get();
234235
}
236+
else
237+
{
238+
// Caller-initiated cancel maps to Aborted; anything else is a failure.
239+
response->m_result = (status == task_status::canceled) ? HttpResult_Aborted : HttpResult_NetworkFailure;
240+
}
235241
}
236242

237-
if (inputStream == nullptr)
238-
{
239-
response->m_result = HttpResult_NetworkFailure;
240-
}
241-
else
243+
if (inputStream != nullptr)
242244
{
243245
const unsigned int chunkSize = 64 * 1024;
244246
for (;;)
245247
{
246248
Buffer^ chunk = ref new Buffer(chunkSize);
247249
auto readOp = inputStream->ReadAsync(chunk, chunkSize, InputStreamOptions::Partial);
248250
auto readTask = create_task(readOp, m_cancellationTokenSource.get_token());
249-
if (readTask.wait() != task_status::completed)
251+
auto status = readTask.wait();
252+
if (status != task_status::completed)
250253
{
251-
response->m_result = HttpResult_NetworkFailure;
254+
// Drop any partial body; caller cancel -> Aborted, else failure.
255+
response->m_result = (status == task_status::canceled) ? HttpResult_Aborted : HttpResult_NetworkFailure;
256+
response->m_body.clear();
252257
break;
253258
}
254259

@@ -263,6 +268,7 @@ namespace MAT_NS_BEGIN {
263268
{
264269
LOG_WARN("HTTP response exceeds max buffered size (%zu bytes); aborting", MAX_HTTP_RESPONSE_SIZE);
265270
response->m_result = HttpResult_NetworkFailure;
271+
response->m_body.clear();
266272
break;
267273
}
268274

@@ -278,12 +284,15 @@ namespace MAT_NS_BEGIN {
278284
}
279285
catch (Platform::Exception^ ex)
280286
{
287+
// A faulted read rethrows here; drop any partial body and fail the request.
281288
LOG_WARN("Reading HTTP response body failed: 0x%08x", ex->HResult);
282289
response->m_result = HttpResult_NetworkFailure;
290+
response->m_body.clear();
283291
}
284292
catch (...)
285293
{
286294
response->m_result = HttpResult_NetworkFailure;
295+
response->m_body.clear();
287296
}
288297
}
289298
else

0 commit comments

Comments
 (0)