util.http 中的 HTTP 帮助程序 - Amazon AppSync GraphQL
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

util.http 中的 HTTP 帮助程序

util.http 实用程序提供一些帮助程序方法,可用于管理 HTTP 请求参数和添加响应标头。

util.http 实用程序列表

util.http.copyHeaders(headers)

从映射中复制标头,不包括以下受限制的 HTTP 标头:

  • transfer-encoding

  • connection

  • host

  • expect

  • keep-alive

  • upgrade

  • proxy-authenticate

  • proxy-authorization

  • te

  • content-length

util.http.addResponseHeader(String, Object)

添加单个自定义标头,其中包含响应的名称 (String) 和值 (Object)。适用以下限制:

  • 除了 copyHeaders(headers) 的受限制标头列表外,标头名称不能与以下列出的任何名称相同:

    • Access-Control-Allow-Credentials

    • Access-Control-Allow-Origin

    • Access-Control-Expose-Headers

    • Access-Control-Max-Age

    • Access-Control-Allow-Methods

    • Access-Control-Allow-Headers

    • Vary

    • Content-Type

  • 标头名称不能以受限制的前缀 x-amzn-x-amz- 开头。

  • 自定义响应标头大小不能超过 4 KB。这包括标头名称和值。

  • 对于每个 GraphQL 操作,您应该定义一次每个响应标头。不过,如果您多次定义具有相同名称的自定义标头,将在响应中显示最新的定义。无论命名如何,所有标头都会计入标头大小限制。

  • 系统会忽略名称为空或使用受限制名称 (String) 或 null 值 (Object) 的标头,并生成一个 ResponseHeaderError 错误,该错误会添加到操作的 errors 输出中。

export function request(ctx) { util.http.addResponseHeader('itemsCount', 7) util.http.addResponseHeader('render', ctx.args.render) return {} }
util.http.addResponseHeaders(Map)

将多个响应标头添加到来自指定的名称 (String) 和值 (Object) 映射的响应中。为 addResponseHeader(String, Object) 方法列出的相同限制也适用于该方法。

export function request(ctx) { const headers = { headerInt: 12, headerString: 'stringValue', headerObject: { field1: 7, field2: 'string' } } util.http.addResponseHeaders(headers) return {} }