-
Notifications
You must be signed in to change notification settings - Fork 0
contentHeader
The contentHeader utility provides functions for parsing and formatting content headers, such as Content-Type and Content-Disposition, within Salesforce Commerce Cloud (SFCC). This utility is essential for services that need to handle MIME types and content disposition parameters in HTTP headers.
Description: Parses a content header string into an object with a type and associated parameters.
-
Parameters:
-
header(string): The content header string to parse. -
headerType('type' | 'disposition', optional): The type of content header being parsed. Defaults to'type'.
-
-
Returns:
-
ContentHeader: The parsed content header information.
-
Usage Example:
var contentHeader = require('*/cartridge/scripts/util/contentHeader');
var header = 'multipart/form-data; boundary=--Boundary';
var parsedHeader = contentHeader.parse(header);
console.log(parsedHeader.type); // 'multipart/form-data'
console.log(parsedHeader.params.boundary); // '--Boundary'Description: Creates a content header string from a ContentHeader object.
-
Parameters:
-
contentHeader(ContentHeader): The content header information.
-
-
Returns:
-
string: The formatted content header string.
-
Usage Example:
var contentHeader = require('*/cartridge/scripts/util/contentHeader');
var headerObject = {
type: 'multipart/form-data',
params: {
boundary: '--Boundary'
}
};
var formattedHeader = contentHeader.format(headerObject);
console.log(formattedHeader); // 'multipart/form-data; boundary=--Boundary'Represents content type information.
-
Type:
Object-
type(string): The MIME/Disposition type. -
params(Object.<string,string>): The parameters associated with the MIME/Disposition type.
-
Usage Example:
var contentHeader = {
type: 'multipart/form-data',
params: {
boundary: '--Boundary'
}
};Description: Regular expression for validating MIME types.
-
Pattern:
/^[!#$%&'*+.^\w|~-]+\/[!#$%&'*+.^\w|~-]+$/
Description: Regular expression for validating disposition types.
-
Pattern:
/^[!#$%&'*+.^\w|~-]+$/
Description: Regular expression for validating and parsing parameters in the content header.
-
Pattern:
/ *([!#$%&'*+.^\w|~-]+)=("(?:[\x0b\x20\x21\x23-\x5b\x5d-\x7e\x80-\xff]|\[\x0b\x20-\xff])"|[!#$%&'+.^\w|~-]+) */