Skip to content

Revert "Removing unnecessary memory allocations." #1101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,73 @@ class MyHttpModule : public CHttpModule
pszUserAgent = pHttpRequest->GetHeader("User-Agent",&cchUserAgent);

// The header length will be 0 if the header was not found.
if (pszUserAgent == NULL || cchUserAgent == 0)
if (cchUserAgent == 0)
{
// Return a status message.
WriteResponseMessage(pHttpContext,
"User-Agent: ","(none)");
}
else
{
// Return the header information.
WriteResponseMessage(pHttpContext,
"User-Agent: ",pszUserAgent);
// Allocate space to store the header.
pszUserAgent = (PCSTR) pHttpContext->AllocateRequestMemory( cchUserAgent + 1 );

// Test for an error.
if (pszUserAgent==NULL)
{
// Set the error status.
hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
pProvider->SetErrorStatus( hr );
// End additional processing.
return RQ_NOTIFICATION_FINISH_REQUEST;
}

// Retrieve the "User-Agent" header.
pszUserAgent = pHttpRequest->GetHeader("User-Agent",&cchUserAgent);
// Test for an error.
if (pszUserAgent!=NULL)
{
// Return the header information.
WriteResponseMessage(pHttpContext,
"User-Agent: ",pszUserAgent);
}
}

// Look for the "Accept-Language" header.
pszAcceptLanguage = pHttpRequest->GetHeader(HttpHeaderAcceptLanguage,&cchAcceptLanguage);

// The header length will be 0 if the header was not found.
if (pszAcceptLanguage == NULL || cchAcceptLanguage == 0)
if (cchAcceptLanguage == 0)
{
// Return a status message.
WriteResponseMessage(pHttpContext,
"\nAccept-Language: ","(none)");
}
else
{
// Return the header information.
WriteResponseMessage(pHttpContext,
"\nAccept-Language: ",pszAcceptLanguage);
// Allocate space to store the header.
pszAcceptLanguage = (PCSTR) pHttpContext->AllocateRequestMemory( cchAcceptLanguage + 1 );

// Test for an error.
if (pszAcceptLanguage==NULL)
{
// Set the error status.
hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
pProvider->SetErrorStatus( hr );
// End additional processing.
return RQ_NOTIFICATION_FINISH_REQUEST;
}

// Retrieve the "Accept-Language" header.
pszAcceptLanguage = pHttpRequest->GetHeader(HttpHeaderAcceptLanguage,&cchAcceptLanguage);

// Test for an error.
if (pszAcceptLanguage!=NULL)
{
// Return the header information.
WriteResponseMessage(pHttpContext,
"\nAccept-Language: ",pszAcceptLanguage);
}
}
// End additional processing.
return RQ_NOTIFICATION_FINISH_REQUEST;
Expand All @@ -92,7 +131,7 @@ class MyHttpModule : public CHttpModule
{
// Create an HRESULT to receive return values from methods.
HRESULT hr;

// Create a data chunk.
HTTP_DATA_CHUNK dataChunk;
// Set the chunk to a chunk in memory.
Expand Down Expand Up @@ -143,7 +182,7 @@ class MyHttpModuleFactory : public IHttpModuleFactory
public:
HRESULT
GetHttpModule(
OUT CHttpModule ** ppModule,
OUT CHttpModule ** ppModule,
IN IModuleAllocator * pAllocator
)
{
Expand All @@ -165,7 +204,7 @@ class MyHttpModuleFactory : public IHttpModuleFactory
pModule = NULL;
// Return a success status.
return S_OK;
}
}
}

void Terminate()
Expand Down Expand Up @@ -194,4 +233,4 @@ RegisterModule(
0
);
}
// </Snippet1>
// </Snippet1>