query, header enabled 적용

This commit is contained in:
현성필
2023-05-09 20:21:51 +09:00
parent e854ed4969
commit b23347fc28
4 changed files with 45 additions and 6 deletions
@@ -1,6 +1,5 @@
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.entity.MockCondition;
import com.eactive.httpmockserver.api.entity.MockResponse;
@@ -2,9 +2,19 @@ package com.eactive.httpmockserver.client.dto;
public class ApiHeaderDTO {
private boolean enabled;
private String key;
private String value;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getKey() {
return key;
}
@@ -1,5 +1,6 @@
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.ApiResponse;
import com.eactive.httpmockserver.client.entity.Server;
@@ -85,8 +86,10 @@ public class NettyApiClient {
if (apiRequest.getHeaders().size() > 0) {
HttpHeaders customHeaders = new DefaultHttpHeaders();
apiRequest.getHeaders().forEach((header) -> {
customHeaders.set(header.getKey(), header.getValue());
apiRequest.getHeaders().stream().filter(ApiHeaderDTO::isEnabled).forEach((header) -> {
if(StringUtils.isNotEmpty(header.getKey()) && StringUtils.isNotEmpty(header.getValue())){
customHeaders.set(header.getKey(), header.getValue());
}
});
request.headers().add(customHeaders);
}
@@ -79,6 +79,7 @@
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">이름</th>
<th></th>
<th>
@@ -96,9 +97,10 @@
<table class="table">
<thead>
<tr>
<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>
</th>
@@ -159,6 +161,11 @@
<table>
<tbody>
<tr>
<td>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="enabled"/>
</div>
</td>
<td>
<input class="form-control" type="text" name="key"/>
</td>
@@ -223,8 +230,15 @@
let template = $('#inputTemplate').children().find('tr').clone();
template.find('input[name="key"]').val(model.queryParams[i].key);
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('input[name="enabled"]').on('change', function () {
model.queryParams[i].enabled = $(this).prop('checked');
controller.buildPath(tabIdx);
});
template.find('input[name="key"]').on('focusout', function () {
model.queryParams[i].key = $(this).val();
controller.buildPath(tabIdx);
@@ -245,12 +259,20 @@
target.find('.request_headers').empty();
let model = apiRequests[tabIdx];
console.log(model);
for (let i = 0; i < model.headers.length; i++) {
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="value"]').val(model.headers[i].value);
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 () {
model.headers[i].key = $(this).val();
});
@@ -336,7 +358,7 @@
let queryParamArray = queryString.split('&');
for (let i = 0; i < queryParamArray.length; i++) {
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) {
let model = apiRequests[tabIdx];
model.headers.push({
enabled: true,
key: '',
value: ''
});
@@ -436,11 +459,12 @@
removeHeader: function (tabIdx, idx) {
let model = apiRequests[tabIdx];
model.headers.splice(idx, 1);
view.renderHeaders(idx);
view.renderHeaders(tabIdx);
},
addQueryParam: function (tabIdx, key, value) {
let model = apiRequests[tabIdx];
model.queryParams.push({
enabled: true,
key: key,
value: value
});
@@ -453,6 +477,9 @@
queryString += '?';
}
for (let i = 0; i < model.queryParams.length; i++) {
if(!model.queryParams[i].enabled){
continue;
}
queryString += model.queryParams[i].key + '=' + model.queryParams[i].value;
if (i < model.queryParams.length - 1) {
queryString += '&';