简体   繁体   English

Google Cloud Functions 标头响应

[英]Google Cloud Functions Headers response

I am executing a GCF triggered by an Http Request, and I only need to receive a custom message, however, I receive all of this headers:我正在执行由 Http 请求触发的 GCF,我只需要接收一条自定义消息,但是,我收到了所有这些标头:

HTTP/1.1 200 OK
Server: nginx
Content-Type: application/json; charset=utf-8
x-powered-by: Express
cache-control: private
Strict-Transport-Security: max-age=31556926; includeSubDomains; preload
etag: W/"19-7046833f"
function-execution-id: nx88bs3fra23
x-cloud-trace-context: 302401ba6a3c3d461c32dc7e4825c54d;o=1, 302401ba6a3c3d461c32dc7e4825c54d
Content-Length: 25
Accept-Ranges: bytes
Date: Wed, 05 Jul 2017 01:48:23 GMT
Via: 1.1 varnish
Connection: keep-alive
X-Served-By: cache-lax8651-LAX
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1499219281.929840,VS0,VE22189

I don't need to use any of the headers because I am doing a request from a 3G module, not a web browser.我不需要使用任何标头,因为我正在从 3G 模块而不是 Web 浏览器发出请求。 The code used to receive this is the following:用于接收此代码的代码如下:

'use strict';
exports.myfunction = functions.https.onRequest((req, res) => {
  admin.database().ref('/root').once('child_changed', (snapshot) =>{
    res.send(snapshot.val());
  });
});

Is there any way to remove these headers from the response?有没有办法从响应中删除这些标头? I have been reading the response documentation , and I found the res.set(field [, value]) method.我一直在阅读响应文档,并且找到了 res.set(field [, value]) 方法。

Do you know if it is possible to remove the automatic headers sent by the server?您知道是否可以删除服务器发送的自动标头吗?

I just tried a Hello World Cloud Functions example and based on that, the following response headers are added by Google Cloud Functions:我刚刚尝试了一个Hello World Cloud Functions 示例,基于此,Google Cloud Functions 添加了以下响应标头:

Content-Length: 12
Date: Sat, 08 Jul 2017 12:12:12 GMT
ETag: W/"c-1a2b3c4d"
Server: Foo
content-type: text/html; charset=utf-8
function-execution-id: SOME_EXECUTION_ID
x-cloud-trace-context: SOME_CONTEXT_1;o=1
x-cloud-trace-context: SOME_CONTEXT_2
x-powered-by: Express

There is no way to remove any of these headers from the Google Cloud Functions side.无法从 Google Cloud Functions 端删除任何这些标头。 Some of the headers in your response seem to be coming from a Varnish Cache, so unless you plan to remove Varnish caching I guess you will not be able to remove those too.您响应中的某些标头似乎来自 Varnish 缓存,因此除非您打算删除 Varnish 缓存,否则我想您也无法删除它们。

The overhead of the response headers is quite small (<1kB in your example) and I would rather not worry about them (even over 3G).响应标头的开销非常小(在您的示例中为 <1kB),我宁愿不担心它们(甚至超过 3G)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM