query, header enabled 적용
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package com.eactive.httpmockserver.api.controller;
|
package com.eactive.httpmockserver.api.controller;
|
||||||
|
|
||||||
import com.eactive.httpmockserver.api.dto.MockConditionDTO;
|
|
||||||
import com.eactive.httpmockserver.api.dto.MockRequest;
|
import com.eactive.httpmockserver.api.dto.MockRequest;
|
||||||
import com.eactive.httpmockserver.api.entity.MockCondition;
|
import com.eactive.httpmockserver.api.entity.MockCondition;
|
||||||
import com.eactive.httpmockserver.api.entity.MockResponse;
|
import com.eactive.httpmockserver.api.entity.MockResponse;
|
||||||
|
|||||||
@@ -2,9 +2,19 @@ package com.eactive.httpmockserver.client.dto;
|
|||||||
|
|
||||||
public class ApiHeaderDTO {
|
public class ApiHeaderDTO {
|
||||||
|
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.eactive.httpmockserver.client.service;
|
package com.eactive.httpmockserver.client.service;
|
||||||
|
|
||||||
|
import com.eactive.httpmockserver.client.dto.ApiHeaderDTO;
|
||||||
import com.eactive.httpmockserver.client.dto.ApiRequestDTO;
|
import com.eactive.httpmockserver.client.dto.ApiRequestDTO;
|
||||||
import com.eactive.httpmockserver.client.dto.ApiResponse;
|
import com.eactive.httpmockserver.client.dto.ApiResponse;
|
||||||
import com.eactive.httpmockserver.client.entity.Server;
|
import com.eactive.httpmockserver.client.entity.Server;
|
||||||
@@ -85,8 +86,10 @@ public class NettyApiClient {
|
|||||||
|
|
||||||
if (apiRequest.getHeaders().size() > 0) {
|
if (apiRequest.getHeaders().size() > 0) {
|
||||||
HttpHeaders customHeaders = new DefaultHttpHeaders();
|
HttpHeaders customHeaders = new DefaultHttpHeaders();
|
||||||
apiRequest.getHeaders().forEach((header) -> {
|
apiRequest.getHeaders().stream().filter(ApiHeaderDTO::isEnabled).forEach((header) -> {
|
||||||
customHeaders.set(header.getKey(), header.getValue());
|
if(StringUtils.isNotEmpty(header.getKey()) && StringUtils.isNotEmpty(header.getValue())){
|
||||||
|
customHeaders.set(header.getKey(), header.getValue());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
request.headers().add(customHeaders);
|
request.headers().add(customHeaders);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@
|
|||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th scope="col">#</th>
|
||||||
<th scope="col">이름</th>
|
<th scope="col">이름</th>
|
||||||
<th>값</th>
|
<th>값</th>
|
||||||
<th>
|
<th>
|
||||||
@@ -96,9 +97,10 @@
|
|||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th scope="col">#</th>
|
||||||
<th scope="col">이름</th>
|
<th scope="col">이름</th>
|
||||||
<th scope="col">값</th>
|
<th scope="col">값</th>
|
||||||
<th>
|
<th scope="col">
|
||||||
<button type="button" class="btn btn-secondary btn-sm btn_add_header">추가
|
<button type="button" class="btn btn-secondary btn-sm btn_add_header">추가
|
||||||
</button>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
@@ -159,6 +161,11 @@
|
|||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" name="enabled"/>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input class="form-control" type="text" name="key"/>
|
<input class="form-control" type="text" name="key"/>
|
||||||
</td>
|
</td>
|
||||||
@@ -223,8 +230,15 @@
|
|||||||
let template = $('#inputTemplate').children().find('tr').clone();
|
let template = $('#inputTemplate').children().find('tr').clone();
|
||||||
template.find('input[name="key"]').val(model.queryParams[i].key);
|
template.find('input[name="key"]').val(model.queryParams[i].key);
|
||||||
template.find('input[name="value"]').val(model.queryParams[i].value);
|
template.find('input[name="value"]').val(model.queryParams[i].value);
|
||||||
|
if(model.queryParams[i].enabled){
|
||||||
|
template.find('input[name="enabled"]').prop("checked",model.queryParams[i].enabled);
|
||||||
|
}
|
||||||
template.find('button').attr("data-id", i);
|
template.find('button').attr("data-id", i);
|
||||||
|
|
||||||
|
template.find('input[name="enabled"]').on('change', function () {
|
||||||
|
model.queryParams[i].enabled = $(this).prop('checked');
|
||||||
|
controller.buildPath(tabIdx);
|
||||||
|
});
|
||||||
template.find('input[name="key"]').on('focusout', function () {
|
template.find('input[name="key"]').on('focusout', function () {
|
||||||
model.queryParams[i].key = $(this).val();
|
model.queryParams[i].key = $(this).val();
|
||||||
controller.buildPath(tabIdx);
|
controller.buildPath(tabIdx);
|
||||||
@@ -245,12 +259,20 @@
|
|||||||
target.find('.request_headers').empty();
|
target.find('.request_headers').empty();
|
||||||
|
|
||||||
let model = apiRequests[tabIdx];
|
let model = apiRequests[tabIdx];
|
||||||
|
console.log(model);
|
||||||
for (let i = 0; i < model.headers.length; i++) {
|
for (let i = 0; i < model.headers.length; i++) {
|
||||||
let template = $('#inputTemplate').children().find('tr').clone();
|
let template = $('#inputTemplate').children().find('tr').clone();
|
||||||
|
console.log(model.headers[i]);
|
||||||
|
if(model.headers[i].enabled){
|
||||||
|
template.find('input[name="enabled"]').prop("checked",model.headers[i].enabled);
|
||||||
|
}
|
||||||
template.find('input[name="key"]').val(model.headers[i].key);
|
template.find('input[name="key"]').val(model.headers[i].key);
|
||||||
template.find('input[name="value"]').val(model.headers[i].value);
|
template.find('input[name="value"]').val(model.headers[i].value);
|
||||||
template.find('button').attr("data-id", i);
|
template.find('button').attr("data-id", i);
|
||||||
|
|
||||||
|
template.find('input[name="enabled"]').on('change', function () {
|
||||||
|
model.headers[i].enabled = $(this).prop('checked');
|
||||||
|
});
|
||||||
template.find('input[name="key"]').on('input', function () {
|
template.find('input[name="key"]').on('input', function () {
|
||||||
model.headers[i].key = $(this).val();
|
model.headers[i].key = $(this).val();
|
||||||
});
|
});
|
||||||
@@ -336,7 +358,7 @@
|
|||||||
let queryParamArray = queryString.split('&');
|
let queryParamArray = queryString.split('&');
|
||||||
for (let i = 0; i < queryParamArray.length; i++) {
|
for (let i = 0; i < queryParamArray.length; i++) {
|
||||||
let queryParam = queryParamArray[i].split('=');
|
let queryParam = queryParamArray[i].split('=');
|
||||||
controller.addQueryParam(idx, queryParam[0], queryParam[1]);
|
controller.addQueryParam(idx, queryParam[0], queryParam[1]===undefined?'' : queryParam[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -428,6 +450,7 @@
|
|||||||
addHeader: function (tabIdx) {
|
addHeader: function (tabIdx) {
|
||||||
let model = apiRequests[tabIdx];
|
let model = apiRequests[tabIdx];
|
||||||
model.headers.push({
|
model.headers.push({
|
||||||
|
enabled: true,
|
||||||
key: '',
|
key: '',
|
||||||
value: ''
|
value: ''
|
||||||
});
|
});
|
||||||
@@ -436,11 +459,12 @@
|
|||||||
removeHeader: function (tabIdx, idx) {
|
removeHeader: function (tabIdx, idx) {
|
||||||
let model = apiRequests[tabIdx];
|
let model = apiRequests[tabIdx];
|
||||||
model.headers.splice(idx, 1);
|
model.headers.splice(idx, 1);
|
||||||
view.renderHeaders(idx);
|
view.renderHeaders(tabIdx);
|
||||||
},
|
},
|
||||||
addQueryParam: function (tabIdx, key, value) {
|
addQueryParam: function (tabIdx, key, value) {
|
||||||
let model = apiRequests[tabIdx];
|
let model = apiRequests[tabIdx];
|
||||||
model.queryParams.push({
|
model.queryParams.push({
|
||||||
|
enabled: true,
|
||||||
key: key,
|
key: key,
|
||||||
value: value
|
value: value
|
||||||
});
|
});
|
||||||
@@ -453,6 +477,9 @@
|
|||||||
queryString += '?';
|
queryString += '?';
|
||||||
}
|
}
|
||||||
for (let i = 0; i < model.queryParams.length; i++) {
|
for (let i = 0; i < model.queryParams.length; i++) {
|
||||||
|
if(!model.queryParams[i].enabled){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
queryString += model.queryParams[i].key + '=' + model.queryParams[i].value;
|
queryString += model.queryParams[i].key + '=' + model.queryParams[i].value;
|
||||||
if (i < model.queryParams.length - 1) {
|
if (i < model.queryParams.length - 1) {
|
||||||
queryString += '&';
|
queryString += '&';
|
||||||
|
|||||||
Reference in New Issue
Block a user