Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP HEAD Method via Proxy zeroing the Content-Length

I have created a file server using a HTTP Trigger Function that accesses Blob Storage. This works fine and the files are served using a HTTP GET.

However, I want to implement a HTTP HEAD method response in order to ascertain file the size. This also works fine when called directly but not when called via a proxy, in that case the Content-Length is returned as 0

I have created a simplified example to demonstrate the issue

Function Code

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("HeadTest fired");

    HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK);

    HttpContent httpContent = new ByteArrayContent(new Byte[0]);

    httpContent.Headers.ContentLength = 1234;

    httpResponseMessage.Content = httpContent;

    httpResponseMessage.Headers.Add("X-Header-Test", "true");

    return httpResponseMessage;
}

Proxy Definition

{
    "$schema": "http://json.schemastore.org/proxies",
    "proxies": {
        "HeadTestProxy": {
            "matchCondition": {
                "route": "/proxy/HeadTest",
                "methods": [
                    "HEAD"
                ]
            },
            "backendUri": "https://localhost/api/HeadTest"
        }
    }
}

Function Response

cache-control →no-cache
content-length →1234
date →Thu, 15 Mar 2018 09:36:10 GMT
expires →-1
pragma →no-cache
server →Microsoft-IIS/10.0
x-header-test →true
x-powered-by →ASP.NET 

Proxy Response

cache-control →no-cache
content-length →0
date →Thu, 15 Mar 2018 09:36:06 GMT
expires →-1
pragma →no-cache
server →Microsoft-IIS/10.0
x-header-test →true
x-powered-by →ASP.NET

Further Notes

I also tried placing the length in a custom header then copying that into the original Content-Length header in the proxy's response override, but that also resulted in 0

like image 755
user3876103 Avatar asked May 29 '26 21:05

user3876103


1 Answers

content-length is a content header so can only be added to the content header collection

I have created a demo to test, I also get the same issue as you. The Content-Length can not be passed to proxy response header. I suppose this is a bug. And there are few articles about the proxies in Azure function. Especially for http head. I suggest you could post this issue to github.

like image 111
Janley Zhang Avatar answered Jun 02 '26 21:06

Janley Zhang



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!