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

Method sendRaw

Tests/Libraries/Http/HttpTestClient.cpp:252–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

250}
251
252SC::Result SC::HttpTestClient::sendRaw(AsyncEventLoop& loop, StringSpan url, StringSpan request)
253{
254 bodyDelay = {};
255 eventLoop = &loop;
256
257 uint16_t port;
258 HttpURLParser urlParser;
259 SC_TRY(urlParser.parse(url));
260 SC_TRY_MSG(urlParser.protocol == "http", "Invalid protocol");
261 char buffer[256];
262 Span<char> ipAddress = {buffer};
263 SC_TRY(SocketDNS::resolveDNS(urlParser.hostname, ipAddress))
264 port = urlParser.port;
265 SocketIPAddress localHost;
266 SC_TRY(localHost.fromAddressPort({ipAddress, true, StringEncoding::Ascii}, port));
267 SC_TRY(eventLoop->createAsyncTCPSocket(localHost.getAddressFamily(), clientSocket));
268
269 {
270 GrowableBuffer<decltype(content)> gb = {content};
271
272 HttpStringAppend& sb = static_cast<HttpStringAppend&>(static_cast<IGrowableBuffer&>(gb));
273 sb.clear();
274 SC_TRY(sb.append(request));
275 headerBytes = content.size();
276 }
277
278 connectAsync.callback.bind<HttpTestClient, &HttpTestClient::startSendingHeaders>(*this);
279 parser = {};
280 parser.type = HttpParser::Type::Response;
281 receivedBytes = 0;
282 parsedBytes = 0;
283 contentLen = 0;
284 headersReceived = false;
285 responseHasNoBody = false;
286 keepConnectionOpen = false;
287 hasActiveConnection = false;
288 return connectAsync.start(*eventLoop, clientSocket, localHost);
289}
290
291SC::StringSpan SC::HttpTestClient::getResponse() const
292{

Callers 6

httpFileServerTestMethod · 0.80
maxHeaderSizeErrorMethod · 0.80

Calls 7

createAsyncTCPSocketMethod · 0.80
getAddressFamilyMethod · 0.80
parseMethod · 0.45
clearMethod · 0.45
appendMethod · 0.45
sizeMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected