Skip to content

Commit

Permalink
Fixing headers
Browse files Browse the repository at this point in the history
  • Loading branch information
povel62 committed Jul 15, 2020
1 parent 0caa306 commit 6cae814
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public HttpClientResponseDTO handleCall(final HttpClientCallDTO dto, boolean jus
return new HttpClientResponseDTO(HttpStatus.NOT_FOUND.value());
}
String url = dto.getUrl();
dto.setUrl(redirectUrl + url);
dto.setUrl((redirectUrl + url).replaceAll("(?<!(http:|https:))//", "/"));
switch (dto.getMethod()) {
case GET:
httpClientResponseDTO = get(dto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Optional;
import java.util.*;

import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -40,6 +38,8 @@
import spark.Request;
import spark.Response;

import javax.servlet.http.HttpServletRequest;

/**
* Created by mgallina.
*/
Expand Down Expand Up @@ -76,6 +76,23 @@ public class MockedRestServerEngineUtils {
@Autowired
private HttpClientService httpClientService;

private Map<String, String> getHeadersInfo(HttpServletRequest request) {
Map<String, String> map = new HashMap<String, String>();

Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {

String key = (String) headerNames.nextElement();
String value = request.getHeader(key);
System.out.println(key + ": " + value);

if(!(key.equalsIgnoreCase("Content-Length") || key.equalsIgnoreCase("Host")))
map.put(key, value);
}

return map;
}

public Optional<String> loadMockedResponse(final Request request,
final Response response,
final boolean isMultiUserMode) {
Expand All @@ -86,7 +103,9 @@ public Optional<String> loadMockedResponse(final Request request,
HttpClientCallDTO http = new HttpClientCallDTO();
http.setUrl(request.pathInfo());
http.setMethod(RestMethodEnum.findByName(request.requestMethod()));
http.setHeaders(request.params());
http.setHeaders(getHeadersInfo(request.raw()));
// http.setHeaders(request.params());

http.setBody(request.body());
HttpClientResponseDTO responseDto = null;
try
Expand All @@ -99,7 +118,8 @@ public Optional<String> loadMockedResponse(final Request request,
}

if(responseDto != null && responseDto.getStatus() != 404) {
return Optional.of(new ResponseEntity<HttpClientResponseDTO>(responseDto, HttpStatus.OK).getBody().getBody());
response.status(responseDto.getStatus());
return Optional.of(new ResponseEntity<HttpClientResponseDTO>(responseDto, HttpStatus.resolve(responseDto.getStatus())).getBody().getBody());
}

try {
Expand Down

0 comments on commit 6cae814

Please sign in to comment.