Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpAddFragmentToCache and OS error 50

I am trying to create an embedded web server in an application. For this I use the http.sys HTTP server component from Windows. Everything works well when I do not try to use HttpAddFragmentToCache.

What I did so far (removed any error checking but without the fragment caching it works OK):

HttpInitialize( HTTPAPI_VERSION_1, HTTP_INITIALIZE_SERVER );
HttpCreateHttpHandle( FQueueHandle )
HttpAddUrl( FQueueHandle, PWideChar( W ) );
...
HttpRemoveUrl( FQueueHandle, PWideChar( W ) );
HttpTerminate( HTTP_INITIALIZE_SERVER );

Now when a request comes by in a helper thread:

HttpReceiveHttpRequest( FQueueHandle, FRequestID, 0, FRequest^, FRequestBufferSize, @Bytes );
// if needed:
HttpReceiveRequestEntityBody( FQueueHandle, FRequestId, 0, @FRequestContent[ 0 ], Longword( N ), @BytesRead )
// Fill in chunks...
// Respond
HttpSendHttpResponse( FQueueHandle, FRequestId, 0, FResponse, nil, N );

What I am trying to change is to add some static documents to the fragment cache (at the ellipsis above):

Chunk.DataChunkType           := hctFromMemory;
Chunk.FromMemory.pBuffer      := @Content[ 0 ];
Chunk.FromMemory.BufferLength := Length( Content );
Policy.Policy                 := hcpUserInvalidates;
Policy.SecondsToLive          := 0;
Result := HttpAddFragmentToCache( FQueueHandle, PWideChar( W ), Chunk, Policy );

Note: all overlapped parameters are made optionally nil / NULL in my code that explains why you might miss that parameter.

This will yield a result of 50 (The request is not supported). I tried to add fragments from memory and from file handle, All different policies. Checked if the values passed are correct in dis-assembly, Checked if the string passed to HttpAddFragmentToCache is indeed a valid subURL from the one passed to HttpAddUrl (if not you get an OS error 2 so that's also not it).

My question is: what could this be? I try to use this API call in the most straightforward manner I can see (it is where the API is designed for) but apparently I am doing something wrong..

Update:

It looks like that fragmens added with the function HttpAddFragmentToCache have a maximum size:

When the code above is replaced by:

Chunk.FromMemory.BufferLength := Min( 256*1024, Length( Content ) );

No errors occur; when replaced by

Chunk.FromMemory.BufferLength := Min( 256*1024 + 1, Length( Content ) );

It fails. Apparently there is a size limit and... I found it:

http://support.microsoft.com/kb/820129

UriMaxUriBytes 262144 (bytes) 4096(4k) – 16777216(16MB) bytes Any response that is greater than this value is not cached in the kernel response cache.

This leaves two options: 1. keep multiple fragments for larger files. or 2. increase this limit in the registry.

like image 693
Ritsaert Hornstra Avatar asked Feb 24 '26 10:02

Ritsaert Hornstra


1 Answers

Solved the problem: There is a limit in the size the fragment cache can cache per fragment; defaults to 256KB. See the update of the question for details.

like image 125
Ritsaert Hornstra Avatar answered Feb 26 '26 01:02

Ritsaert Hornstra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!