MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / commonMethodWrappers

Method commonMethodWrappers

Tests/Libraries/Http/HttpAsyncClientTest.cpp:593–788  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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++;

Callers

nothing calls this directly

Calls 15

StringSpanFunction · 0.85
mapPortMethod · 0.80
patchMethod · 0.80
formatFunction · 0.50
createMethod · 0.45
initMethod · 0.45
startMethod · 0.45
sendEmptyResponseMethod · 0.45
attachMethod · 0.45
detachMethod · 0.45
isEmptyMethod · 0.45
viewMethod · 0.45

Tested by

no test coverage detected