mirror of https://github.com/grpc/grpc-java.git
okhttp: Fix okio 2.x API incompatibility (#9054)
This commit is contained in:
parent
18753b654f
commit
78308c0c6a
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package io.grpc.okhttp.internal.proxy;
|
package io.grpc.okhttp.internal.proxy;
|
||||||
|
|
||||||
|
import java.io.EOFException;
|
||||||
import java.net.IDN;
|
import java.net.IDN;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
@ -433,8 +434,7 @@ public final class HttpUrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void canonicalize(Buffer out, String input, int pos, int limit,
|
static void canonicalize(Buffer out, String input, int pos, int limit,
|
||||||
String encodeSet, boolean alreadyEncoded, boolean plusIsSpace, boolean asciiOnly)
|
String encodeSet, boolean alreadyEncoded, boolean plusIsSpace, boolean asciiOnly) {
|
||||||
throws Exception {
|
|
||||||
Buffer utf8Buffer = null; // Lazily allocated.
|
Buffer utf8Buffer = null; // Lazily allocated.
|
||||||
int codePoint;
|
int codePoint;
|
||||||
for (int i = pos; i < limit; i += Character.charCount(codePoint)) {
|
for (int i = pos; i < limit; i += Character.charCount(codePoint)) {
|
||||||
|
@ -456,10 +456,15 @@ public final class HttpUrl {
|
||||||
}
|
}
|
||||||
utf8Buffer.writeUtf8CodePoint(codePoint);
|
utf8Buffer.writeUtf8CodePoint(codePoint);
|
||||||
while (!utf8Buffer.exhausted()) {
|
while (!utf8Buffer.exhausted()) {
|
||||||
|
try {
|
||||||
|
fakeEofExceptionMethod(); // Okio 2.x can throw EOFException from readByte()
|
||||||
int b = utf8Buffer.readByte() & 0xff;
|
int b = utf8Buffer.readByte() & 0xff;
|
||||||
out.writeByte('%');
|
out.writeByte('%');
|
||||||
out.writeByte(HEX_DIGITS[(b >> 4) & 0xf]);
|
out.writeByte(HEX_DIGITS[(b >> 4) & 0xf]);
|
||||||
out.writeByte(HEX_DIGITS[b & 0xf]);
|
out.writeByte(HEX_DIGITS[b & 0xf]);
|
||||||
|
} catch (EOFException e) {
|
||||||
|
throw new IndexOutOfBoundsException(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This character doesn't need encoding. Just copy it over.
|
// This character doesn't need encoding. Just copy it over.
|
||||||
|
@ -467,4 +472,6 @@ public final class HttpUrl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void fakeEofExceptionMethod() throws EOFException {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue