aliostad / CacheCow

An implementation of HTTP Caching in .NET Core and 4.5.2+ for both the client and the server
MIT License
849 stars 171 forks source link

CacheCow doesn't like multiple DelegatingHandlers #152

Closed ehsemsar closed 6 years ago

ehsemsar commented 8 years ago

Hi Ali,

I have a MessageHandlers called MetadataHandler in my web api which is shaping the data just before returning back to the client. When I add the CachCow I get this error "This operation is not supported for a relative URI."

Here is the MetaDataHandler:

public class MetadataHandler : DelegatingHandler { protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { return base.SendAsync(request, cancellationToken).ContinueWith( task => { //The error happens here on this line //task: Id = 68, Status = Faulted, Method = "{null}", Result = "{Not yet computed}" if (ResponseIsValid(task.Result)) { AddMetaDataToResponse(task.Result, request); }

                return task.Result;
            });
    }

... }

And this is how I registered CachCow in WebApiConfig:

config.MessageHandlers.Add(new MetadataHandler()); config.MessageHandlers.Add(new CachingHandler(config));

I have a feeling that the thread is getting blocked somewhere according to this: http://stackoverflow.com/questions/24326043/deadlock-reading-async-response-content-from-async-delegatinghandler-in-webapi

I appreciate if you can help solving this, thanks.

aliostad commented 6 years ago

I am sorry, this is two year old. If still a problem let me know.