Google Cloud 功能 - 未收到标头(在端点中)

问题描述 投票:0回答:1

今天早上我部署了自定义请求标头的更新版本后,自定义请求标头没有“到达”/被我的谷歌云功能接收。

备注:

  • 我没有更改任何与请求标头/响应标头相关的代码
  • 此错误可在 python 3.9-3.12 中重现
  • 过去 7 天内我没有更改任何 GCP 网络设置
  • 不使用VPN
  • 从浏览器发送请求和从 python 脚本发送请求时都不会收到标头

为了确定是 Google Cloud Functions 造成的,我设置了一个新函数来测试这一点:

import functions_framework
from flask import make_response

@functions_framework.http
def hello_http(request):
    print(request.headers)


    response = make_response('Hello World')
    response.headers['Access-Control-Allow-Origin']  = '*'
    response.headers['Access-Control-Allow-Headers'] = '*'
    return response

这是我用来测试此问题/发送请求的Python脚本:

import requests 

resp = requests.get("<google_cloud_function_url>/test-headers-1", headers = {
    "custom_header_example" : "custom header value",
})

print(resp)
print(resp.headers)

最后,这些是云函数收到的标头(找不到custom_header_example)

如果有人知道导致此问题的原因,我将非常感谢您的帮助,我已经使用 GCP Cloud Functions 两年多了,从未出现过此问题,似乎这可能是 GCP 最近更改的内容

python rest flask google-cloud-platform google-cloud-functions
1个回答
0
投票

找到解决方案:标题不能包含下划线“_”

所以我正在测试并注意到谷歌云功能只接收带有下划线的标头。

因此“custom_header_example”不会出现,但如果我将标头作为“custom-header-example”发送,云函数现在突然收到标头。

如果您认识在 GCP 工作的人,请让他们知道此错误

© www.soinside.com 2019 - 2024. All rights reserved.