@@ -44,73 +44,34 @@ class MyHttpModule : public CHttpModule
44
44
pszUserAgent = pHttpRequest->GetHeader (" User-Agent" ,&cchUserAgent);
45
45
46
46
// The header length will be 0 if the header was not found.
47
- if (cchUserAgent == 0 )
47
+ if (pszUserAgent == NULL || cchUserAgent == 0 )
48
48
{
49
49
// Return a status message.
50
50
WriteResponseMessage (pHttpContext,
51
51
" User-Agent: " ," (none)" );
52
52
}
53
53
else
54
54
{
55
- // Allocate space to store the header.
56
- pszUserAgent = (PCSTR) pHttpContext->AllocateRequestMemory ( cchUserAgent + 1 );
57
-
58
- // Test for an error.
59
- if (pszUserAgent==NULL )
60
- {
61
- // Set the error status.
62
- hr = HRESULT_FROM_WIN32 (ERROR_NOT_ENOUGH_MEMORY);
63
- pProvider->SetErrorStatus ( hr );
64
- // End additional processing.
65
- return RQ_NOTIFICATION_FINISH_REQUEST;
66
- }
67
-
68
- // Retrieve the "User-Agent" header.
69
- pszUserAgent = pHttpRequest->GetHeader (" User-Agent" ,&cchUserAgent);
70
- // Test for an error.
71
- if (pszUserAgent!=NULL )
72
- {
73
- // Return the header information.
74
- WriteResponseMessage (pHttpContext,
75
- " User-Agent: " ,pszUserAgent);
76
- }
55
+ // Return the header information.
56
+ WriteResponseMessage (pHttpContext,
57
+ " User-Agent: " ,pszUserAgent);
77
58
}
78
59
79
60
// Look for the "Accept-Language" header.
80
61
pszAcceptLanguage = pHttpRequest->GetHeader (HttpHeaderAcceptLanguage,&cchAcceptLanguage);
81
62
82
63
// The header length will be 0 if the header was not found.
83
- if (cchAcceptLanguage == 0 )
64
+ if (pszAcceptLanguage == NULL || cchAcceptLanguage == 0 )
84
65
{
85
66
// Return a status message.
86
67
WriteResponseMessage (pHttpContext,
87
68
" \n Accept-Language: " ," (none)" );
88
69
}
89
70
else
90
71
{
91
- // Allocate space to store the header.
92
- pszAcceptLanguage = (PCSTR) pHttpContext->AllocateRequestMemory ( cchAcceptLanguage + 1 );
93
-
94
- // Test for an error.
95
- if (pszAcceptLanguage==NULL )
96
- {
97
- // Set the error status.
98
- hr = HRESULT_FROM_WIN32 (ERROR_NOT_ENOUGH_MEMORY);
99
- pProvider->SetErrorStatus ( hr );
100
- // End additional processing.
101
- return RQ_NOTIFICATION_FINISH_REQUEST;
102
- }
103
-
104
- // Retrieve the "Accept-Language" header.
105
- pszAcceptLanguage = pHttpRequest->GetHeader (HttpHeaderAcceptLanguage,&cchAcceptLanguage);
106
-
107
- // Test for an error.
108
- if (pszAcceptLanguage!=NULL )
109
- {
110
- // Return the header information.
111
- WriteResponseMessage (pHttpContext,
112
- " \n Accept-Language: " ,pszAcceptLanguage);
113
- }
72
+ // Return the header information.
73
+ WriteResponseMessage (pHttpContext,
74
+ " \n Accept-Language: " ,pszAcceptLanguage);
114
75
}
115
76
// End additional processing.
116
77
return RQ_NOTIFICATION_FINISH_REQUEST;
@@ -131,7 +92,7 @@ class MyHttpModule : public CHttpModule
131
92
{
132
93
// Create an HRESULT to receive return values from methods.
133
94
HRESULT hr;
134
-
95
+
135
96
// Create a data chunk.
136
97
HTTP_DATA_CHUNK dataChunk;
137
98
// Set the chunk to a chunk in memory.
@@ -182,7 +143,7 @@ class MyHttpModuleFactory : public IHttpModuleFactory
182
143
public:
183
144
HRESULT
184
145
GetHttpModule (
185
- OUT CHttpModule ** ppModule,
146
+ OUT CHttpModule ** ppModule,
186
147
IN IModuleAllocator * pAllocator
187
148
)
188
149
{
@@ -204,7 +165,7 @@ class MyHttpModuleFactory : public IHttpModuleFactory
204
165
pModule = NULL ;
205
166
// Return a success status.
206
167
return S_OK;
207
- }
168
+ }
208
169
}
209
170
210
171
void Terminate ()
@@ -233,4 +194,4 @@ RegisterModule(
233
194
0
234
195
);
235
196
}
236
- // </Snippet1>
197
+ // </Snippet1>
0 commit comments