Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'content-type' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
async _waitForLoadEventWhenXml(page, response) {
// Response can sometimes be null.
if (!response) return;
const cTypeHeader = response.headers()['content-type'];
try {
const { type } = contentType.parse(cTypeHeader);
if (!/^(text|application)\/xml$|\+xml$/.test(type)) return;
} catch (err) {
// Invalid type is not XML.
return;
}
try {
const timeout = this.input.pageLoadTimeoutSecs * 1000;
await page.waitFor(() => document.readyState === 'complete', { timeout });
} catch (err) {
if (err.stack.startsWith('TimeoutError')) {
throw new Error('Parsing of XML in the page timed out. If you\'re expecting a large XML file, '
+ ' such as a site map, try increasing the Page load timeout input setting.');
} else {
throw err;
}
return function* charset(next) {
yield* next;
// manually turn off charset by `this.charset = false`
if (this.charset === false) return;
if (!this.body) return;
if (!text(this.type)) return;
var contentType = this.response.get('Content-Type');
// first this.charset
// then global.charset
// at last check charset in `content-type`
var charset = (this.charset
|| options.charset
|| typer.parse(contentType).parameters.charset
|| '').toLowerCase();
if (!charset
|| charset === 'utf-8'
|| charset === 'utf8') return;
// set type with charset
var type = this.type;
this.type = type + '; charset=' + charset;
// buffer / string body
if (Buffer.isBuffer(this.body) || typeof this.body === 'string') {
return this.body = iconv.encode(this.body, charset);
}
// stream body
if (typeof this.body.pipe === 'function') {
exports.setCharset = function setCharset(type, charset) {
if (!type || !charset) {
return type;
}
// parse type
var parsed = contentType.parse(type);
// set charset
parsed.parameters.charset = charset;
// format type
return contentType.format(parsed);
};
exports.setCharset = function setCharset(type, charset) {
if (!type || !charset) {
return type;
}
// parse type
var parsed = contentType.parse(type);
// set charset
parsed.parameters.charset = charset;
// format type
return contentType.format(parsed);
};
exports.setCharset = function setCharset(type, charset) {
if (!type || !charset) return type;
var parsed = contentType.parse(type);
var exists = parsed.parameters.charset;
// keep existing charset
if (exists) {
return type;
}
// set charset
parsed.parameters.charset = charset;
return contentType.format(parsed);
};
exports.setCharset = function setCharset(type, charset) {
if (!type || !charset) {
return type;
}
// parse type
var parsed = contentType.parse(type);
// set charset
parsed.parameters.charset = charset;
// format type
return contentType.format(parsed);
};
exports.setCharset = function setCharset(type, charset) {
if (!type || !charset) return type;
var parsed = contentType.parse(type);
var exists = parsed.parameters.charset;
// keep existing charset
if (exists) {
return type;
}
// set charset
parsed.parameters.charset = charset;
return contentType.format(parsed);
};
Compiler.prototype._handleCharset = function () {
const ct = contentType.parse(this._table.headers['Content-Type'] || 'text/plain');
const charset = sharedFuncs.formatCharset(this._table.charset || ct.parameters.charset || 'utf-8');
// clean up content-type charset independently using fallback if missing
if (ct.parameters.charset) {
ct.parameters.charset = sharedFuncs.formatCharset(ct.parameters.charset);
}
this._table.charset = charset;
this._table.headers['Content-Type'] = contentType.format(ct);
};
exports.setCharset = function setCharset(type, charset) {
if (!type || !charset) {
return type;
}
// parse type
var parsed = contentType.parse(type);
// set charset
parsed.parameters.charset = charset;
// format type
return contentType.format(parsed);
};
exports.setCharset = function setCharset(type, charset) {
if (!type || !charset) {
return type;
}
// parse type
var parsed = contentType.parse(type);
// set charset
parsed.parameters.charset = charset;
// format type
return contentType.format(parsed);
};