Skip to content

Commit

Permalink
Support http headers
Browse files Browse the repository at this point in the history
  • Loading branch information
pc9795 committed Nov 18, 2023
1 parent f73b45a commit c609c65
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class RequestInfo extends Model {
@Builder.Default Map<String, String> cookies = new HashMap<>();
Object postData;
@Builder.Default Map<String, List<String>> queryString = new HashMap<>();
@Builder.Default Map<String, List<String>> headers = new HashMap<>();

public Boolean isSecure() {
return secure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public int getPriority() {
}

@Override
public void run(
EventPluginContext eventPluginContext, Configuration configuration) {
public void run(EventPluginContext eventPluginContext, Configuration configuration) {
Event event = eventPluginContext.getEvent();
if (event.getRequestInfo().isPresent()) {
return;
Expand All @@ -47,10 +46,8 @@ public void run(
RequestInfoGetArgs.builder()
.exclusions(configuration.getDataExclusions())
.includeCookies(configuration.getPrivateInformationInclusions().getCookies())
.includeIpAddress(
configuration.getPrivateInformationInclusions().getIpAddress())
.includePostData(
configuration.getPrivateInformationInclusions().getPostData())
.includeIpAddress(configuration.getPrivateInformationInclusions().getIpAddress())
.includePostData(configuration.getPrivateInformationInclusions().getPostData())
.includeQueryString(
configuration.getPrivateInformationInclusions().getQueryString())
.build());
Expand All @@ -73,7 +70,8 @@ private RequestInfo getRequestInfo(HttpRequest request, RequestInfoGetArgs args)
.httpMethod(request.method())
.host(request.uri().getHost())
.path(request.uri().getPath())
.port(request.uri().getPort());
.port(request.uri().getPort())
.headers(request.headers().map());

if (args.isIncludeIpAddress()) {
try {
Expand All @@ -94,8 +92,6 @@ private RequestInfo getRequestInfo(HttpRequest request, RequestInfoGetArgs args)
filterExclusions(Utils.getQueryParams(request.uri()), args.getExclusions()));
}

// todo get post data from request.

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ public void itShouldCancelEventIfUserAgentIsABotPattern() {
@Test
public void itShouldAddRequestInfoToEvent() {
HttpRequest httpRequest =
HttpRequest.newBuilder().uri(URI.create("http://localhost:5000/test-path")).GET().build();
HttpRequest.newBuilder()
.uri(URI.create("http://localhost:5000/test-path"))
.header("test-header", "test-header-value")
.header("test-header", "test-header-value-2")
.GET()
.build();
context =
EventPluginContext.builder()
.event(Event.builder().build())
Expand All @@ -108,6 +113,8 @@ public void itShouldAddRequestInfoToEvent() {
assertThat(requestInfo.getHost()).isEqualTo("localhost");
assertThat(requestInfo.getPath()).isEqualTo("/test-path");
assertThat(requestInfo.getPort()).isEqualTo(5000);
assertThat(requestInfo.getHeaders())
.isEqualTo(Map.of("test-header", List.of("test-header-value", "test-header-value-2")));
}

@Test
Expand Down Expand Up @@ -163,8 +170,7 @@ public void itCanGetIpAddressCookiesAndQueryStringFromAHttpRequest() {
.context(PluginContext.builder().request(httpRequest).build())
.build();

PrivateInformationInclusions inclusions =
configuration.getPrivateInformationInclusions();
PrivateInformationInclusions inclusions = configuration.getPrivateInformationInclusions();
inclusions.setIpAddress(true);
inclusions.setCookies(true);
inclusions.setQueryString(true);
Expand Down Expand Up @@ -197,8 +203,7 @@ public void itCanExcludeData() {
.context(PluginContext.builder().request(httpRequest).build())
.build();
configuration.addDataExclusions("exclude-query-param", "exclude-cookie");
PrivateInformationInclusions inclusions =
configuration.getPrivateInformationInclusions();
PrivateInformationInclusions inclusions = configuration.getPrivateInformationInclusions();
inclusions.setIpAddress(true);
inclusions.setCookies(true);
inclusions.setQueryString(true);
Expand Down

0 comments on commit c609c65

Please sign in to comment.