mirror of
https://github.com/Kong/insomnia.git
synced 2026-10-25 16:19:20 -04:00
Fix race condition on setting request body and headers
This commit is contained in:
1 parent
a4f56ffe7d
commit
f836913e28
1 file changed
+29
-29
@@ -80,37 +80,37 @@ class BodyEditor extends React.PureComponent<Props> {
|
||||
const { onChange, onChangeHeaders, request } = this.props;
|
||||
const headers = clone(request.headers);
|
||||
|
||||
let contentTypeHeader = getContentTypeHeader(headers);
|
||||
|
||||
if (!contentTypeHeader) {
|
||||
contentTypeHeader = { name: 'Content-Type', value: CONTENT_TYPE_FILE };
|
||||
headers.push(contentTypeHeader);
|
||||
}
|
||||
|
||||
// Update Content-Type header if the user wants
|
||||
const contentType = contentTypeHeader.value;
|
||||
const newContentType = mimes.lookup(path) || CONTENT_TYPE_FILE;
|
||||
if (contentType !== newContentType) {
|
||||
contentTypeHeader.value = newContentType;
|
||||
showModal(AskModal, {
|
||||
title: 'Change Content-Type',
|
||||
message: (
|
||||
<p>
|
||||
Do you want set the <span className="monospace">Content-Type</span> header to{' '}
|
||||
<span className="monospace">{newContentType}</span>?
|
||||
</p>
|
||||
),
|
||||
onDone: saidYes => {
|
||||
if (saidYes) {
|
||||
onChangeHeaders(request, headers);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const newBody = newBodyFile(path);
|
||||
|
||||
onChange(request, newBody);
|
||||
onChange(request, newBody).then(request => {
|
||||
let contentTypeHeader = getContentTypeHeader(headers);
|
||||
|
||||
if (!contentTypeHeader) {
|
||||
contentTypeHeader = { name: 'Content-Type', value: CONTENT_TYPE_FILE };
|
||||
headers.push(contentTypeHeader);
|
||||
}
|
||||
|
||||
// Update Content-Type header if the user wants
|
||||
const contentType = contentTypeHeader.value;
|
||||
const newContentType = mimes.lookup(path) || CONTENT_TYPE_FILE;
|
||||
if (contentType !== newContentType && path) {
|
||||
contentTypeHeader.value = newContentType;
|
||||
showModal(AskModal, {
|
||||
title: 'Change Content-Type',
|
||||
message: (
|
||||
<p>
|
||||
Do you want set the <span className="monospace">Content-Type</span> header to{' '}
|
||||
<span className="monospace">{newContentType}</span>?
|
||||
</p>
|
||||
),
|
||||
onDone: saidYes => {
|
||||
if (saidYes) {
|
||||
onChangeHeaders(request, headers);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
Reference in new issue
Block a user