adding error description which was commented out previously (#613)

This commit is contained in:
pan-wang 2018-02-27 09:41:09 -08:00 committed by GitHub
parent 8df5b8931b
commit 792b72e71a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 57 deletions

View File

@ -18,6 +18,7 @@ SRWLOCK g_srwLockRH;
HINTERNET g_hWinhttpSession = NULL; HINTERNET g_hWinhttpSession = NULL;
IHttpServer * g_pHttpServer = NULL; IHttpServer * g_pHttpServer = NULL;
HINSTANCE g_hWinHttpModule; HINSTANCE g_hWinHttpModule;
HINSTANCE g_hAspNetCoreModule;
HANDLE g_hEventLog = NULL; HANDLE g_hEventLog = NULL;
@ -160,6 +161,8 @@ EnsureOutOfProcessInitializtion()
g_hWinHttpModule = GetModuleHandle(TEXT("winhttp.dll")); g_hWinHttpModule = GetModuleHandle(TEXT("winhttp.dll"));
g_hAspNetCoreModule = GetModuleHandle(TEXT("aspnetcore.dll"));
hr = WINHTTP_HELPER::StaticInitialize(); hr = WINHTTP_HELPER::StaticInitialize();
if (FAILED(hr)) if (FAILED(hr))
{ {

View File

@ -572,32 +572,32 @@ Failure:
pResponse->SetStatus(502, "Bad Gateway", 3, hr); pResponse->SetStatus(502, "Bad Gateway", 3, hr);
// if (!(hr > HRESULT_FROM_WIN32(WINHTTP_ERROR_BASE) && if (!(hr > HRESULT_FROM_WIN32(WINHTTP_ERROR_BASE) &&
// hr <= HRESULT_FROM_WIN32(WINHTTP_ERROR_LAST)) || hr <= HRESULT_FROM_WIN32(WINHTTP_ERROR_LAST)) ||
//#pragma prefast (suppress : __WARNING_FUNCTION_NEEDS_REVIEW, "Function and parameters reviewed.") #pragma prefast (suppress : __WARNING_FUNCTION_NEEDS_REVIEW, "Function and parameters reviewed.")
// FormatMessage( FormatMessage(
// FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_HMODULE, FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_HMODULE,
// g_hWinHttpModule, g_hWinHttpModule,
// HRESULT_CODE(hr), HRESULT_CODE(hr),
// 0, 0,
// strDescription.QueryStr(), strDescription.QueryStr(),
// strDescription.QuerySizeCCH(), strDescription.QuerySizeCCH(),
// NULL) == 0) NULL) == 0)
// { {
// /*LoadString(g_hModule, LoadString(g_hAspNetCoreModule,
// IDS_SERVER_ERROR, IDS_SERVER_ERROR,
// strDescription.QueryStr(), strDescription.QueryStr(),
// strDescription.QuerySizeCCH());*/ strDescription.QuerySizeCCH());
// } }
//
// (VOID)strDescription.SyncWithBuffer(); (VOID)strDescription.SyncWithBuffer();
// if (strDescription.QueryCCH() != 0) if (strDescription.QueryCCH() != 0)
// { {
// pResponse->SetErrorDescription( pResponse->SetErrorDescription(
// strDescription.QueryStr(), strDescription.QueryStr(),
// strDescription.QueryCCH(), strDescription.QueryCCH(),
// FALSE); FALSE);
// } }
} }
// //
@ -1421,40 +1421,42 @@ None
Failure: Failure:
m_RequestStatus = FORWARDER_DONE; if (!m_fHasError)
m_fHasError = TRUE;
pResponse->DisableKernelCache();
pResponse->GetRawHttpResponse()->EntityChunkCount = 0;
if (hr == HRESULT_FROM_WIN32(ERROR_WINHTTP_INVALID_SERVER_RESPONSE))
{ {
m_fResetConnection = TRUE; m_RequestStatus = FORWARDER_DONE;
} m_fHasError = TRUE;
if (fClientError || m_fHandleClosedDueToClient) pResponse->DisableKernelCache();
{ pResponse->GetRawHttpResponse()->EntityChunkCount = 0;
if (!m_fResponseHeadersReceivedAndSet)
if (hr == HRESULT_FROM_WIN32(ERROR_WINHTTP_INVALID_SERVER_RESPONSE))
{ {
pResponse->SetStatus(400, "Bad Request", 0, HRESULT_FROM_WIN32(WSAECONNRESET)); m_fResetConnection = TRUE;
}
if (fClientError || m_fHandleClosedDueToClient)
{
if (!m_fResponseHeadersReceivedAndSet)
{
pResponse->SetStatus(400, "Bad Request", 0, HRESULT_FROM_WIN32(WSAECONNRESET));
}
else
{
//
// Response headers from origin server were
// already received and set for the current response.
// Honor the response status.
//
}
} }
else else
{ {
// STACK_STRU(strDescription, 128);
// Response headers from origin server were
// already received and set for the current response.
// Honor the response status.
//
}
}
else
{
STACK_STRU(strDescription, 128);
pResponse->SetStatus(502, "Bad Gateway", 3, hr); pResponse->SetStatus(502, "Bad Gateway", 3, hr);
/*
if (!(hr > HRESULT_FROM_WIN32(WINHTTP_ERROR_BASE) && if (!(hr > HRESULT_FROM_WIN32(WINHTTP_ERROR_BASE) &&
hr <= HRESULT_FROM_WIN32(WINHTTP_ERROR_LAST)) || hr <= HRESULT_FROM_WIN32(WINHTTP_ERROR_LAST)) ||
#pragma prefast (suppress : __WARNING_FUNCTION_NEEDS_REVIEW, "Function and parameters reviewed.") #pragma prefast (suppress : __WARNING_FUNCTION_NEEDS_REVIEW, "Function and parameters reviewed.")
FormatMessage( FormatMessage(
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_HMODULE, FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_HMODULE,
@ -1465,7 +1467,7 @@ Failure:
strDescription.QuerySizeCCH(), strDescription.QuerySizeCCH(),
NULL) == 0) NULL) == 0)
{ {
LoadString(g_hModule, LoadString(g_hAspNetCoreModule,
IDS_SERVER_ERROR, IDS_SERVER_ERROR,
strDescription.QueryStr(), strDescription.QueryStr(),
strDescription.QuerySizeCCH()); strDescription.QuerySizeCCH());
@ -1478,9 +1480,9 @@ Failure:
strDescription.QueryStr(), strDescription.QueryStr(),
strDescription.QueryCCH(), strDescription.QueryCCH(),
FALSE); FALSE);
}*/ }
}
} }
//}
// FREB log // FREB log
if (ANCMEvents::ANCM_REQUEST_FORWARD_FAIL::IsEnabled(m_pW3Context->GetTraceContext())) if (ANCMEvents::ANCM_REQUEST_FORWARD_FAIL::IsEnabled(m_pW3Context->GetTraceContext()))

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
extern DWORD g_OptionalWinHttpFlags; extern DWORD g_OptionalWinHttpFlags;
extern HINSTANCE g_hWinHttpModule;
extern HINSTANCE g_hAspNetCoreModule;
enum FORWARDING_REQUEST_STATUS enum FORWARDING_REQUEST_STATUS