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