(Salesforce Apex 2024 Release) InvalidHeaderException in Apex REST API

 



The reason you are encountering the error InvalidHeaderException is due to a recently implemented restriction that states that REST response headers defined in Apex via the RestResponse must match API versions. RFC 7230 is used to validate the header names in the addHeader(name, value) method.

Following the upgrade, many more restrictions have been implemented; you can verify them by visiting the RFC 7230 validation page. Invalid characters, including /(slash), are no longer accepted.

Below is a summary of the information found on the validation page of RFC 7230:

  1. Header Field Syntax: Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field value, and optional trailing whitespace.
  2. Field Extensibility: Header fields are fully extensible, allowing the introduction of new field names, each defining new semantics. Unrecognized header fields should be forwarded, except when explicitly blocked by the Connection header field.
  3. Field Order: The order of header fields with differing names is not significant. It's recommended to send header fields with control data first for early message processing. Multiple header fields with the same name are allowed, but their order matters when interpreting the combined field value.
  4. Whitespace: Whitespace rules include OWS (optional whitespace), RWS (required whitespace), and BWS ("bad" whitespace). Implementations should adhere to proper whitespace rules.
  5. Field Parsing: Field values are not parsed until a later stage of message interpretation, and no whitespace is allowed between the field-name and colon. Obs-fold (line folding) should be handled correctly.
  6. Field Limits: There is no predefined limit on the length of each header field or the header section as a whole. However, servers should reject overly large header fields, and clients may discard or truncate excessively large header fields.
  7. Field Value Components: Header field values are often defined using common syntax components, such as tokens, quoted-strings, and comments. The backslash ("") can be used for quoting within these constructs.

These restrictions and guidelines ensure proper handling of header fields in HTTP, including RESTful resources, and help maintain the integrity and consistency of HTTP messages.

Comments

Popular posts from this blog

Understanding the Salesforce Approval Process: A Step-by-Step Guide

How to Give Permissions to Automated Process Users or System Context Users

Salesforce Custom Settings: Optimizing Your CRM for Maximum Efficiency