Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for application/form-urlencoded content-type curl with empty body #244

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading