| 591 | Buffer patchBody; |
| 592 | |
| 593 | int patchRequests = 0; |
| 594 | int optionsRequests = 0; |
| 595 | int deleteRequests = 0; |
| 596 | |
| 597 | Result append(Span<const char> data) |
| 598 | { |
| 599 | GrowableBuffer<Buffer> gb(patchBody); |
| 600 | HttpStringAppend& sb = static_cast<HttpStringAppend&>(static_cast<IGrowableBuffer&>(gb)); |
| 601 | return Result(sb.append(data, 0)); |
| 602 | } |
| 603 | |
| 604 | Result sendEmptyResponse(int statusCode) |
| 605 | { |
| 606 | SC_TRY(connection->response.startResponse(statusCode)); |
| 607 | SC_TRY(connection->response.addHeader("Content-Length", "0")); |
| 608 | SC_TRY(connection->response.sendHeaders()); |
| 609 | return connection->response.end(); |
| 610 | } |
| 611 | |
| 612 | void onPatchData(AsyncBufferView::ID bufferID) |
| 613 | { |
| 614 | Span<const char> data; |
| 615 | SC_ASSERT_RELEASE(connection != nullptr); |
| 616 | SC_ASSERT_RELEASE(connection->request.getReadableStream().getBuffersPool().getReadableData(bufferID, data)); |
| 617 | SC_ASSERT_RELEASE(append(data)); |
| 618 | SC_ASSERT_RELEASE(connection->request.consumeBodyBytes(data.sizeInBytes())); |
| 619 | } |
| 620 | |
| 621 | void onPatchEnd() |
| 622 | { |
| 623 | test->recordExpectation("patch body", |
| 624 | StringView(patchBody.toSpanConst(), false, StringEncoding::Ascii) == "patch"); |
| 625 | test->recordExpectation("patch response", sendEmptyResponse(200)); |
| 626 | } |
| 627 | |
| 628 | explicit ServerContext(HttpAsyncClientTest* testCase) : test(testCase) {} |
| 629 | } serverContext(this); |
| 630 | |
| 631 | httpServer.onRequest = [this, &serverContext](HttpConnection& connection) |
| 632 | { |
| 633 | serverContext.connection = &connection; |
| 634 | if (connection.request.getParser().method == HttpParser::Method::HttpPATCH) |
| 635 | { |
| 636 | serverContext.patchRequests++; |
| 637 | SC_TEST_EXPECT(connection.request.getRequestTarget() == "/patch"); |
| 638 | const bool addedData = |
| 639 | connection.request.getReadableStream() |
| 640 | .eventData.addListener<ServerContext, &ServerContext::onPatchData>(serverContext); |
| 641 | const bool addedEnd = |
| 642 | connection.request.getReadableStream().eventEnd.addListener<ServerContext, &ServerContext::onPatchEnd>( |
| 643 | serverContext); |
| 644 | SC_TEST_EXPECT(addedData); |
| 645 | SC_TEST_EXPECT(addedEnd); |
| 646 | return; |
| 647 | } |
| 648 | if (connection.request.getParser().method == HttpParser::Method::HttpOPTIONS) |
| 649 | { |
| 650 | serverContext.optionsRequests++; |
nothing calls this directly
no test coverage detected