Skip to content

Setting OwinRequest.Host doesn't work as expected #571

Description

@marc-hall-oak

Hi

I am running an OWIN server (.net framework) behind a proxy. The OWIN app has the following middleware:

public override Task Invoke(IOwinContext context)
{
    var forwardedProto = context.Request.Headers.Get("X-Forwarded-Proto");
    if (forwardedProto != null)
    {
        context.Request.Scheme = forwardedProto;
    }

    var forwardedHost = context.Request.Headers.Get("X-Forwarded-Host");
    if (forwardedHost != null)
    {
        //context.Request.Headers.Set("Host", forwardedHost);
        context.Request.Host = new HostString(forwardedHost);
    }

    return Next.Invoke(context);
}

x-forwarded-* headers are set and this code executes. context.Request.Scheme is updated as expected. Setting context.Request.Host adds the Host header but context.Request.Host returns the unaltered host value (which would be localhost:xxxx.) I tried setting the Host header directly (commented out here) and it has the same effect. I've looked at the implementation of OwinRequest and it looks like it should just work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions