Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

HTTP helpers in util.http

Focus mode
HTTP helpers in util.http - AWS AppSync GraphQL

The util.http utility provides helper methods that you can use to manage HTTP request parameters and to add response headers.

util.http utils list

util.http.copyHeaders(headers)

Copies the headers from the map, excluding the following restricted HTTP headers:

  • transfer-encoding

  • connection

  • host

  • expect

  • keep-alive

  • upgrade

  • proxy-authenticate

  • proxy-authorization

  • te

  • content-length

util.http.addResponseHeader(String, Object)

Adds a single custom header with the name (String) and value (Object) of the response. The following limitations apply:

  • In addition to the list of restricted headers for copyHeaders(headers), header names cannot match any of the following:

    • 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

  • Header names can't start with the restricted prefixes x-amzn- or x-amz-.

  • The size of custom response headers can't exceed 4 KB. This includes header names and values.

  • You should define each response header once per GraphQL operation. However, if you define a custom header with the same name multiple times, the most recent definition appears in the response. All headers count towards the header size limit regardless of naming.

  • Headers with an empty or restricted name (String) or a null value (Object) will be ignored and yield a ResponseHeaderError error that is added to the operation's errors output.

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

Adds multiple response headers to the response from the specified map of names (String) and values (Object). The same limitations listed for the addResponseHeader(String, Object) method also apply to this method.

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

On this page

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.