| 1041 | bool responseSent = false; |
| 1042 | |
| 1043 | Result append(Span<const char> data) |
| 1044 | { |
| 1045 | GrowableBuffer<Buffer> gb(body); |
| 1046 | HttpStringAppend& sb = static_cast<HttpStringAppend&>(static_cast<IGrowableBuffer&>(gb)); |
| 1047 | return Result(sb.append(data, 0)); |
| 1048 | } |
| 1049 | |
| 1050 | void onData(AsyncBufferView::ID bufferID) |
| 1051 | { |
| 1052 | SC_ASSERT_RELEASE(connection != nullptr); |
| 1053 | AsyncReadableStream& readable = connection->request.getReadableStream(); |
| 1054 | Span<const char> data; |
| 1055 | SC_ASSERT_RELEASE(readable.getBuffersPool().getReadableData(bufferID, data)); |
| 1056 | SC_ASSERT_RELEASE(append(data)); |
| 1057 | SC_ASSERT_RELEASE(connection->request.consumeBodyBytes(data.sizeInBytes())); |
| 1058 | } |
| 1059 | |
| 1060 | void onEnd() |
| 1061 | { |
| 1062 | SC_ASSERT_RELEASE(connection != nullptr); |
| 1063 | SC_ASSERT_RELEASE(connection->request.getBodyFramingKind() == HttpBodyFramingKind::Chunked); |
| 1064 | SC_ASSERT_RELEASE(StringView(StringSpan(body.toSpanConst(), false, StringEncoding::Ascii)) == |
| 1065 | "ChunkedBody"); |
| 1066 | responseSent = true; |
| 1067 | SC_ASSERT_RELEASE(connection->response.startResponse(200)); |
| 1068 | SC_ASSERT_RELEASE(connection->response.addHeader("Content-Length", "6")); |
| 1069 | SC_ASSERT_RELEASE(connection->response.sendHeaders()); |
| 1070 | SC_ASSERT_RELEASE(connection->response.getWritableStream().write("stored")); |
| 1071 | SC_ASSERT_RELEASE(connection->response.end()); |
| 1072 | } |
| 1073 | |
| 1074 | [[nodiscard]] StringSpan view() const { return {body.toSpanConst(), false, StringEncoding::Ascii}; } |
| 1075 | } serverCtx; |
| 1076 | |
| 1077 | httpServer.onRequest = [this, &serverCtx](HttpConnection& connection) |
| 1078 | { |
| 1079 | serverCtx.connection = &connection; |
| 1080 | const bool addedData = |
| 1081 | connection.request.getReadableStream().eventData.addListener<ServerContext, &ServerContext::onData>( |
| 1082 | serverCtx); |
| 1083 | SC_TEST_EXPECT(addedData); |
| 1084 | const bool addedEnd = |
| 1085 | connection.request.getReadableStream().eventEnd.addListener<ServerContext, &ServerContext::onEnd>( |
| 1086 | serverCtx); |
| 1087 | SC_TEST_EXPECT(addedEnd); |
| 1088 | }; |
| 1089 | |
| 1090 | ClientConnection clientStorage; |
| 1091 | HttpAsyncClient client; |
| 1092 | ResponseCollector collector; |
| 1093 | ChunkedBodyStream bodyStream; |
| 1094 | TimeoutGuard timeout; |
| 1095 | |
| 1096 | struct Context |
| 1097 | { |
| 1098 | ResponseCollector& collector; |
| 1099 | HttpAsyncServer& httpServer; |
| 1100 | ServerContext& serverCtx; |
nothing calls this directly
no test coverage detected