closes #36 raw body option

This commit is contained in:
Nicholas Palenchar
2019-08-25 17:10:17 -04:00
parent fddd41f6b4
commit bfffdbc4d8

View File

@@ -36,8 +36,10 @@
<option>application/json</option> <option>application/json</option>
<option>www-form/urlencoded</option> <option>www-form/urlencoded</option>
</select> </select>
<!-- <label for="rawinput">Raw input</label>--> <span>
<span><input v-model="rawInput" type="checkbox" id="rawinput">Raw Input</span> <input v-model="rawInput" style="cursor: pointer;" type="checkbox" id="rawInput">
<label for="rawInput" style="cursor: pointer;">Raw Input</label>
</span>
</li> </li>
</ul> </ul>
<div v-if="!rawInput"> <div v-if="!rawInput">
@@ -252,7 +254,6 @@
return validIP.test(this.url) || validHostname.test(this.url); return validIP.test(this.url) || validHostname.test(this.url);
}, },
rawRequestBody() { rawRequestBody() {
debugger;
const { const {
bodyParams bodyParams
} = this } = this
@@ -338,7 +339,6 @@
xhr.setRequestHeader('Authorization', 'Bearer ' + this.bearerToken); xhr.setRequestHeader('Authorization', 'Bearer ' + this.bearerToken);
} }
if (this.method === 'POST' || this.method === 'PUT') { if (this.method === 'POST' || this.method === 'PUT') {
debugger;
const requestBody = this.rawInput ? this.rawParams : this.rawRequestBody; const requestBody = this.rawInput ? this.rawParams : this.rawRequestBody;
xhr.setRequestHeader('Content-Length', requestBody.length) xhr.setRequestHeader('Content-Length', requestBody.length)
xhr.setRequestHeader('Content-Type', `${this.contentType}; charset=utf-8`) xhr.setRequestHeader('Content-Type', `${this.contentType}; charset=utf-8`)
@@ -382,8 +382,7 @@
}, },
formatRawParams(event) { formatRawParams(event) {
if ((event.which !== 13 && event.which !== 9)) { if ((event.which !== 13 && event.which !== 9)) {
console.log('not not returning'); return;
return
} }
const textBody = event.target.value; const textBody = event.target.value;
@@ -391,8 +390,17 @@
const textAfterCursor = textBody.substring(event.target.selectionEnd); const textAfterCursor = textBody.substring(event.target.selectionEnd);
if (event.which === 13) { if (event.which === 13) {
const lastLine = textBody.split('\n').slice(-1)[0]; event.preventDefault();
const oldSelectionStart = event.target.selectionStart;
const lastLine = textBeforeCursor.split('\n').slice(-1)[0];
const rightPadding = lastLine.match(/([\s\t]*).*/)[1] || ""; const rightPadding = lastLine.match(/([\s\t]*).*/)[1] || "";
event.target.value = textBeforeCursor + '\n' + rightPadding + textAfterCursor;
setTimeout(() => event.target.selectionStart = event.target.selectionEnd = oldSelectionStart + rightPadding.length + 1, 1);
return;
// const lastLine = textBeforeCursor.split('\n').slice(-1)[0];
// const rightPadding = lastLine.match(/([\s\t]*).*/)[1] || "";
event.target.value = textBeforeCursor + '\n' + rightPadding + textAfterCursor
setTimeout(() => event.target.value = textBeforeCursor + '\n' + rightPadding + textAfterCursor, 1); setTimeout(() => event.target.value = textBeforeCursor + '\n' + rightPadding + textAfterCursor, 1);
} }
else if (event.which === 9) { else if (event.which === 9) {