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 UI for emtpy body in request/response #562

Merged
merged 1 commit into from
Feb 15, 2021
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 @@ -247,17 +247,24 @@ internal class TransactionPayloadFragment :

// The body could either be an image, plain text, decoded binary or not decoded binary.
val responseBitmap = transaction.responseImageBitmap
when {
type == PayloadType.RESPONSE && responseBitmap != null -> {
val bitmapLuminance = responseBitmap.calculateLuminance()
result.add(TransactionPayloadItem.ImageItem(responseBitmap, bitmapLuminance))
}
bodyString.isNotBlank() -> bodyString.lines().forEach {
result.add(TransactionPayloadItem.BodyLineItem(SpannableStringBuilder.valueOf(it)))
}
!isBodyPlainText -> {

if (type == PayloadType.RESPONSE && responseBitmap != null) {
val bitmapLuminance = responseBitmap.calculateLuminance()
result.add(TransactionPayloadItem.ImageItem(responseBitmap, bitmapLuminance))
return@withContext result
}

if (bodyString.isBlank()) {
val text = requireContext().getString(R.string.chucker_body_empty)
result.add(TransactionPayloadItem.BodyLineItem(SpannableStringBuilder.valueOf(text)))
} else {
if (!isBodyPlainText) {
Copy link
Contributor

@MiSikora MiSikora Feb 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be handled in a different way. Otherwise non-blank bodies that are not plain text but decoded from a different format will not show. This can be checked with a Postman proto echo call.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you are right, just checked. Not sure how we can handle it elegantly, since we also need to understand whenever the content is decoded.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I'm getting it now. There's one thing I didn't consider when refactoring in #543. isBodyPlainText was true by default before (same for responses in #554), so it breaks here.

I'm not sure how to proceed with it. IMHO setting property that body is plain text when there is no body was a bug but this complicates things because we can't do check like this.

when {
  isImage -> showImage()
  bodyIsNotEmpty -> showBody()
  bodyIsPlainText -> showEmptyText()
  else -> showEncodedText()
}

Maybe the best way would be to have isBodyEncoded property instead of isBodyPlainText? This way combination of conditions should work properly I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isBodyEncoded would work, I believe.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is something for a follow up PR?

Copy link
Contributor

@MiSikora MiSikora Feb 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind fixing it in another PR but wouldn't this make this PR just trade one bug for another?

After typing it I guess not. It will be just removing new functionality, so I'm ok with doing it in another PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might misunderstood you initially, because I thought that you want to deal with it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind dealing with it. I just want get it fixed one way or the other. :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, merging this one. Let's discuss that other fix in Slack.

val text = requireContext().getString(R.string.chucker_body_omitted)
result.add(TransactionPayloadItem.BodyLineItem(SpannableStringBuilder.valueOf(text)))
} else {
bodyString.lines().forEach {
result.add(TransactionPayloadItem.BodyLineItem(SpannableStringBuilder.valueOf(it)))
}
}
}

Expand Down