Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _generateCode(request, target, client) {
// Some clients need a content-length for the request to succeed
const addContentLength = (TO_ADD_CONTENT_LENGTH[target.key] || []).find(c => c === client.key);
const { environmentId } = this.props;
const har = await exportHarRequest(request._id, environmentId, addContentLength);
const snippet = new HTTPSnippet(har);
const cmd = snippet.convert(target.key, client.key);
this.setState({ request, cmd, client, target });
// Save client/target for next time
window.localStorage.setItem('insomnia::generateCode::client', JSON.stringify(client));
window.localStorage.setItem('insomnia::generateCode::target', JSON.stringify(target));
}
async _handleCopyAsCurl(request) {
const { activeEnvironment } = this.props;
const environmentId = activeEnvironment ? activeEnvironment._id : 'n/a';
const har = await exportHarRequest(request._id, environmentId);
const snippet = new HTTPSnippet(har);
const cmd = snippet.convert('shell', 'curl');
clipboard.writeText(cmd);
}
private refresh(record: DtoRecord, language: CodeSnippetLang, type: string) {
const har = new HAR(record);
let code = '';
try {
const snippet = new HTTPSnippet(har);
code = snippet.convert(language, type);
} catch (ex) {
code = JSON.stringify(ex);
}
this.setState({ ...this.state, language, type, code });
}