Skip to content

Commit

Permalink
Merge pull request #244 from newrelic/fix/form-urlencoded-NR-259579
Browse files Browse the repository at this point in the history
Fix for application/form-urlencoded content-type curl with empty body
  • Loading branch information
lovesh-ap authored May 13, 2024
2 parents ad8439a + 54e7380 commit 332d090
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class RequestUtils {

private static final FileLoggerThreadPool logger = FileLoggerThreadPool.getInstance();
public static final String ERROR_IN_FUZZ_REQUEST_GENERATION = "Error in fuzz request generation {}";
public static final String APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded";

public static Request generateK2Request(FuzzRequestBean httpRequest, String endpoint) {
try {
Expand All @@ -27,19 +28,20 @@ public static Request generateK2Request(FuzzRequestBean httpRequest, String endp
RequestBody requestBody = null;

if (StringUtils.isNotBlank(httpRequest.getContentType())) {
if (httpRequest.getParameterMap() != null && !httpRequest.getParameterMap().isEmpty()) {
if (httpRequest.getParameterMap() != null && !httpRequest.getParameterMap().isEmpty() && StringUtils.startsWith(httpRequest.getContentType(), APPLICATION_X_WWW_FORM_URLENCODED)) {
FormBody.Builder builder = new FormBody.Builder();
for (Entry<String, String[]> param : httpRequest.getParameterMap().entrySet()) {
for (int i = 0; i < param.getValue().length; i++) {
builder.add(param.getKey(), param.getValue()[i]);
}
}
requestBody = builder.build();
} else {
} else if( StringUtils.isNotBlank(httpRequest.getBody().toString())) {
requestBody = RequestBody.create(httpRequest.getBody().toString(),
MediaType.parse(httpRequest.getContentType()));
}
} else if (StringUtils.equalsIgnoreCase(httpRequest.getMethod(), "POST")) {
}
if (requestBody == null && HttpMethod.permitsRequestBody(httpRequest.getMethod())) {
requestBody = RequestBody.create(httpRequest.getBody().toString(), null);
}

Expand Down

0 comments on commit 332d090

Please sign in to comment.