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 issue with sending response headers #34

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apply plugin: 'java'
apply plugin: 'maven-publish'

group 'ai.levo'
version '0.1.12'
version '0.1.13'

def burpExtensionHomepage = 'https://github.com/levoai/levoai-burp-extension'
def burpExtensionJarName = 'LevoAiBurpExtension.jar'
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/ai/levo/HttpMessagePublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,19 @@ private HttpMessage convertToHttpMessage(IRequestInfo reqInfo, byte[] reqContent
request.getHeaders().put(":path", reqInfo.getUrl().getPath());
}

String requestBody = callbacks.getHelpers().bytesToString(reqContent);
String[] parts = requestBody.split(TWO_LINES_PATTERN);
if (parts.length > 1 && parts[1].length() > 0) {
String[] requestParts = callbacks.getHelpers().bytesToString(reqContent).split(TWO_LINES_PATTERN);
if (requestParts.length > 1 && !requestParts[1].isEmpty()) {
// Base64 encode the body.
request.setBody(callbacks.getHelpers().base64Encode(parts[1]));
request.setBody(callbacks.getHelpers().base64Encode(requestParts[1]));
} else {
request.setBody("");
}

HttpMessage.Response response = new HttpMessage.Response();
String[] responseParts = callbacks.getHelpers().bytesToString(resContent).split(TWO_LINES_PATTERN);

// Create response headers from the first part of the response. Ignore the status line.
String[] responseHeaders = parts[0].split(NEW_LINE_PATTERN);
String[] responseHeaders = responseParts[0].split(NEW_LINE_PATTERN);
if (responseHeaders.length > 1) {
// Create a list from an array and remove the first element since that's status line.
List<String> headers = java.util.Arrays.asList(responseHeaders);
Expand All @@ -161,11 +161,9 @@ private HttpMessage convertToHttpMessage(IRequestInfo reqInfo, byte[] reqContent
alertWriter.writeAlert("Not sending response body for content-type: " + contentType + " to Levo.");
response.setBody("");
} else {
String responseBody = callbacks.getHelpers().bytesToString(resContent);
parts = responseBody.split(TWO_LINES_PATTERN);
if (parts.length > 1 && parts[1].length() > 0) {
if (responseParts.length > 1 && !responseParts[1].isEmpty()) {
// Base64 encode the response body.
response.setBody(callbacks.getHelpers().base64Encode(parts[1]));
response.setBody(callbacks.getHelpers().base64Encode(responseParts[1]));
} else {
// Don't drop the message if the response body is empty.
response.setBody("");
Expand Down
Loading