Skip to content

Commit 8bc1872

Browse files
committed
bit of cleanup
1 parent de562c6 commit 8bc1872

File tree

5 files changed

+25
-429
lines changed

5 files changed

+25
-429
lines changed

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/ServerErrorHandler.h

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
class ServerErrorHandler : public REQUEST_HANDLER
1111
{
1212
public:
13+
ServerErrorHandler(IHttpContext& pContext, USHORT statusCode, USHORT subStatusCode, std::string statusText, HRESULT hr, HINSTANCE module, bool disableStartupPage, BYTE* content, int length) noexcept
14+
: ServerErrorHandler(pContext, statusCode, subStatusCode, statusText, hr, module, disableStartupPage, 0, content, length)
15+
{
16+
}
17+
18+
ServerErrorHandler(IHttpContext& pContext, USHORT statusCode, USHORT subStatusCode, std::string statusText, HRESULT hr, HINSTANCE module, bool disableStartupPage, int page) noexcept
19+
: ServerErrorHandler(pContext, statusCode, subStatusCode, statusText, hr, module, disableStartupPage, page, nullptr, 0)
20+
{
21+
}
22+
1323
ServerErrorHandler(IHttpContext& pContext, USHORT statusCode, USHORT subStatusCode, std::string statusText, HRESULT hr, HINSTANCE module, bool disableStartupPage, int page, BYTE* content, int length) noexcept
1424
: REQUEST_HANDLER(pContext),
1525
m_pContext(pContext),
@@ -18,9 +28,9 @@ class ServerErrorHandler : public REQUEST_HANDLER
1828
m_statusCode(statusCode),
1929
m_subStatusCode(subStatusCode),
2030
m_statusText(std::move(statusText)),
31+
m_page(page),
2132
m_ExceptionInfoContent(content),
2233
m_length(length),
23-
m_page(page),
2434
m_moduleInstance(module)
2535
{
2636
}
@@ -43,24 +53,6 @@ class ServerErrorHandler : public REQUEST_HANDLER
4353
return;
4454
}
4555

46-
if (m_length > 0)
47-
{
48-
// TODO cleanup
49-
HTTP_DATA_CHUNK dataChunk = {};
50-
IHttpResponse* pResponse = pContext.GetResponse();
51-
pResponse->SetStatus(m_statusCode, m_statusText.c_str(), m_subStatusCode, hr, nullptr, true);
52-
pResponse->SetHeader("Content-Type",
53-
"text/html",
54-
(USHORT)strlen("text/html"),
55-
FALSE
56-
);
57-
dataChunk.DataChunkType = HttpDataChunkFromMemory;
58-
dataChunk.FromMemory.pBuffer = m_ExceptionInfoContent;
59-
dataChunk.FromMemory.BufferLength = static_cast<ULONG>(m_length);
60-
pResponse->WriteEntityChunkByReference(&dataChunk);
61-
return;
62-
}
63-
6456
HTTP_DATA_CHUNK dataChunk = {};
6557
IHttpResponse* pResponse = pContext.GetResponse();
6658
pResponse->SetStatus(m_statusCode, m_statusText.c_str(), m_subStatusCode, hr, nullptr, true);
@@ -69,10 +61,19 @@ class ServerErrorHandler : public REQUEST_HANDLER
6961
(USHORT)strlen("text/html"),
7062
FALSE
7163
);
72-
dataChunk.DataChunkType = HttpDataChunkFromMemory;
7364

74-
dataChunk.FromMemory.pBuffer = page.data();
75-
dataChunk.FromMemory.BufferLength = static_cast<ULONG>(page.size());
65+
dataChunk.DataChunkType = HttpDataChunkFromMemory;
66+
if (m_length > 0)
67+
{
68+
dataChunk.FromMemory.pBuffer = m_ExceptionInfoContent;
69+
dataChunk.FromMemory.BufferLength = static_cast<ULONG>(m_length);
70+
}
71+
else
72+
{
73+
dataChunk.FromMemory.pBuffer = page.data();
74+
dataChunk.FromMemory.BufferLength = static_cast<ULONG>(page.size());
75+
}
76+
7677
pResponse->WriteEntityChunkByReference(&dataChunk);
7778
}
7879

Binary file not shown.

0 commit comments

Comments
 (0)