-
Notifications
You must be signed in to change notification settings - Fork 0
headers
Dmytro Katashev edited this page Aug 12, 2024
·
1 revision
The headers utility provides functions for parsing and formatting raw HTTP headers in Salesforce Commerce Cloud (SFCC). It is useful for converting between a raw headers string and a key-value object representation, making it easier to manage and manipulate HTTP headers in web services.
Description: Parses a raw headers string into an object where each key is a header name and each value is the corresponding header value.
-
Parameters:
-
rawHeaders(string): The raw headers string to parse.
-
-
Returns:
-
Object.<string, string>: An object containing the parsed headers as key-value pairs.
-
Usage Example:
var headers = require('*/cartridge/scripts/util/headers');
var rawHeaders = 'Content-Type: application/json\r\nAuthorization: Bearer token';
var parsedHeaders = headers.parse(rawHeaders);
// parsedHeaders will be:
// {
// 'content-type': 'application/json',
// 'authorization': 'Bearer token'
// }Description: Converts a headers object into a raw headers string.
-
Parameters:
-
headers(Object.<string, string>): An object containing headers as key-value pairs.
-
-
Returns:
-
string: The formatted raw headers string.
-
Usage Example:
var headers = require('*/cartridge/scripts/util/headers');
var headersObject = {
'content-type': 'application/json',
'authorization': 'Bearer token'
};
var rawHeaders = headers.format(headersObject);
// rawHeaders will be:
// 'content-type: application/json\r\nauthorization: Bearer token'