aspnet / AspNetWebStack

ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x (not ASP.NET Core)
Other
858 stars 354 forks source link

Owin: The content is the response has value when calling HTTP HEAD request when the API is not support 'HEAD' #182

Closed Tratcher closed 6 years ago

Tratcher commented 6 years ago

From @zhenm on July 26, 2018 2:4

I have a 2 services(WebApi), one is azure cloud service that using IIS host and another one is azure service fabric stateless service that using Owin host. There is a handler that like below, and both services register this handler to handle the context(config.MessageHandlers.Add(new ContextHandler())).

Currently, what I met is: If I call cloud service api(just ping) using HTTP HEAD request, this will return '405 method not allowed'. But if I call fabric service, I will get 'Could not get any response' with 'there was an error connecting to...'.

When debug the code. For the cloud service using IIS, in the below code, the response.Content has no value. But for the fabric service using Owin, the response.Content has value like 'The resource is not support http head request'.

My question is, what the difference between them? Why the Owin will return a response with content back as the request is HEAD request?

Thanks.

public class ContextHandler : DelegatingHandler
    {
        protected override async Task<HttpResponseMessage> SendAsync(
            HttpRequestMessage request, CancellationToken cancellationToken)
        {
            // initialize context
            using (new ApiRequestContextWrapper(request))
            {
                var context = ApiRequestContext.Current;
                context.Log.Trace(
                    $"API Call {request.Method.Method} 
               {request.RequestUri.GetLeftPart(UriPartial.Path)}");

                var response = await base.SendAsync(request, 
                cancellationToken).ConfigureAwait(false);                

                return response;
            }
        }
    }

image

Copied from original issue: aspnet/AspNetKatana#218

dougbu commented 6 years ago

@zhenm thank-you for filing this issue.

Could you please clarify which config object you're adding the handler to in the two cases? Ideally, please provide us with a minimal repro project that illustrates the problem, preferably hosted in a GitHub repo.

mkArtakMSFT commented 6 years ago

Hi. We're closing this issue as there's been no response and we have been unable to reproduce it. If you have more details and are encountering this issue please add a new reply and re-open the issue.