Fix detection of truncation (so messages exactly max length aren't flagged truncated)

This commit is contained in:
Steve Waldman 2019-06-29 00:08:44 -07:00
parent 1b21f200b5
commit 20ca549612
1 changed files with 10 additions and 5 deletions

View File

@ -209,13 +209,18 @@ class GigahorseUrlHandler(http: OkHttpClient) extends AbstractURLHandler {
val os = new ByteArrayOutputStream(ErrorBodyTruncateLen)
var count = 0
var b = is.read()
while (b >= 0 && count < ErrorBodyTruncateLen) {
os.write(b)
count += 1
b = is.read()
var truncated = false
while (!truncated && b >= 0) {
if (count >= ErrorBodyTruncateLen) {
truncated = true
} else {
os.write(b)
count += 1
b = is.read()
}
}
if (count > 0) {
Some((os.toByteArray, count >= ErrorBodyTruncateLen))
Some((os.toByteArray, truncated))
} else {
None
}