0

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 '405 Method not allowed'.

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;
            }
        }
    }
MichaelDotKnox
  • 1,312
  • 1
  • 14
  • 17
zhenm
  • 41
  • 4
  • Literally the two responses have no difference. – Lex Li Jul 24 '18 at 12:20
  • @LexLi: But what I got is: for IIS host, the content in the response has no value. But for Owin, the content has value. This is very strange as for HEAD request, I think the content should has no value. Do you know the internal diff between IIS and OWin on 'Exception handling' related with this HEAD request? Thanks. – zhenm Jul 25 '18 at 02:57
  • The HTTP protocol itself only says "the server MUST NOT return a message-body in the response." https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html But the ambiguity is whether when an error happens (like your case) a message body can be returned. That's why I commented that literally the two responses (405) have no difference. Most web browsers/clients won't check the body in such error responses. If you want to dig deeper, Microsoft OWIN is open source. However, IIS is not. – Lex Li Jul 25 '18 at 03:04

0 Answers0