@@ -90,7 +90,7 @@ class REQUEST_STORED_CONTEXT : public IHttpStoredContext
9090ULONGLONGm_pResponseLength;
9191ULONGLONGm_pResponsePosition;
9292
93- preAllocBodyChunk*head ;
93+ preAllocBodyChunk*requestBodyBufferHead ;
9494};
9595
9696
@@ -296,6 +296,44 @@ REQUEST_STORED_CONTEXT *RetrieveIISContext(request_rec *r)
296296return NULL ;
297297}
298298
299+ HRESULTGetRequestBodyFromIIS (IHttpRequest* pRequest, preAllocBodyChunk** head)
300+ {
301+ HRESULT hr = S_OK;
302+ HTTP_REQUEST * pRawRequest = pRequest->GetRawHttpRequest ();
303+ preAllocBodyChunk** cur = head;
304+ while (pRequest->GetRemainingEntityBytes () >0 )
305+ {
306+ // Allocate memory for the preAllocBodyChunk linked list structure, and also the actual body content
307+ // HUGE_STRING_LEN is hardcoded because this is also hardcoded in apache2_io.c's call to ap_get_brigade
308+ preAllocBodyChunk* chunk = (preAllocBodyChunk*)malloc (sizeof (preAllocBodyChunk) + HUGE_STRING_LEN);
309+ chunk->next =NULL ;
310+
311+ // Pointer to rest of allocated memory, for convenience
312+ chunk->data = chunk +1 ;
313+
314+ DWORD readcnt =0 ;
315+ hr = pRequest->ReadEntityBody (chunk->data , HUGE_STRING_LEN,false , &readcnt,NULL );
316+ if (ERROR_HANDLE_EOF == (hr &0x0000FFFF ))
317+ {
318+ free (chunk);
319+ hr = S_OK;
320+ break ;
321+ }
322+ chunk->length = readcnt;
323+
324+ // Append to linked list
325+ *cur = chunk;
326+ cur = &(chunk->next );
327+
328+ if (hr != S_OK)
329+ {
330+ break ;
331+ }
332+ }
333+
334+ return hr;
335+ }
336+
299337HRESULTCMyHttpModule::ReadFileChunk (HTTP_DATA_CHUNK *chunk,char *buf)
300338{
301339 OVERLAPPED ovl;
@@ -764,46 +802,12 @@ CMyHttpModule::OnBeginRequest(
764802
765803// Get request body without holding lock, because some clients may be slow at sending
766804LeaveCriticalSection (&m_csLock);
767- HTTP_REQUEST * pRawRequest = pRequest->GetRawHttpRequest ();
768- preAllocBodyChunk* head =NULL ;
769- preAllocBodyChunk* cur =NULL ;
770- while (pRequest->GetRemainingEntityBytes () >0 )
805+ preAllocBodyChunk* requestBodyBufferHead =NULL ;
806+ hr =GetRequestBodyFromIIS (pRequest, &requestBodyBufferHead);
807+ if (hr != S_OK)
771808 {
772- // Allocate memory for the preAllocBodyChunk linked list structure, and also the actual body content
773- // HUGE_STRING_LEN is hardcoded because this is also hardcoded in apache2_io.c's call to ap_get_brigade
774- preAllocBodyChunk* chunk = (preAllocBodyChunk*)malloc (sizeof (preAllocBodyChunk) + HUGE_STRING_LEN);
775- chunk->next =NULL ;
776-
777- // Pointer to rest of allocated memory, for convenience
778- chunk->data = chunk +1 ;
779-
780- DWORD readcnt;
781- HRESULT hr = pRequest->ReadEntityBody (chunk->data , HUGE_STRING_LEN,false , &readcnt,NULL );
782- if (ERROR_HANDLE_EOF == (hr &0x0000FFFF ))
783- {
784- free (chunk);
785- break ;
786- }
787- chunk->length = readcnt;
788-
789- if (!head)
790- {
791- // Initialize linked list
792- head = chunk;
793- cur = chunk;
794- }
795- else {
796- // Append to linked list
797- cur->next = chunk;
798- cur = chunk;
799- }
800-
801- if (hr != S_OK)
802- {
803- goto Finished;
804- }
809+ goto FinishedWithoutLock;
805810 }
806-
807811EnterCriticalSection (&m_csLock);
808812
809813// Get the config again, in case it changed during the time we released the lock
@@ -903,8 +907,8 @@ CMyHttpModule::OnBeginRequest(
903907rsc->m_pRequestRec = r;
904908rsc->m_pHttpContext = pHttpContext;
905909rsc->m_pProvider = pProvider;
906- rsc->head =head ;
907- head =NULL ;// This is to indicate to the cleanup process to use rsc->head instead ofhead now
910+ rsc->requestBodyBufferHead =requestBodyBufferHead ;
911+ requestBodyBufferHead =NULL ;// This is to indicate to the cleanup process to use rsc->requestBodyBufferHead instead ofrequestBodyBufferHead now
908912
909913pHttpContext->GetModuleContextContainer ()->SetModuleContext (rsc, g_pModuleContext);
910914
@@ -1150,8 +1154,9 @@ CMyHttpModule::OnBeginRequest(
11501154Finished:
11511155LeaveCriticalSection (&m_csLock);
11521156
1157+ FinishedWithoutLock:
11531158// Free the preallocated body in case there was a failure and it wasn't consumed already
1154- preAllocBodyChunk* chunkToFree =head ?head : rsc->head ;
1159+ preAllocBodyChunk* chunkToFree =requestBodyBufferHead ?requestBodyBufferHead : rsc->requestBodyBufferHead ;
11551160while (chunkToFree !=NULL )
11561161 {
11571162 preAllocBodyChunk* next = chunkToFree->next ;
@@ -1170,22 +1175,22 @@ apr_status_t ReadBodyCallback(request_rec *r, char *buf, unsigned int length, un
11701175{
11711176 REQUEST_STORED_CONTEXT *rsc =RetrieveIISContext (r);
11721177
1173- if (rsc->head ==NULL )
1178+ if (rsc->requestBodyBufferHead ==NULL )
11741179 {
11751180 *is_eos =1 ;
11761181return APR_SUCCESS;
11771182 }
11781183
1179- *readcnt = length < rsc->head ->length ? length : rsc->head ->length ;
1180- void * src = (char *)rsc->head ->data ;
1184+ *readcnt = length <( unsigned int ) rsc->requestBodyBufferHead ->length ? length :( unsigned int ) rsc->requestBodyBufferHead ->length ;
1185+ void * src = (char *)rsc->requestBodyBufferHead ->data ;
11811186memcpy_s (buf, length, src, *readcnt);
11821187
11831188// Remove the front and proceed to next chunk in the linked list
1184- preAllocBodyChunk* chunkToFree = rsc->head ;
1185- rsc->head = rsc->head ->next ;
1189+ preAllocBodyChunk* chunkToFree = rsc->requestBodyBufferHead ;
1190+ rsc->requestBodyBufferHead = rsc->requestBodyBufferHead ->next ;
11861191free (chunkToFree);
11871192
1188- if (rsc->head ==NULL )
1193+ if (rsc->requestBodyBufferHead ==NULL )
11891194 {
11901195 *is_eos =1 ;
11911196 }