mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 14:49:53 +00:00
34 lines
793 B
JavaScript
34 lines
793 B
JavaScript
import * as types from '../constants/actionTypes'
|
|
|
|
const defaultResponse = {
|
|
id: null,
|
|
requestId: null,
|
|
created: 0,
|
|
modified: 0,
|
|
body: '',
|
|
statusCode: -1,
|
|
contentType: 'text/plain',
|
|
headers: [{
|
|
name: 'Content-Type',
|
|
value: 'application/json'
|
|
}]
|
|
};
|
|
|
|
function buildResponse (response) {
|
|
// Build the required fields
|
|
const id = response.id || `rsp_${Date.now()}`;
|
|
const created = response.created || Date.now();
|
|
const modified = response.modified || Date.now();
|
|
|
|
// Create the response
|
|
return Object.assign({}, defaultResponse, response, {
|
|
id, created, modified
|
|
});
|
|
}
|
|
|
|
export function setResponse (requestId, response) {
|
|
response.requestId = requestId;
|
|
response = buildResponse(response);
|
|
return {type: types.RESPONSE_SET, requestId, response}
|
|
}
|