mirror of
https://github.com/square/okhttp.git
synced 2025-08-01 16:06:56 +03:00
Don't use @JvmStatic for internal calls
This commit is contained in:
@ -35,7 +35,6 @@ object DnsRecordCodec {
|
||||
private const val TYPE_PTR = 0x000c
|
||||
private val ASCII = StandardCharsets.US_ASCII
|
||||
|
||||
@JvmStatic
|
||||
fun encodeQuery(host: String, type: Int): ByteString = Buffer().apply {
|
||||
writeShort(0) // query id
|
||||
writeShort(256) // flags with recursion
|
||||
@ -62,7 +61,6 @@ object DnsRecordCodec {
|
||||
}.readByteString()
|
||||
|
||||
@Throws(Exception::class)
|
||||
@JvmStatic
|
||||
fun decodeAnswers(hostname: String, byteString: ByteString): List<InetAddress> {
|
||||
val result = ArrayList<InetAddress>()
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class DnsRecordCodecTest {
|
||||
}
|
||||
|
||||
private String encodeQuery(String host, int type) {
|
||||
return DnsRecordCodec.encodeQuery(host, type).base64Url().replace("=", "");
|
||||
return DnsRecordCodec.INSTANCE.encodeQuery(host, type).base64Url().replace("=", "");
|
||||
}
|
||||
|
||||
@Test public void testGoogleDotComEncodingWithIPv6() {
|
||||
@ -44,30 +44,37 @@ public class DnsRecordCodecTest {
|
||||
}
|
||||
|
||||
@Test public void testGoogleDotComDecodingFromCloudflare() throws Exception {
|
||||
List<InetAddress> encoded = DnsRecordCodec.decodeAnswers("test.com", ByteString.decodeHex(
|
||||
"00008180000100010000000006676f6f676c6503636f6d0000010001c00c00010001000000430004d83ad54e"));
|
||||
List<InetAddress> encoded = DnsRecordCodec.INSTANCE.decodeAnswers("test.com",
|
||||
ByteString.decodeHex("00008180000100010000000006676f6f676c6503636f6d0000010001c00c000100010"
|
||||
+ "00000430004d83ad54e"));
|
||||
|
||||
assertThat(encoded).containsExactly(InetAddress.getByName("216.58.213.78"));
|
||||
}
|
||||
|
||||
@Test public void testGoogleDotComDecodingFromGoogle() throws Exception {
|
||||
List<InetAddress> decoded = DnsRecordCodec.decodeAnswers("test.com", ByteString.decodeHex(
|
||||
"0000818000010003000000000567726170680866616365626f6f6b03636f6d0000010001c00c0005000100000a6d000603617069c012c0300005000100000cde000c04737461720463313072c012c042000100010000003b00049df00112"));
|
||||
List<InetAddress> decoded = DnsRecordCodec.INSTANCE.decodeAnswers("test.com",
|
||||
ByteString.decodeHex("0000818000010003000000000567726170680866616365626f6f6b03636f6d0000010"
|
||||
+ "001c00c0005000100000a6d000603617069c012c0300005000100000cde000c04737461720463313072c"
|
||||
+ "012c042000100010000003b00049df00112"));
|
||||
|
||||
assertThat(decoded).containsExactly(InetAddress.getByName("157.240.1.18"));
|
||||
}
|
||||
|
||||
@Test public void testGoogleDotComDecodingFromGoogleIPv6() throws Exception {
|
||||
List<InetAddress> decoded = DnsRecordCodec.decodeAnswers("test.com", ByteString.decodeHex(
|
||||
"0000818000010003000000000567726170680866616365626f6f6b03636f6d00001c0001c00c0005000100000a1b000603617069c012c0300005000100000b1f000c04737461720463313072c012c042001c00010000003b00102a032880f0290011faceb00c00000002"));
|
||||
List<InetAddress> decoded = DnsRecordCodec.INSTANCE.decodeAnswers("test.com",
|
||||
ByteString.decodeHex("0000818000010003000000000567726170680866616365626f6f6b03636f6d00001c0"
|
||||
+ "001c00c0005000100000a1b000603617069c012c0300005000100000b1f000c04737461720463313072c"
|
||||
+ "012c042001c00010000003b00102a032880f0290011faceb00c00000002"));
|
||||
|
||||
assertThat(decoded).containsExactly(InetAddress.getByName("2a03:2880:f029:11:face:b00c:0:2"));
|
||||
}
|
||||
|
||||
@Test public void testGoogleDotComDecodingNxdomainFailure() throws Exception {
|
||||
try {
|
||||
DnsRecordCodec.decodeAnswers("sdflkhfsdlkjdf.ee", ByteString.decodeHex(
|
||||
"0000818300010000000100000e7364666c6b686673646c6b6a64660265650000010001c01b00060001000007070038026e7303746c64c01b0a686f73746d61737465720d6565737469696e7465726e6574c01b5adb12c100000e10000003840012750000000e10"));
|
||||
DnsRecordCodec.INSTANCE.decodeAnswers("sdflkhfsdlkjdf.ee", ByteString.decodeHex("000081830001"
|
||||
+ "0000000100000e7364666c6b686673646c6b6a64660265650000010001c01b00060001000007070038026e"
|
||||
+ "7303746c64c01b0a686f73746d61737465720d6565737469696e7465726e6574c01b5adb12c100000e1000"
|
||||
+ "0003840012750000000e10"));
|
||||
fail();
|
||||
} catch (UnknownHostException uhe) {
|
||||
assertThat(uhe.getMessage()).isEqualTo("sdflkhfsdlkjdf.ee: NXDOMAIN");
|
||||
|
Reference in New Issue
Block a user