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

Method responseBodyHelpers

Tests/Libraries/Http/HttpAsyncServerTest.cpp:795–952  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

793
794 SC_TEST_EXPECT(response.sendRedirect(302, "/new-place"));
795 while (writable.flushOne()) {}
796
797 constexpr StringView expected = "HTTP/1.1 302 Found\r\n"
798 "Content-Length: 0\r\n"
799 "Location: /new-place\r\n"
800 "Connection: keep-alive\r\n"
801 "\r\n";
802 SC_TEST_EXPECT(StringSpan(writable.output.toSpanConst(), false, StringEncoding::Ascii) == expected);
803 }
804
805 {
806 SC::AsyncBufferView buffers[4] = {};
807 SC::AsyncBuffersPool pool;
808 pool.setBuffers(buffers);
809
810 RecordedWritableStream writable;
811 SC_TEST_EXPECT(writable.init(pool));
812
813 ProbeHttpResponse response;
814 char headers[256] = {0};
815 response.setup(headers, writable);
816 SC_TEST_EXPECT(not response.sendRedirect(200, "/not-a-redirect"));
817
818 ProbeHttpResponse emptyLocationResponse;
819 emptyLocationResponse.setup(headers, writable);
820 SC_TEST_EXPECT(not emptyLocationResponse.sendRedirect(302, ""));
821 }
822
823 {
824 SC::AsyncBufferView buffers[4] = {};
825 SC::AsyncBuffersPool pool;
826 pool.setBuffers(buffers);
827
828 RecordedWritableStream writable;
829 SC_TEST_EXPECT(writable.init(pool));
830
831 ProbeHttpResponse response;
832 char headers[256] = {0};
833 response.setup(headers, writable);
834
835 SC_TEST_EXPECT(response.sendMethodNotAllowed("GET, POST"));
836 while (writable.flushOne()) {}
837
838 constexpr StringView expected = "HTTP/1.1 405 Method Not Allowed\r\n"
839 "Content-Length: 0\r\n"
840 "Allow: GET, POST\r\n"
841 "Connection: keep-alive\r\n"
842 "\r\n";
843 SC_TEST_EXPECT(StringSpan(writable.output.toSpanConst(), false, StringEncoding::Ascii) == expected);
844 }
845
846 {
847 SC::AsyncBufferView buffers[4] = {};
848 SC::AsyncBuffersPool pool;
849 pool.setBuffers(buffers);
850
851 RecordedWritableStream writable;
852 SC_TEST_EXPECT(writable.init(pool));

Callers

nothing calls this directly

Calls 14

StringSpanFunction · 0.85
sendTextMethod · 0.80
sendRedirectMethod · 0.80
sendMethodNotAllowedMethod · 0.80
sendJsonMethod · 0.80
startBodyMethod · 0.80
sendHeadersMethod · 0.80
sendBodyMethod · 0.80
initMethod · 0.45
setupMethod · 0.45
flushOneMethod · 0.45
addHeaderMethod · 0.45

Tested by

no test coverage detected