javascript - Google Cloud Functions header 响应

标签 javascript express firebase google-cloud-functions

我正在执行由 Http 请求触发的 GCF,我只需要接收自定义消息,但是,我收到了所有这些 header :

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

我不需要使用任何 header ,因为我正在从 3G 模块而不是 Web 浏览器发出请求。用于接收此代码的代码如下:

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

有什么方法可以从响应中删除这些 header 吗? 我一直在阅读 response documentation ,然后我找到了 res.set(field [, value]) 方法。

您知道是否可以删除服务器发送的自动 header 吗?

最佳答案

我刚刚尝试了 Hello World Cloud Functions example并基于此,Google Cloud Functions 添加了以下响应 header :

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

无法从 Google Cloud Functions 端删除任何这些 header 。您响应中的某些 header 似乎来自 Varnish 缓存,因此除非您打算删除 Varnish 缓存,否则我想您也无法删除它们。

响应 header 的开销非常小(在您的示例中为 <1kB),我宁愿不用担心它们(甚至超过 3G)。

关于javascript - Google Cloud Functions header 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44936220/

相关文章:

node.js - Express 无法从后面读取未定义的属性 'name'

javascript - 原型(prototype)模式创建新属性

java - Firebase 分析 : maximum number of event names?

javascript - 使用 Firebase FCM 响应 native

node.js - 从架构生成静态 API 文档?

firebase - 无法部署 Firebase Cloud Functions [找不到模块 'protobufjs/minimal']

javascript - jquery 自动完成位置

javascript - 鼠标悬停时继续调用函数

javascript - Angular 2 : Emit events across multiple components, 不仅仅是直接父级

javascript - AngularJS - 如何在工厂中组合相同的并行 $http/$resource 请求