Skip to content

Commit

Permalink
Fix issue with sending response headers (#34)
Browse files Browse the repository at this point in the history
The request headers were being sent for both the request as well as the
response headers while exporting.

Signed-off-by: Akshath Kothari <[email protected]>
  • Loading branch information
ricekot authored Jul 18, 2024
1 parent 7b394e1 commit f37812f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
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

0 comments on commit f37812f

Please sign in to comment.