我使用访问 Blob 存储的 HTTP 触发器函数创建了一个文件服务器。这工作正常,文件使用 HTTP GET 提供。
但是,我想实现HTTP HEAD方法响应以确定文件的大小。这在直接调用时也可以正常工作,但在通过代理调用时则不工作,在这种情况下,内容长度返回为 0
我创建了一个简化的示例来演示该问题
函数代码
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;
}
代理定义
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"HeadTestProxy": {
"matchCondition": {
"route": "/proxy/HeadTest",
"methods": [
"HEAD"
]
},
"backendUri": "https://localhost/api/HeadTest"
}
}
}
函数响应
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
代理响应
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
进一步说明
我还尝试将长度放在自定义标头中,然后将其复制到代理响应覆盖中的原始 Content-Length 标头中,但这也导致 0
内容长度是一个内容标头,因此只能添加到内容标头集合中
我创建了一个演示来测试,我也遇到了与您相同的问题。内容长度不能传递到代理响应标头。我想这是一个错误。关于 Azure 函数中的代理的文章很少。特别是对于http头。我建议你可以把这个问题发布到github。