-
-
Notifications
You must be signed in to change notification settings - Fork 444
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
Add optional 'body' field to HttpInterface. #334
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d70e063
Add optional 'body' field to HttpInterface.
bretthoerner 922309d
Merge remote-tracking branch 'origin/master' into http-body
bretthoerner 03907eb
Adjust body length based on SDK docs.
bretthoerner 73ba3ab
Fixes.
bretthoerner 2134aed
Checkstyle. :(
bretthoerner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ public class HttpInterface implements SentryInterface { | |
private final String authType; | ||
private final String remoteUser; | ||
private final Map<String, Collection<String>> headers; | ||
private final String body; | ||
|
||
/** | ||
* This constructor is for compatibility reasons and should not be used. | ||
|
@@ -49,6 +50,17 @@ public HttpInterface(HttpServletRequest request) { | |
* @param remoteAddressResolver RemoteAddressResolver | ||
*/ | ||
public HttpInterface(HttpServletRequest request, RemoteAddressResolver remoteAddressResolver) { | ||
this(request, remoteAddressResolver, null); | ||
} | ||
|
||
/** | ||
* Creates a an HTTP element for an {@link com.getsentry.raven.event.Event}. | ||
* | ||
* @param request Captured HTTP request to send to Sentry. | ||
* @param remoteAddressResolver RemoteAddressResolver | ||
* @param body HTTP request body (optional) | ||
*/ | ||
public HttpInterface(HttpServletRequest request, RemoteAddressResolver remoteAddressResolver, String body) { | ||
this.requestUrl = request.getRequestURL().toString(); | ||
this.method = request.getMethod(); | ||
this.parameters = new HashMap<>(); | ||
|
@@ -79,6 +91,7 @@ public HttpInterface(HttpServletRequest request, RemoteAddressResolver remoteAdd | |
for (String headerName : Collections.list(request.getHeaderNames())) { | ||
this.headers.put(headerName, Collections.list(request.getHeaders(headerName))); | ||
} | ||
this.body = body; | ||
} | ||
|
||
@Override | ||
|
@@ -150,6 +163,10 @@ public String getRemoteUser() { | |
return remoteUser; | ||
} | ||
|
||
public String getBody() { | ||
return body; | ||
} | ||
|
||
public Map<String, Collection<String>> getHeaders() { | ||
return Collections.unmodifiableMap(headers); | ||
} | ||
|
@@ -226,6 +243,9 @@ public boolean equals(Object o) { | |
if (serverName != null ? !serverName.equals(that.serverName) : that.serverName != null) { | ||
return false; | ||
} | ||
if (body != null ? !body.equals(that.body) : that.body != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clever |
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,4 +109,22 @@ public static Double parseDouble(String value, Double defaultValue) { | |
} | ||
return Double.parseDouble(value); | ||
} | ||
|
||
/** | ||
* Trims a String, ensuring that the maximum length isn't reached. | ||
* | ||
* @param string string to trim | ||
* @param maxMessageLength maximum length of the string | ||
* @return trimmed string | ||
*/ | ||
public static String trimString(String string, int maxMessageLength) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be worth considering ellipisizing this? I'm not sure what behavior is consistent among the other SDKs…? |
||
if (string == null) { | ||
return null; | ||
} else if (string.length() > maxMessageLength) { | ||
return string.substring(0, maxMessageLength); | ||
} else { | ||
return string; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
raven/src/test/resources/com/getsentry/raven/marshaller/json/Http1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"a an"