10
10
class ServerErrorHandler : public REQUEST_HANDLER
11
11
{
12
12
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
+
13
23
ServerErrorHandler (IHttpContext& pContext, USHORT statusCode, USHORT subStatusCode, std::string statusText, HRESULT hr, HINSTANCE module , bool disableStartupPage, int page, BYTE* content, int length) noexcept
14
24
: REQUEST_HANDLER(pContext),
15
25
m_pContext (pContext),
@@ -18,9 +28,9 @@ class ServerErrorHandler : public REQUEST_HANDLER
18
28
m_statusCode(statusCode),
19
29
m_subStatusCode(subStatusCode),
20
30
m_statusText(std::move(statusText)),
31
+ m_page(page),
21
32
m_ExceptionInfoContent(content),
22
33
m_length(length),
23
- m_page(page),
24
34
m_moduleInstance(module )
25
35
{
26
36
}
@@ -43,24 +53,6 @@ class ServerErrorHandler : public REQUEST_HANDLER
43
53
return ;
44
54
}
45
55
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
-
64
56
HTTP_DATA_CHUNK dataChunk = {};
65
57
IHttpResponse* pResponse = pContext.GetResponse ();
66
58
pResponse->SetStatus (m_statusCode, m_statusText.c_str (), m_subStatusCode, hr, nullptr , true );
@@ -69,10 +61,19 @@ class ServerErrorHandler : public REQUEST_HANDLER
69
61
(USHORT)strlen (" text/html" ),
70
62
FALSE
71
63
);
72
- dataChunk.DataChunkType = HttpDataChunkFromMemory;
73
64
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
+
76
77
pResponse->WriteEntityChunkByReference (&dataChunk);
77
78
}
78
79
0 commit comments