Google Cloud Function自定义请求头无法接收问题求助
Google Cloud Function部署新版本后无法接收自定义请求头
今日上午部署Google Cloud Function的更新版本后,自定义请求头无法被函数接收。
关键信息:
- 未修改任何与请求头/响应头相关的代码
- 该问题在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已有2年多,从未遇到过此问题,推测可能是GCP近期变更导致,恳请各位提供帮助。
内容的提问来源于stack exchange,提问作者Quantitative
相关产品推荐
相关产品推荐

