-
-
Notifications
You must be signed in to change notification settings - Fork 356
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 Host IP address in the overview and sharable #1180
base: main
Are you sure you want to change the base?
Add Host IP address in the overview and sharable #1180
Conversation
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.
Thanks for the PR @FarshidRoohi.
I've left one comment
public fun Response.getHostIp(): String? { | ||
val body = body?.source()?.readUtf8() | ||
val pattern: Pattern = Pattern.compile(IP_REGEX) | ||
val matcher: Matcher? = body?.let { pattern.matcher(it) } | ||
if (matcher?.find() == true) { | ||
return matcher.group() | ||
} | ||
return null | ||
} |
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.
Can you test this function?
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.
I wrote two tests for this extension function.
https://github.com/ChuckerTeam/chucker/pull/1180/files#diff-9e02dc5b49faba047a35920cbd28850dec0ae4a568dd09ba6264dc754c332dcaR55
@@ -43,6 +43,7 @@ internal class ResponseProcessor( | |||
requestDate = response.sentRequestAtMillis | |||
responseDate = response.receivedResponseAtMillis | |||
protocol = response.protocol.toString() | |||
hostIp = response.body?.source()?.getHostIp() |
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.
I'm having trouble understanding this. Why is it assumed that the response body contains IP?
private const val IP_REGEX = "(?:\\d{1,3}\\.){3}\\d{1,3}" | ||
|
||
public fun BufferedSource.getHostIp(): String? { | ||
val body = readUtf8() |
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.
This reads the whole body of the source to the memory and assumes that it is UTF-8 encoded.
📷 Screenshots
📄 Context
I needed to know the IP address of each request because each request might be directed to a specific server with a specific IP address. Having the CDN IP address can be very helpful in troubleshooting issues. Therefore, I thought it would be useful for other developers as well, and that's why I added this information.
📝 Changes