mirror of
https://github.com/square/okhttp.git
synced 2025-08-07 12:42:57 +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 const val TYPE_PTR = 0x000c
|
||||||
private val ASCII = StandardCharsets.US_ASCII
|
private val ASCII = StandardCharsets.US_ASCII
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun encodeQuery(host: String, type: Int): ByteString = Buffer().apply {
|
fun encodeQuery(host: String, type: Int): ByteString = Buffer().apply {
|
||||||
writeShort(0) // query id
|
writeShort(0) // query id
|
||||||
writeShort(256) // flags with recursion
|
writeShort(256) // flags with recursion
|
||||||
@@ -62,7 +61,6 @@ object DnsRecordCodec {
|
|||||||
}.readByteString()
|
}.readByteString()
|
||||||
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
@JvmStatic
|
|
||||||
fun decodeAnswers(hostname: String, byteString: ByteString): List<InetAddress> {
|
fun decodeAnswers(hostname: String, byteString: ByteString): List<InetAddress> {
|
||||||
val result = ArrayList<InetAddress>()
|
val result = ArrayList<InetAddress>()
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ public class DnsRecordCodecTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String encodeQuery(String host, int type) {
|
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() {
|
@Test public void testGoogleDotComEncodingWithIPv6() {
|
||||||
@@ -44,30 +44,37 @@ public class DnsRecordCodecTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testGoogleDotComDecodingFromCloudflare() throws Exception {
|
@Test public void testGoogleDotComDecodingFromCloudflare() throws Exception {
|
||||||
List<InetAddress> encoded = DnsRecordCodec.decodeAnswers("test.com", ByteString.decodeHex(
|
List<InetAddress> encoded = DnsRecordCodec.INSTANCE.decodeAnswers("test.com",
|
||||||
"00008180000100010000000006676f6f676c6503636f6d0000010001c00c00010001000000430004d83ad54e"));
|
ByteString.decodeHex("00008180000100010000000006676f6f676c6503636f6d0000010001c00c000100010"
|
||||||
|
+ "00000430004d83ad54e"));
|
||||||
|
|
||||||
assertThat(encoded).containsExactly(InetAddress.getByName("216.58.213.78"));
|
assertThat(encoded).containsExactly(InetAddress.getByName("216.58.213.78"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testGoogleDotComDecodingFromGoogle() throws Exception {
|
@Test public void testGoogleDotComDecodingFromGoogle() throws Exception {
|
||||||
List<InetAddress> decoded = DnsRecordCodec.decodeAnswers("test.com", ByteString.decodeHex(
|
List<InetAddress> decoded = DnsRecordCodec.INSTANCE.decodeAnswers("test.com",
|
||||||
"0000818000010003000000000567726170680866616365626f6f6b03636f6d0000010001c00c0005000100000a6d000603617069c012c0300005000100000cde000c04737461720463313072c012c042000100010000003b00049df00112"));
|
ByteString.decodeHex("0000818000010003000000000567726170680866616365626f6f6b03636f6d0000010"
|
||||||
|
+ "001c00c0005000100000a6d000603617069c012c0300005000100000cde000c04737461720463313072c"
|
||||||
|
+ "012c042000100010000003b00049df00112"));
|
||||||
|
|
||||||
assertThat(decoded).containsExactly(InetAddress.getByName("157.240.1.18"));
|
assertThat(decoded).containsExactly(InetAddress.getByName("157.240.1.18"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testGoogleDotComDecodingFromGoogleIPv6() throws Exception {
|
@Test public void testGoogleDotComDecodingFromGoogleIPv6() throws Exception {
|
||||||
List<InetAddress> decoded = DnsRecordCodec.decodeAnswers("test.com", ByteString.decodeHex(
|
List<InetAddress> decoded = DnsRecordCodec.INSTANCE.decodeAnswers("test.com",
|
||||||
"0000818000010003000000000567726170680866616365626f6f6b03636f6d00001c0001c00c0005000100000a1b000603617069c012c0300005000100000b1f000c04737461720463313072c012c042001c00010000003b00102a032880f0290011faceb00c00000002"));
|
ByteString.decodeHex("0000818000010003000000000567726170680866616365626f6f6b03636f6d00001c0"
|
||||||
|
+ "001c00c0005000100000a1b000603617069c012c0300005000100000b1f000c04737461720463313072c"
|
||||||
|
+ "012c042001c00010000003b00102a032880f0290011faceb00c00000002"));
|
||||||
|
|
||||||
assertThat(decoded).containsExactly(InetAddress.getByName("2a03:2880:f029:11:face:b00c:0:2"));
|
assertThat(decoded).containsExactly(InetAddress.getByName("2a03:2880:f029:11:face:b00c:0:2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testGoogleDotComDecodingNxdomainFailure() throws Exception {
|
@Test public void testGoogleDotComDecodingNxdomainFailure() throws Exception {
|
||||||
try {
|
try {
|
||||||
DnsRecordCodec.decodeAnswers("sdflkhfsdlkjdf.ee", ByteString.decodeHex(
|
DnsRecordCodec.INSTANCE.decodeAnswers("sdflkhfsdlkjdf.ee", ByteString.decodeHex("000081830001"
|
||||||
"0000818300010000000100000e7364666c6b686673646c6b6a64660265650000010001c01b00060001000007070038026e7303746c64c01b0a686f73746d61737465720d6565737469696e7465726e6574c01b5adb12c100000e10000003840012750000000e10"));
|
+ "0000000100000e7364666c6b686673646c6b6a64660265650000010001c01b00060001000007070038026e"
|
||||||
|
+ "7303746c64c01b0a686f73746d61737465720d6565737469696e7465726e6574c01b5adb12c100000e1000"
|
||||||
|
+ "0003840012750000000e10"));
|
||||||
fail();
|
fail();
|
||||||
} catch (UnknownHostException uhe) {
|
} catch (UnknownHostException uhe) {
|
||||||
assertThat(uhe.getMessage()).isEqualTo("sdflkhfsdlkjdf.ee: NXDOMAIN");
|
assertThat(uhe.getMessage()).isEqualTo("sdflkhfsdlkjdf.ee: NXDOMAIN");
|
||||||
|
@@ -724,7 +724,6 @@ class Cache internal constructor(
|
|||||||
fun key(url: HttpUrl): String = url.toString().encodeUtf8().md5().hex()
|
fun key(url: HttpUrl): String = url.toString().encodeUtf8().md5().hex()
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
@JvmStatic
|
|
||||||
internal fun readInt(source: BufferedSource): Int {
|
internal fun readInt(source: BufferedSource): Int {
|
||||||
try {
|
try {
|
||||||
val result = source.readDecimalLong()
|
val result = source.readDecimalLong()
|
||||||
|
@@ -1421,7 +1421,6 @@ class HttpUrl internal constructor(
|
|||||||
* Returns the index of the ':' in `input` that is after scheme characters. Returns -1 if
|
* Returns the index of the ':' in `input` that is after scheme characters. Returns -1 if
|
||||||
* `input` does not have a scheme that starts at `pos`.
|
* `input` does not have a scheme that starts at `pos`.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
|
||||||
private fun schemeDelimiterOffset(input: String, pos: Int, limit: Int): Int {
|
private fun schemeDelimiterOffset(input: String, pos: Int, limit: Int): Int {
|
||||||
if (limit - pos < 2) return -1
|
if (limit - pos < 2) return -1
|
||||||
|
|
||||||
@@ -1493,7 +1492,6 @@ class HttpUrl internal constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
|
||||||
private val HEX_DIGITS =
|
private val HEX_DIGITS =
|
||||||
charArrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')
|
charArrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')
|
||||||
internal const val USERNAME_ENCODE_SET = " \"':;<=>@[]^`{}|/\\?#"
|
internal const val USERNAME_ENCODE_SET = " \"':;<=>@[]^`{}|/\\?#"
|
||||||
|
@@ -25,9 +25,7 @@ import okhttp3.internal.connection.RealConnectionPool
|
|||||||
* packages.
|
* packages.
|
||||||
*/
|
*/
|
||||||
object Internal {
|
object Internal {
|
||||||
@JvmStatic
|
|
||||||
fun realConnectionPool(connectionPool: ConnectionPool): RealConnectionPool = connectionPool.delegate
|
fun realConnectionPool(connectionPool: ConnectionPool): RealConnectionPool = connectionPool.delegate
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun exchange(response: Response): Exchange? = response.exchange
|
fun exchange(response: Response): Exchange? = response.exchange
|
||||||
}
|
}
|
||||||
|
@@ -83,7 +83,7 @@ object Util {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic fun threadFactory(
|
fun threadFactory(
|
||||||
name: String,
|
name: String,
|
||||||
daemon: Boolean
|
daemon: Boolean
|
||||||
): ThreadFactory = ThreadFactory { runnable ->
|
): ThreadFactory = ThreadFactory { runnable ->
|
||||||
@@ -232,13 +232,11 @@ object Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true if [host] is not a host name and might be an IP address. */
|
/** Returns true if [host] is not a host name and might be an IP address. */
|
||||||
@JvmStatic
|
|
||||||
fun verifyAsIpAddress(host: String): Boolean {
|
fun verifyAsIpAddress(host: String): Boolean {
|
||||||
return VERIFY_AS_IP_ADDRESS.matches(host)
|
return VERIFY_AS_IP_ADDRESS.matches(host)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a [Locale.US] formatted [String]. */
|
/** Returns a [Locale.US] formatted [String]. */
|
||||||
@JvmStatic
|
|
||||||
fun format(format: String, vararg args: Any): String {
|
fun format(format: String, vararg args: Any): String {
|
||||||
return String.format(Locale.US, format, *args)
|
return String.format(Locale.US, format, *args)
|
||||||
}
|
}
|
||||||
|
@@ -981,7 +981,6 @@ class DiskLruCache internal constructor(
|
|||||||
* @param valueCount the number of values per cache entry. Must be positive.
|
* @param valueCount the number of values per cache entry. Must be positive.
|
||||||
* @param maxSize the maximum number of bytes this cache should use to store
|
* @param maxSize the maximum number of bytes this cache should use to store
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
|
||||||
fun create(
|
fun create(
|
||||||
fileSystem: FileSystem,
|
fileSystem: FileSystem,
|
||||||
directory: File,
|
directory: File,
|
||||||
|
@@ -309,7 +309,6 @@ class Relay private constructor(
|
|||||||
* close that when they're done. Otherwise a handle to [file] will be leaked.
|
* close that when they're done. Otherwise a handle to [file] will be leaked.
|
||||||
*/
|
*/
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
@JvmStatic
|
|
||||||
fun edit(
|
fun edit(
|
||||||
file: File,
|
file: File,
|
||||||
upstream: Source,
|
upstream: Source,
|
||||||
@@ -333,7 +332,6 @@ class Relay private constructor(
|
|||||||
* close that when they're done. Otherwise a handle to [file] will be leaked.
|
* close that when they're done. Otherwise a handle to [file] will be leaked.
|
||||||
*/
|
*/
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
@JvmStatic
|
|
||||||
fun read(file: File): Relay {
|
fun read(file: File): Relay {
|
||||||
val randomAccessFile = RandomAccessFile(file, "rw")
|
val randomAccessFile = RandomAccessFile(file, "rw")
|
||||||
val fileOperator = FileOperator(randomAccessFile.channel)
|
val fileOperator = FileOperator(randomAccessFile.channel)
|
||||||
|
@@ -700,7 +700,6 @@ class RealConnection(
|
|||||||
private const val NPE_THROW_WITH_NULL = "throw with null exception"
|
private const val NPE_THROW_WITH_NULL = "throw with null exception"
|
||||||
private const val MAX_TUNNEL_ATTEMPTS = 21
|
private const val MAX_TUNNEL_ATTEMPTS = 21
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun newTestConnection(
|
fun newTestConnection(
|
||||||
connectionPool: RealConnectionPool,
|
connectionPool: RealConnectionPool,
|
||||||
route: Route,
|
route: Route,
|
||||||
|
@@ -182,7 +182,6 @@ class RouteSelector(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/** Obtain a host string containing either an actual host name or a numeric IP address. */
|
/** Obtain a host string containing either an actual host name or a numeric IP address. */
|
||||||
@JvmStatic
|
|
||||||
val InetSocketAddress.socketHost: String get() {
|
val InetSocketAddress.socketHost: String get() {
|
||||||
// The InetSocketAddress was specified with a string (either a numeric IP or a host name). If
|
// The InetSocketAddress was specified with a string (either a numeric IP or a host name). If
|
||||||
// it is a name, all IPs for that name should be tried. If it is an IP address, only that IP
|
// it is a name, all IPs for that name should be tried. If it is an IP address, only that IP
|
||||||
|
@@ -19,8 +19,8 @@ import okhttp3.internal.Util.UTC
|
|||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.text.ParsePosition
|
import java.text.ParsePosition
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Best-effort parser for HTTP dates.
|
* Best-effort parser for HTTP dates.
|
||||||
@@ -69,7 +69,6 @@ object HttpDate {
|
|||||||
private val BROWSER_COMPATIBLE_DATE_FORMATS = arrayOfNulls<DateFormat>(BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS.size)
|
private val BROWSER_COMPATIBLE_DATE_FORMATS = arrayOfNulls<DateFormat>(BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS.size)
|
||||||
|
|
||||||
/** Returns the date for [value]. Returns null if the value couldn't be parsed. */
|
/** Returns the date for [value]. Returns null if the value couldn't be parsed. */
|
||||||
@JvmStatic
|
|
||||||
fun parse(value: String): Date? {
|
fun parse(value: String): Date? {
|
||||||
if (value.isEmpty()) {
|
if (value.isEmpty()) {
|
||||||
return null
|
return null
|
||||||
@@ -109,7 +108,6 @@ object HttpDate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the string for [value]. */
|
/** Returns the string for [value]. */
|
||||||
@JvmStatic
|
|
||||||
fun format(value: Date): String {
|
fun format(value: Date): String {
|
||||||
return STANDARD_DATE_FORMAT.get().format(value)
|
return STANDARD_DATE_FORMAT.get().format(value)
|
||||||
}
|
}
|
||||||
|
@@ -16,29 +16,24 @@
|
|||||||
package okhttp3.internal.http
|
package okhttp3.internal.http
|
||||||
|
|
||||||
object HttpMethod {
|
object HttpMethod {
|
||||||
@JvmStatic
|
|
||||||
fun invalidatesCache(method: String): Boolean = (method == "POST" ||
|
fun invalidatesCache(method: String): Boolean = (method == "POST" ||
|
||||||
method == "PATCH" ||
|
method == "PATCH" ||
|
||||||
method == "PUT" ||
|
method == "PUT" ||
|
||||||
method == "DELETE" ||
|
method == "DELETE" ||
|
||||||
method == "MOVE") // WebDAV
|
method == "MOVE") // WebDAV
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun requiresRequestBody(method: String): Boolean = (method == "POST" ||
|
fun requiresRequestBody(method: String): Boolean = (method == "POST" ||
|
||||||
method == "PUT" ||
|
method == "PUT" ||
|
||||||
method == "PATCH" ||
|
method == "PATCH" ||
|
||||||
method == "PROPPATCH" || // WebDAV
|
method == "PROPPATCH" || // WebDAV
|
||||||
method == "REPORT") // CalDAV/CardDAV (defined in WebDAV Versioning)
|
method == "REPORT") // CalDAV/CardDAV (defined in WebDAV Versioning)
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun permitsRequestBody(method: String): Boolean = !(method == "GET" || method == "HEAD")
|
fun permitsRequestBody(method: String): Boolean = !(method == "GET" || method == "HEAD")
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun redirectsWithBody(method: String): Boolean =
|
fun redirectsWithBody(method: String): Boolean =
|
||||||
// (WebDAV) redirects should also maintain the request body
|
// (WebDAV) redirects should also maintain the request body
|
||||||
method == "PROPFIND"
|
method == "PROPFIND"
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun redirectsToGet(method: String): Boolean =
|
fun redirectsToGet(method: String): Boolean =
|
||||||
// All requests but PROPFIND should redirect to a GET request.
|
// All requests but PROPFIND should redirect to a GET request.
|
||||||
method != "PROPFIND"
|
method != "PROPFIND"
|
||||||
|
@@ -15,10 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package okhttp3.internal.http
|
package okhttp3.internal.http
|
||||||
|
|
||||||
import java.net.HttpURLConnection
|
|
||||||
import java.net.Proxy
|
|
||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
|
import java.net.HttpURLConnection
|
||||||
|
import java.net.Proxy
|
||||||
|
|
||||||
object RequestLine {
|
object RequestLine {
|
||||||
|
|
||||||
@@ -27,7 +27,6 @@ object RequestLine {
|
|||||||
* [HttpURLConnection.getHeaderFields], so it needs to be set even if the transport is
|
* [HttpURLConnection.getHeaderFields], so it needs to be set even if the transport is
|
||||||
* HTTP/2.
|
* HTTP/2.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
|
||||||
fun get(request: Request, proxyType: Proxy.Type): String {
|
fun get(request: Request, proxyType: Proxy.Type): String {
|
||||||
val result = StringBuilder()
|
val result = StringBuilder()
|
||||||
result.append(request.method())
|
result.append(request.method())
|
||||||
@@ -47,7 +46,6 @@ object RequestLine {
|
|||||||
* Returns true if the request line should contain the full URL with host and port (like "GET
|
* Returns true if the request line should contain the full URL with host and port (like "GET
|
||||||
* http://android.com/foo HTTP/1.1") or only the path (like "GET /foo HTTP/1.1").
|
* http://android.com/foo HTTP/1.1") or only the path (like "GET /foo HTTP/1.1").
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
|
||||||
private fun includeAuthorityInRequestLine(request: Request, proxyType: Proxy.Type): Boolean {
|
private fun includeAuthorityInRequestLine(request: Request, proxyType: Proxy.Type): Boolean {
|
||||||
return !request.isHttps && proxyType == Proxy.Type.HTTP
|
return !request.isHttps && proxyType == Proxy.Type.HTTP
|
||||||
}
|
}
|
||||||
@@ -56,7 +54,6 @@ object RequestLine {
|
|||||||
* Returns the path to request, like the '/' in 'GET / HTTP/1.1'. Never empty, even if the request
|
* Returns the path to request, like the '/' in 'GET / HTTP/1.1'. Never empty, even if the request
|
||||||
* URL is. Includes the query component if it exists.
|
* URL is. Includes the query component if it exists.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
|
||||||
fun requestPath(url: HttpUrl): String {
|
fun requestPath(url: HttpUrl): String {
|
||||||
val path = url.encodedPath()
|
val path = url.encodedPath()
|
||||||
val query = url.encodedQuery()
|
val query = url.encodedQuery()
|
||||||
|
@@ -45,12 +45,10 @@ class StatusLine(
|
|||||||
const val HTTP_PERM_REDIRECT = 308
|
const val HTTP_PERM_REDIRECT = 308
|
||||||
const val HTTP_CONTINUE = 100
|
const val HTTP_CONTINUE = 100
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun get(response: Response): StatusLine {
|
fun get(response: Response): StatusLine {
|
||||||
return StatusLine(response.protocol(), response.code(), response.message())
|
return StatusLine(response.protocol(), response.code(), response.message())
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
fun parse(statusLine: String): StatusLine {
|
fun parse(statusLine: String): StatusLine {
|
||||||
// H T T P / 1 . 1 2 0 0 T e m p o r a r y R e d i r e c t
|
// H T T P / 1 . 1 2 0 0 T e m p o r a r y R e d i r e c t
|
||||||
|
@@ -105,7 +105,6 @@ object Http2 {
|
|||||||
* `<< 0x0000000f 12 HEADERS END_HEADERS|END_STREAM
|
* `<< 0x0000000f 12 HEADERS END_HEADERS|END_STREAM
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
|
||||||
fun frameLog(
|
fun frameLog(
|
||||||
inbound: Boolean,
|
inbound: Boolean,
|
||||||
streamId: Int,
|
streamId: Int,
|
||||||
@@ -125,7 +124,6 @@ object Http2 {
|
|||||||
* in binary.
|
* in binary.
|
||||||
*/
|
*/
|
||||||
// Visible for testing.
|
// Visible for testing.
|
||||||
@JvmStatic
|
|
||||||
fun formatFlags(type: Int, flags: Int): String {
|
fun formatFlags(type: Int, flags: Int): String {
|
||||||
if (flags == 0) return ""
|
if (flags == 0) return ""
|
||||||
when (type) {
|
when (type) {
|
||||||
|
@@ -106,7 +106,6 @@ class ConscryptPlatform private constructor() : Platform() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
|
||||||
fun buildIfSupported(): ConscryptPlatform? = try {
|
fun buildIfSupported(): ConscryptPlatform? = try {
|
||||||
// Trigger an early exception over a fatal error, prefer a RuntimeException over Error.
|
// Trigger an early exception over a fatal error, prefer a RuntimeException over Error.
|
||||||
Class.forName("org.conscrypt.Conscrypt\$Version")
|
Class.forName("org.conscrypt.Conscrypt\$Version")
|
||||||
@@ -119,7 +118,6 @@ class ConscryptPlatform private constructor() : Platform() {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic @JvmOverloads
|
|
||||||
fun atLeastVersion(major: Int, minor: Int = 0, patch: Int = 0): Boolean {
|
fun atLeastVersion(major: Int, minor: Int = 0, patch: Int = 0): Boolean {
|
||||||
val conscryptVersion = Conscrypt.version()
|
val conscryptVersion = Conscrypt.version()
|
||||||
|
|
||||||
|
@@ -123,7 +123,6 @@ class Jdk8WithJettyBootPlatform(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
|
||||||
fun buildIfSupported(): Platform? {
|
fun buildIfSupported(): Platform? {
|
||||||
val jvmVersion = System.getProperty("java.specification.version", "unknown")
|
val jvmVersion = System.getProperty("java.specification.version", "unknown")
|
||||||
try {
|
try {
|
||||||
|
@@ -71,7 +71,6 @@ class Jdk9Platform(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
|
||||||
fun buildIfSupported(): Jdk9Platform? =
|
fun buildIfSupported(): Jdk9Platform? =
|
||||||
try {
|
try {
|
||||||
// Find JDK 9 methods
|
// Find JDK 9 methods
|
||||||
|
@@ -193,7 +193,6 @@ open class Platform {
|
|||||||
fun alpnProtocolNames(protocols: List<Protocol>) =
|
fun alpnProtocolNames(protocols: List<Protocol>) =
|
||||||
protocols.filter { it != Protocol.HTTP_1_0 }.map { it.toString() }
|
protocols.filter { it != Protocol.HTTP_1_0 }.map { it.toString() }
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
val isConscryptPreferred: Boolean
|
val isConscryptPreferred: Boolean
|
||||||
get() {
|
get() {
|
||||||
val preferredProvider = Security.getProviders()[0].name
|
val preferredProvider = Security.getProviders()[0].name
|
||||||
@@ -201,7 +200,6 @@ open class Platform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Attempt to match the host runtime to a capable Platform implementation. */
|
/** Attempt to match the host runtime to a capable Platform implementation. */
|
||||||
@JvmStatic
|
|
||||||
private fun findPlatform(): Platform {
|
private fun findPlatform(): Platform {
|
||||||
val android = AndroidPlatform.buildIfSupported()
|
val android = AndroidPlatform.buildIfSupported()
|
||||||
|
|
||||||
@@ -233,7 +231,6 @@ open class Platform {
|
|||||||
* Returns the concatenation of 8-bit, length prefixed protocol names.
|
* Returns the concatenation of 8-bit, length prefixed protocol names.
|
||||||
* http://tools.ietf.org/html/draft-agl-tls-nextprotoneg-04#page-4
|
* http://tools.ietf.org/html/draft-agl-tls-nextprotoneg-04#page-4
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
|
||||||
fun concatLengthPrefixed(protocols: List<Protocol>): ByteArray {
|
fun concatLengthPrefixed(protocols: List<Protocol>): ByteArray {
|
||||||
val result = Buffer()
|
val result = Buffer()
|
||||||
for (protocol in alpnProtocolNames(protocols)) {
|
for (protocol in alpnProtocolNames(protocols)) {
|
||||||
@@ -243,7 +240,6 @@ open class Platform {
|
|||||||
return result.readByteArray()
|
return result.readByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun <T> readFieldOrNull(instance: Any, fieldType: Class<T>, fieldName: String): T? {
|
fun <T> readFieldOrNull(instance: Any, fieldType: Class<T>, fieldName: String): T? {
|
||||||
var c: Class<*> = instance.javaClass
|
var c: Class<*> = instance.javaClass
|
||||||
while (c != Any::class.java) {
|
while (c != Any::class.java) {
|
||||||
|
@@ -38,12 +38,10 @@ abstract class CertificateChainCleaner {
|
|||||||
abstract fun clean(chain: List<Certificate>, hostname: String): List<Certificate>
|
abstract fun clean(chain: List<Certificate>, hostname: String): List<Certificate>
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
|
||||||
fun get(trustManager: X509TrustManager): CertificateChainCleaner {
|
fun get(trustManager: X509TrustManager): CertificateChainCleaner {
|
||||||
return Platform.get().buildCertificateChainCleaner(trustManager)
|
return Platform.get().buildCertificateChainCleaner(trustManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun get(vararg caCerts: X509Certificate): CertificateChainCleaner {
|
fun get(vararg caCerts: X509Certificate): CertificateChainCleaner {
|
||||||
return BasicCertificateChainCleaner(BasicTrustRootIndex(*caCerts))
|
return BasicCertificateChainCleaner(BasicTrustRootIndex(*caCerts))
|
||||||
}
|
}
|
||||||
|
@@ -95,7 +95,6 @@ object WebSocketProtocol {
|
|||||||
/** Used when an empty close frame was received (i.e., without a status code). */
|
/** Used when an empty close frame was received (i.e., without a status code). */
|
||||||
internal const val CLOSE_NO_STATUS_CODE = 1005
|
internal const val CLOSE_NO_STATUS_CODE = 1005
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun toggleMask(cursor: Buffer.UnsafeCursor, key: ByteArray) {
|
fun toggleMask(cursor: Buffer.UnsafeCursor, key: ByteArray) {
|
||||||
var keyIndex = 0
|
var keyIndex = 0
|
||||||
val keyLength = key.size
|
val keyLength = key.size
|
||||||
@@ -120,7 +119,6 @@ object WebSocketProtocol {
|
|||||||
} while (cursor.next() != -1)
|
} while (cursor.next() != -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun closeCodeExceptionMessage(code: Int): String? {
|
fun closeCodeExceptionMessage(code: Int): String? {
|
||||||
return if (code < 1000 || code >= 5000) {
|
return if (code < 1000 || code >= 5000) {
|
||||||
"Code must be in range [1000,5000): $code"
|
"Code must be in range [1000,5000): $code"
|
||||||
@@ -131,7 +129,6 @@ object WebSocketProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun validateCloseCode(code: Int) {
|
fun validateCloseCode(code: Int) {
|
||||||
val message = closeCodeExceptionMessage(code)
|
val message = closeCodeExceptionMessage(code)
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
@@ -139,7 +136,6 @@ object WebSocketProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun acceptHeader(key: String): String {
|
fun acceptHeader(key: String): String {
|
||||||
return (key + ACCEPT_MAGIC).encodeUtf8().sha1().base64()
|
return (key + ACCEPT_MAGIC).encodeUtf8().sha1().base64()
|
||||||
}
|
}
|
||||||
|
@@ -37,22 +37,22 @@ public final class CertificateChainCleanerTest {
|
|||||||
HeldCertificate rootB = new HeldCertificate.Builder()
|
HeldCertificate rootB = new HeldCertificate.Builder()
|
||||||
.serialNumber(2L)
|
.serialNumber(2L)
|
||||||
.build();
|
.build();
|
||||||
assertThat(CertificateChainCleaner.get(rootB.certificate(), rootA.certificate())).isEqualTo(
|
assertThat(CertificateChainCleaner.Companion.get(rootB.certificate(), rootA.certificate()))
|
||||||
CertificateChainCleaner.get(rootA.certificate(), rootB.certificate()));
|
.isEqualTo(CertificateChainCleaner.Companion.get(rootA.certificate(), rootB.certificate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void equalsFromTrustManager() {
|
@Test public void equalsFromTrustManager() {
|
||||||
HandshakeCertificates handshakeCertificates = new HandshakeCertificates.Builder().build();
|
HandshakeCertificates handshakeCertificates = new HandshakeCertificates.Builder().build();
|
||||||
X509TrustManager x509TrustManager = handshakeCertificates.trustManager();
|
X509TrustManager x509TrustManager = handshakeCertificates.trustManager();
|
||||||
assertThat(CertificateChainCleaner.get(x509TrustManager)).isEqualTo(
|
assertThat(CertificateChainCleaner.Companion.get(x509TrustManager)).isEqualTo(
|
||||||
CertificateChainCleaner.get(x509TrustManager));
|
CertificateChainCleaner.Companion.get(x509TrustManager));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void normalizeSingleSelfSignedCertificate() throws Exception {
|
@Test public void normalizeSingleSelfSignedCertificate() throws Exception {
|
||||||
HeldCertificate root = new HeldCertificate.Builder()
|
HeldCertificate root = new HeldCertificate.Builder()
|
||||||
.serialNumber(1L)
|
.serialNumber(1L)
|
||||||
.build();
|
.build();
|
||||||
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate());
|
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
|
||||||
assertThat(cleaner.clean(list(root), "hostname")).isEqualTo(list(root));
|
assertThat(cleaner.clean(list(root), "hostname")).isEqualTo(list(root));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public final class CertificateChainCleanerTest {
|
|||||||
HeldCertificate root = new HeldCertificate.Builder()
|
HeldCertificate root = new HeldCertificate.Builder()
|
||||||
.serialNumber(1L)
|
.serialNumber(1L)
|
||||||
.build();
|
.build();
|
||||||
CertificateChainCleaner cleaner = CertificateChainCleaner.get();
|
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cleaner.clean(list(root), "hostname");
|
cleaner.clean(list(root), "hostname");
|
||||||
@@ -82,7 +82,7 @@ public final class CertificateChainCleanerTest {
|
|||||||
.signedBy(certA)
|
.signedBy(certA)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate());
|
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
|
||||||
assertThat(cleaner.clean(list(certB, certA, root), "hostname")).isEqualTo(
|
assertThat(cleaner.clean(list(certB, certA, root), "hostname")).isEqualTo(
|
||||||
list(certB, certA, root));
|
list(certB, certA, root));
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ public final class CertificateChainCleanerTest {
|
|||||||
.signedBy(certA)
|
.signedBy(certA)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate());
|
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
|
||||||
// Root is added!
|
// Root is added!
|
||||||
assertThat(cleaner.clean(list(certB, certA), "hostname")).isEqualTo(
|
assertThat(cleaner.clean(list(certB, certA), "hostname")).isEqualTo(
|
||||||
list(certB, certA, root));
|
list(certB, certA, root));
|
||||||
@@ -123,7 +123,7 @@ public final class CertificateChainCleanerTest {
|
|||||||
.signedBy(certB)
|
.signedBy(certB)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate());
|
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
|
||||||
assertThat(cleaner.clean(list(certC, certA, root, certB), "hostname")).isEqualTo(
|
assertThat(cleaner.clean(list(certC, certA, root, certB), "hostname")).isEqualTo(
|
||||||
list(certC, certB, certA, root));
|
list(certC, certB, certA, root));
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ public final class CertificateChainCleanerTest {
|
|||||||
.signedBy(certB)
|
.signedBy(certB)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate());
|
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
|
||||||
assertThat(cleaner.clean(list(certC, certA, certB), "hostname")).isEqualTo(
|
assertThat(cleaner.clean(list(certC, certA, certB), "hostname")).isEqualTo(
|
||||||
list(certC, certB, certA, root));
|
list(certC, certB, certA, root));
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ public final class CertificateChainCleanerTest {
|
|||||||
.serialNumber(4L)
|
.serialNumber(4L)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate());
|
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
|
||||||
assertThat(cleaner.clean(list(certB, certUnnecessary, certA, root), "hostname")).isEqualTo(
|
assertThat(cleaner.clean(list(certB, certUnnecessary, certA, root), "hostname")).isEqualTo(
|
||||||
list(certB, certA, root));
|
list(certB, certA, root));
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,7 @@ public final class CertificateChainCleanerTest {
|
|||||||
.signedBy(certA)
|
.signedBy(certA)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
CertificateChainCleaner cleaner = CertificateChainCleaner.get(
|
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(
|
||||||
selfSigned.certificate(), trusted.certificate());
|
selfSigned.certificate(), trusted.certificate());
|
||||||
assertThat(cleaner.clean(list(certB, certA), "hostname")).isEqualTo(
|
assertThat(cleaner.clean(list(certB, certA), "hostname")).isEqualTo(
|
||||||
list(certB, certA, trusted, selfSigned));
|
list(certB, certA, trusted, selfSigned));
|
||||||
@@ -215,7 +215,7 @@ public final class CertificateChainCleanerTest {
|
|||||||
.serialNumber(4L)
|
.serialNumber(4L)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
CertificateChainCleaner cleaner = CertificateChainCleaner.get(trusted.certificate());
|
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(trusted.certificate());
|
||||||
assertThat(cleaner.clean(list(certificate, intermediateCa), "hostname")).isEqualTo(
|
assertThat(cleaner.clean(list(certificate, intermediateCa), "hostname")).isEqualTo(
|
||||||
list(certificate, intermediateCa, trusted));
|
list(certificate, intermediateCa, trusted));
|
||||||
assertThat(cleaner.clean(list(certificate, intermediateCa, trusted), "hostname")).isEqualTo(
|
assertThat(cleaner.clean(list(certificate, intermediateCa, trusted), "hostname")).isEqualTo(
|
||||||
@@ -230,7 +230,7 @@ public final class CertificateChainCleanerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
X509Certificate root = heldCertificates.get(heldCertificates.size() - 1).certificate();
|
X509Certificate root = heldCertificates.get(heldCertificates.size() - 1).certificate();
|
||||||
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root);
|
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root);
|
||||||
assertThat(cleaner.clean(certificates, "hostname")).isEqualTo(certificates);
|
assertThat(cleaner.clean(certificates, "hostname")).isEqualTo(certificates);
|
||||||
assertThat(cleaner.clean(certificates.subList(0, 9), "hostname")).isEqualTo(
|
assertThat(cleaner.clean(certificates.subList(0, 9), "hostname")).isEqualTo(
|
||||||
certificates);
|
certificates);
|
||||||
@@ -244,7 +244,7 @@ public final class CertificateChainCleanerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
X509Certificate root = heldCertificates.get(heldCertificates.size() - 1).certificate();
|
X509Certificate root = heldCertificates.get(heldCertificates.size() - 1).certificate();
|
||||||
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root);
|
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root);
|
||||||
try {
|
try {
|
||||||
cleaner.clean(certificates, "hostname");
|
cleaner.clean(certificates, "hostname");
|
||||||
fail();
|
fail();
|
||||||
|
@@ -89,7 +89,7 @@ public final class EventListenerTest {
|
|||||||
.eventListener(listener)
|
.eventListener(listener)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
listener.forbidLock(Internal.realConnectionPool(client.connectionPool()));
|
listener.forbidLock(Internal.INSTANCE.realConnectionPool(client.connectionPool()));
|
||||||
listener.forbidLock(client.dispatcher());
|
listener.forbidLock(client.dispatcher());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -58,7 +58,7 @@ public final class SocksProxy {
|
|||||||
private static final Logger logger = Logger.getLogger(SocksProxy.class.getName());
|
private static final Logger logger = Logger.getLogger(SocksProxy.class.getName());
|
||||||
|
|
||||||
private final ExecutorService executor = Executors.newCachedThreadPool(
|
private final ExecutorService executor = Executors.newCachedThreadPool(
|
||||||
Util.threadFactory("SocksProxy", false));
|
Util.INSTANCE.threadFactory("SocksProxy", false));
|
||||||
|
|
||||||
private ServerSocket serverSocket;
|
private ServerSocket serverSocket;
|
||||||
private AtomicInteger connectionCount = new AtomicInteger();
|
private AtomicInteger connectionCount = new AtomicInteger();
|
||||||
|
@@ -232,7 +232,7 @@ class UrlComponentEncodingTester {
|
|||||||
String urlString = component.urlString(encoded);
|
String urlString = component.urlString(encoded);
|
||||||
HttpUrl url = HttpUrl.get(urlString);
|
HttpUrl url = HttpUrl.get(urlString);
|
||||||
if (!component.encodedValue(url).equals(encoded)) {
|
if (!component.encodedValue(url).equals(encoded)) {
|
||||||
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +243,7 @@ class UrlComponentEncodingTester {
|
|||||||
HttpUrl url = builder.build();
|
HttpUrl url = builder.build();
|
||||||
String actual = component.get(url);
|
String actual = component.get(url);
|
||||||
if (!expected.equals(actual)) {
|
if (!expected.equals(actual)) {
|
||||||
fail(Util.format("Roundtrip %s %#x %s", component, codePoint, url));
|
fail(Util.INSTANCE.format("Roundtrip %s %#x %s", component, codePoint, url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +256,7 @@ class UrlComponentEncodingTester {
|
|||||||
|
|
||||||
String s = component.encodedValue(url);
|
String s = component.encodedValue(url);
|
||||||
if (!s.equals(encoded)) {
|
if (!s.equals(encoded)) {
|
||||||
fail(Util.format("Encoding %s %#02x using %s", component, codePoint, encoding));
|
fail(Util.INSTANCE.format("Encoding %s %#02x using %s", component, codePoint, encoding));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +265,7 @@ class UrlComponentEncodingTester {
|
|||||||
HttpUrl httpUrl = HttpUrl.get(component.urlString(encoded));
|
HttpUrl httpUrl = HttpUrl.get(component.urlString(encoded));
|
||||||
URL javaNetUrl = httpUrl.url();
|
URL javaNetUrl = httpUrl.url();
|
||||||
if (!javaNetUrl.toString().equals(javaNetUrl.toString())) {
|
if (!javaNetUrl.toString().equals(javaNetUrl.toString())) {
|
||||||
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ class UrlComponentEncodingTester {
|
|||||||
HttpUrl httpUrl = HttpUrl.get(component.urlString(encoded));
|
HttpUrl httpUrl = HttpUrl.get(component.urlString(encoded));
|
||||||
HttpUrl toAndFromJavaNetUrl = HttpUrl.get(httpUrl.url());
|
HttpUrl toAndFromJavaNetUrl = HttpUrl.get(httpUrl.url());
|
||||||
if (!toAndFromJavaNetUrl.equals(httpUrl)) {
|
if (!toAndFromJavaNetUrl.equals(httpUrl)) {
|
||||||
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,18 +288,18 @@ class UrlComponentEncodingTester {
|
|||||||
if (uriEscaped) {
|
if (uriEscaped) {
|
||||||
// The URI has more escaping than the HttpURL. Check that the decoded values still match.
|
// The URI has more escaping than the HttpURL. Check that the decoded values still match.
|
||||||
if (uri.toString().equals(httpUrl.toString())) {
|
if (uri.toString().equals(httpUrl.toString())) {
|
||||||
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
||||||
}
|
}
|
||||||
if (!component.get(toAndFromUri).equals(string)) {
|
if (!component.get(toAndFromUri).equals(string)) {
|
||||||
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Check that the URI and HttpURL have the exact same escaping.
|
// Check that the URI and HttpURL have the exact same escaping.
|
||||||
if (!toAndFromUri.equals(httpUrl)) {
|
if (!toAndFromUri.equals(httpUrl)) {
|
||||||
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
||||||
}
|
}
|
||||||
if (!uri.toString().equals(httpUrl.toString())) {
|
if (!uri.toString().equals(httpUrl.toString())) {
|
||||||
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -316,7 +316,7 @@ class UrlComponentEncodingTester {
|
|||||||
ByteString utf8 = ByteString.encodeUtf8(IDENTITY.encode(codePoint));
|
ByteString utf8 = ByteString.encodeUtf8(IDENTITY.encode(codePoint));
|
||||||
Buffer percentEncoded = new Buffer();
|
Buffer percentEncoded = new Buffer();
|
||||||
for (int i = 0; i < utf8.size(); i++) {
|
for (int i = 0; i < utf8.size(); i++) {
|
||||||
percentEncoded.writeUtf8(Util.format("%%%02X", utf8.getByte(i) & 0xff));
|
percentEncoded.writeUtf8(Util.INSTANCE.format("%%%02X", utf8.getByte(i) & 0xff));
|
||||||
}
|
}
|
||||||
return percentEncoded.readUtf8();
|
return percentEncoded.readUtf8();
|
||||||
}
|
}
|
||||||
|
@@ -82,7 +82,7 @@ public final class WebPlatformUrlTestData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public String toString() {
|
@Override public String toString() {
|
||||||
return Util.format("Parsing: <%s> against <%s>", input, base);
|
return Util.INSTANCE.format("Parsing: <%s> against <%s>", input, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<WebPlatformUrlTestData> load(BufferedSource source) throws IOException {
|
public static List<WebPlatformUrlTestData> load(BufferedSource source) throws IOException {
|
||||||
|
@@ -662,7 +662,7 @@ public final class DiskLruCacheTest {
|
|||||||
|
|
||||||
@Test public void constructorDoesNotAllowZeroCacheSize() throws Exception {
|
@Test public void constructorDoesNotAllowZeroCacheSize() throws Exception {
|
||||||
try {
|
try {
|
||||||
DiskLruCache.create(fileSystem, cacheDir, appVersion, 2, 0);
|
DiskLruCache.Companion.create(fileSystem, cacheDir, appVersion, 2, 0);
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (IllegalArgumentException expected) {
|
||||||
}
|
}
|
||||||
@@ -670,7 +670,7 @@ public final class DiskLruCacheTest {
|
|||||||
|
|
||||||
@Test public void constructorDoesNotAllowZeroValuesPerEntry() throws Exception {
|
@Test public void constructorDoesNotAllowZeroValuesPerEntry() throws Exception {
|
||||||
try {
|
try {
|
||||||
DiskLruCache.create(fileSystem, cacheDir, appVersion, 0, 10);
|
DiskLruCache.Companion.create(fileSystem, cacheDir, appVersion, 0, 10);
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (IllegalArgumentException expected) {
|
||||||
}
|
}
|
||||||
@@ -978,7 +978,7 @@ public final class DiskLruCacheTest {
|
|||||||
@Test public void openCreatesDirectoryIfNecessary() throws Exception {
|
@Test public void openCreatesDirectoryIfNecessary() throws Exception {
|
||||||
cache.close();
|
cache.close();
|
||||||
File dir = tempDir.newFolder("testOpenCreatesDirectoryIfNecessary");
|
File dir = tempDir.newFolder("testOpenCreatesDirectoryIfNecessary");
|
||||||
cache = DiskLruCache.create(fileSystem, dir, appVersion, 2, Integer.MAX_VALUE);
|
cache = DiskLruCache.Companion.create(fileSystem, dir, appVersion, 2, Integer.MAX_VALUE);
|
||||||
set("a", "a", "a");
|
set("a", "a", "a");
|
||||||
assertThat(fileSystem.exists(new File(dir, "a.0"))).isTrue();
|
assertThat(fileSystem.exists(new File(dir, "a.0"))).isTrue();
|
||||||
assertThat(fileSystem.exists(new File(dir, "a.1"))).isTrue();
|
assertThat(fileSystem.exists(new File(dir, "a.1"))).isTrue();
|
||||||
|
@@ -56,7 +56,7 @@ public final class RelayTest {
|
|||||||
Buffer upstream = new Buffer();
|
Buffer upstream = new Buffer();
|
||||||
upstream.writeUtf8("abcdefghijklm");
|
upstream.writeUtf8("abcdefghijklm");
|
||||||
|
|
||||||
Relay relay = Relay.edit(file, upstream, metadata, 1024);
|
Relay relay = Relay.Companion.edit(file, upstream, metadata, 1024);
|
||||||
Source source = relay.newSource();
|
Source source = relay.newSource();
|
||||||
Buffer sourceBuffer = new Buffer();
|
Buffer sourceBuffer = new Buffer();
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ public final class RelayTest {
|
|||||||
Buffer upstream = new Buffer();
|
Buffer upstream = new Buffer();
|
||||||
upstream.writeUtf8("abcdefghijklm");
|
upstream.writeUtf8("abcdefghijklm");
|
||||||
|
|
||||||
Relay relay = Relay.edit(file, upstream, metadata, 1024);
|
Relay relay = Relay.Companion.edit(file, upstream, metadata, 1024);
|
||||||
BufferedSource source1 = Okio.buffer(relay.newSource());
|
BufferedSource source1 = Okio.buffer(relay.newSource());
|
||||||
BufferedSource source2 = Okio.buffer(relay.newSource());
|
BufferedSource source2 = Okio.buffer(relay.newSource());
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ public final class RelayTest {
|
|||||||
Buffer upstream = new Buffer();
|
Buffer upstream = new Buffer();
|
||||||
upstream.writeUtf8("abcdefghij");
|
upstream.writeUtf8("abcdefghij");
|
||||||
|
|
||||||
Relay relay = Relay.edit(file, upstream, metadata, 5);
|
Relay relay = Relay.Companion.edit(file, upstream, metadata, 5);
|
||||||
BufferedSource source1 = Okio.buffer(relay.newSource());
|
BufferedSource source1 = Okio.buffer(relay.newSource());
|
||||||
BufferedSource source2 = Okio.buffer(relay.newSource());
|
BufferedSource source2 = Okio.buffer(relay.newSource());
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ public final class RelayTest {
|
|||||||
Buffer upstream = new Buffer();
|
Buffer upstream = new Buffer();
|
||||||
upstream.writeUtf8("abcdefghijklmnopqrst");
|
upstream.writeUtf8("abcdefghijklmnopqrst");
|
||||||
|
|
||||||
Relay relay = Relay.edit(file, upstream, metadata, 5);
|
Relay relay = Relay.Companion.edit(file, upstream, metadata, 5);
|
||||||
BufferedSource source1 = Okio.buffer(relay.newSource());
|
BufferedSource source1 = Okio.buffer(relay.newSource());
|
||||||
BufferedSource source2 = Okio.buffer(relay.newSource());
|
BufferedSource source2 = Okio.buffer(relay.newSource());
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ public final class RelayTest {
|
|||||||
Buffer upstream = new Buffer();
|
Buffer upstream = new Buffer();
|
||||||
upstream.writeUtf8("abcdefghij");
|
upstream.writeUtf8("abcdefghij");
|
||||||
|
|
||||||
Relay relay1 = Relay.edit(file, upstream, metadata, 5);
|
Relay relay1 = Relay.Companion.edit(file, upstream, metadata, 5);
|
||||||
BufferedSource source1 = Okio.buffer(relay1.newSource());
|
BufferedSource source1 = Okio.buffer(relay1.newSource());
|
||||||
assertThat(source1.readUtf8(10)).isEqualTo("abcdefghij");
|
assertThat(source1.readUtf8(10)).isEqualTo("abcdefghij");
|
||||||
assertThat(source1.exhausted()).isTrue();
|
assertThat(source1.exhausted()).isTrue();
|
||||||
@@ -147,7 +147,7 @@ public final class RelayTest {
|
|||||||
// Since relay1 is closed, new sources cannot be created.
|
// Since relay1 is closed, new sources cannot be created.
|
||||||
assertThat(relay1.newSource()).isNull();
|
assertThat(relay1.newSource()).isNull();
|
||||||
|
|
||||||
Relay relay2 = Relay.read(file);
|
Relay relay2 = Relay.Companion.read(file);
|
||||||
assertThat(relay2.metadata()).isEqualTo(metadata);
|
assertThat(relay2.metadata()).isEqualTo(metadata);
|
||||||
BufferedSource source2 = Okio.buffer(relay2.newSource());
|
BufferedSource source2 = Okio.buffer(relay2.newSource());
|
||||||
assertThat(source2.readUtf8(10)).isEqualTo("abcdefghij");
|
assertThat(source2.readUtf8(10)).isEqualTo("abcdefghij");
|
||||||
@@ -165,14 +165,14 @@ public final class RelayTest {
|
|||||||
Buffer upstream = new Buffer();
|
Buffer upstream = new Buffer();
|
||||||
upstream.writeUtf8("abcdefghij");
|
upstream.writeUtf8("abcdefghij");
|
||||||
|
|
||||||
Relay relay1 = Relay.edit(file, upstream, metadata, 5);
|
Relay relay1 = Relay.Companion.edit(file, upstream, metadata, 5);
|
||||||
BufferedSource source1 = Okio.buffer(relay1.newSource());
|
BufferedSource source1 = Okio.buffer(relay1.newSource());
|
||||||
assertThat(source1.readUtf8(10)).isEqualTo("abcdefghij");
|
assertThat(source1.readUtf8(10)).isEqualTo("abcdefghij");
|
||||||
source1.close(); // Not exhausted!
|
source1.close(); // Not exhausted!
|
||||||
assertThat(relay1.isClosed()).isTrue();
|
assertThat(relay1.isClosed()).isTrue();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Relay.read(file);
|
Relay.Companion.read(file);
|
||||||
fail();
|
fail();
|
||||||
} catch (IOException expected) {
|
} catch (IOException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("unreadable cache file");
|
assertThat(expected.getMessage()).isEqualTo("unreadable cache file");
|
||||||
@@ -185,7 +185,7 @@ public final class RelayTest {
|
|||||||
Buffer upstream = new Buffer();
|
Buffer upstream = new Buffer();
|
||||||
upstream.writeUtf8("abcde");
|
upstream.writeUtf8("abcde");
|
||||||
|
|
||||||
Relay relay = Relay.edit(file, upstream, metadata, 1024);
|
Relay relay = Relay.Companion.edit(file, upstream, metadata, 1024);
|
||||||
Source source1 = relay.newSource();
|
Source source1 = relay.newSource();
|
||||||
Source source2 = relay.newSource();
|
Source source2 = relay.newSource();
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ public final class RelayTest {
|
|||||||
Pipe pipe = new Pipe(1024);
|
Pipe pipe = new Pipe(1024);
|
||||||
BufferedSink sink = Okio.buffer(pipe.sink());
|
BufferedSink sink = Okio.buffer(pipe.sink());
|
||||||
|
|
||||||
Relay relay = Relay.edit(file, pipe.source(), metadata, 5);
|
Relay relay = Relay.Companion.edit(file, pipe.source(), metadata, 5);
|
||||||
|
|
||||||
Future<ByteString> future1 = executor.submit(sourceReader(relay.newSource()));
|
Future<ByteString> future1 = executor.submit(sourceReader(relay.newSource()));
|
||||||
Future<ByteString> future2 = executor.submit(sourceReader(relay.newSource()));
|
Future<ByteString> future2 = executor.submit(sourceReader(relay.newSource()));
|
||||||
|
@@ -34,7 +34,6 @@ import okhttp3.internal.RecordingOkAuthenticator;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static okhttp3.TestUtil.awaitGarbageCollection;
|
import static okhttp3.TestUtil.awaitGarbageCollection;
|
||||||
import static okhttp3.internal.connection.RealConnection.newTestConnection;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public final class ConnectionPoolTest {
|
public final class ConnectionPoolTest {
|
||||||
@@ -79,7 +78,7 @@ public final class ConnectionPoolTest {
|
|||||||
|
|
||||||
@Test public void inUseConnectionsNotEvicted() throws Exception {
|
@Test public void inUseConnectionsNotEvicted() throws Exception {
|
||||||
ConnectionPool poolApi = new ConnectionPool(Integer.MAX_VALUE, 100L, TimeUnit.NANOSECONDS);
|
ConnectionPool poolApi = new ConnectionPool(Integer.MAX_VALUE, 100L, TimeUnit.NANOSECONDS);
|
||||||
RealConnectionPool pool = Internal.realConnectionPool(poolApi);
|
RealConnectionPool pool = Internal.INSTANCE.realConnectionPool(poolApi);
|
||||||
pool.setCleanupRunning(true); // Prevent the cleanup runnable from being started.
|
pool.setCleanupRunning(true); // Prevent the cleanup runnable from being started.
|
||||||
|
|
||||||
RealConnection c1 = newConnection(pool, routeA1, 50L);
|
RealConnection c1 = newConnection(pool, routeA1, 50L);
|
||||||
@@ -167,7 +166,7 @@ public final class ConnectionPoolTest {
|
|||||||
|
|
||||||
@Test public void leakedAllocation() throws Exception {
|
@Test public void leakedAllocation() throws Exception {
|
||||||
ConnectionPool poolApi = new ConnectionPool(Integer.MAX_VALUE, 100L, TimeUnit.NANOSECONDS);
|
ConnectionPool poolApi = new ConnectionPool(Integer.MAX_VALUE, 100L, TimeUnit.NANOSECONDS);
|
||||||
RealConnectionPool pool = Internal.realConnectionPool(poolApi);
|
RealConnectionPool pool = Internal.INSTANCE.realConnectionPool(poolApi);
|
||||||
pool.setCleanupRunning(true); // Prevent the cleanup runnable from being started.
|
pool.setCleanupRunning(true); // Prevent the cleanup runnable from being started.
|
||||||
|
|
||||||
RealConnection c1 = newConnection(pool, routeA1, 0L);
|
RealConnection c1 = newConnection(pool, routeA1, 0L);
|
||||||
@@ -183,7 +182,7 @@ public final class ConnectionPoolTest {
|
|||||||
|
|
||||||
/** Use a helper method so there's no hidden reference remaining on the stack. */
|
/** Use a helper method so there's no hidden reference remaining on the stack. */
|
||||||
private void allocateAndLeakAllocation(ConnectionPool pool, RealConnection connection) {
|
private void allocateAndLeakAllocation(ConnectionPool pool, RealConnection connection) {
|
||||||
synchronized (Internal.realConnectionPool(pool)) {
|
synchronized (Internal.INSTANCE.realConnectionPool(pool)) {
|
||||||
OkHttpClient client = new OkHttpClient.Builder()
|
OkHttpClient client = new OkHttpClient.Builder()
|
||||||
.connectionPool(pool)
|
.connectionPool(pool)
|
||||||
.build();
|
.build();
|
||||||
@@ -195,7 +194,8 @@ public final class ConnectionPoolTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private RealConnection newConnection(RealConnectionPool pool, Route route, long idleAtNanos) {
|
private RealConnection newConnection(RealConnectionPool pool, Route route, long idleAtNanos) {
|
||||||
RealConnection result = newTestConnection(pool, route, new Socket(), idleAtNanos);
|
RealConnection result = RealConnection.Companion.newTestConnection(
|
||||||
|
pool, route, new Socket(), idleAtNanos);
|
||||||
synchronized (pool) {
|
synchronized (pool) {
|
||||||
pool.put(result);
|
pool.put(result);
|
||||||
}
|
}
|
||||||
|
@@ -422,19 +422,19 @@ public final class RouteSelectorTest {
|
|||||||
@Test public void getHostString() throws Exception {
|
@Test public void getHostString() throws Exception {
|
||||||
// Name proxy specification.
|
// Name proxy specification.
|
||||||
InetSocketAddress socketAddress = InetSocketAddress.createUnresolved("host", 1234);
|
InetSocketAddress socketAddress = InetSocketAddress.createUnresolved("host", 1234);
|
||||||
assertThat(RouteSelector.getSocketHost(socketAddress)).isEqualTo("host");
|
assertThat(RouteSelector.Companion.getSocketHost(socketAddress)).isEqualTo("host");
|
||||||
socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 1234);
|
socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 1234);
|
||||||
assertThat(RouteSelector.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
|
assertThat(RouteSelector.Companion.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
|
||||||
|
|
||||||
// InetAddress proxy specification.
|
// InetAddress proxy specification.
|
||||||
socketAddress = new InetSocketAddress(InetAddress.getByName("localhost"), 1234);
|
socketAddress = new InetSocketAddress(InetAddress.getByName("localhost"), 1234);
|
||||||
assertThat(RouteSelector.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
|
assertThat(RouteSelector.Companion.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
|
||||||
socketAddress = new InetSocketAddress(
|
socketAddress = new InetSocketAddress(
|
||||||
InetAddress.getByAddress(new byte[] {127, 0, 0, 1}), 1234);
|
InetAddress.getByAddress(new byte[] {127, 0, 0, 1}), 1234);
|
||||||
assertThat(RouteSelector.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
|
assertThat(RouteSelector.Companion.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
|
||||||
socketAddress = new InetSocketAddress(
|
socketAddress = new InetSocketAddress(
|
||||||
InetAddress.getByAddress("foobar", new byte[] {127, 0, 0, 1}), 1234);
|
InetAddress.getByAddress("foobar", new byte[] {127, 0, 0, 1}), 1234);
|
||||||
assertThat(RouteSelector.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
|
assertThat(RouteSelector.Companion.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void routeToString() throws Exception {
|
@Test public void routeToString() throws Exception {
|
||||||
|
@@ -13,80 +13,84 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package okhttp3.internal.http;
|
package okhttp3.internal.http
|
||||||
|
|
||||||
import java.util.Date;
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import java.util.TimeZone;
|
import org.junit.After
|
||||||
import org.junit.After;
|
import org.junit.Before
|
||||||
import org.junit.Before;
|
import org.junit.Test
|
||||||
import org.junit.Test;
|
import java.util.Date
|
||||||
|
import java.util.TimeZone
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
class HttpDateTest {
|
||||||
|
|
||||||
public class HttpDateTest {
|
private lateinit var originalDefault: TimeZone
|
||||||
|
|
||||||
private TimeZone originalDefault;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
@Throws(Exception::class)
|
||||||
originalDefault = TimeZone.getDefault();
|
fun setUp() {
|
||||||
|
originalDefault = TimeZone.getDefault()
|
||||||
// The default timezone should affect none of these tests: HTTP specified GMT, so we set it to
|
// The default timezone should affect none of these tests: HTTP specified GMT, so we set it to
|
||||||
// something else.
|
// something else.
|
||||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
|
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
@Throws(Exception::class)
|
||||||
TimeZone.setDefault(originalDefault);
|
fun tearDown() {
|
||||||
|
TimeZone.setDefault(originalDefault)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void parseStandardFormats() throws Exception {
|
@Test @Throws(Exception::class)
|
||||||
|
fun parseStandardFormats() {
|
||||||
// RFC 822, updated by RFC 1123 with GMT.
|
// RFC 822, updated by RFC 1123 with GMT.
|
||||||
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 GMT").getTime()).isEqualTo(0L);
|
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 GMT")!!.time).isEqualTo(0L)
|
||||||
assertThat(HttpDate.parse("Fri, 06 Jun 2014 12:30:30 GMT").getTime()).isEqualTo(1402057830000L);
|
assertThat(HttpDate.parse("Fri, 06 Jun 2014 12:30:30 GMT")!!.time).isEqualTo(1402057830000L)
|
||||||
|
|
||||||
// RFC 850, obsoleted by RFC 1036 with GMT.
|
// RFC 850, obsoleted by RFC 1036 with GMT.
|
||||||
assertThat(HttpDate.parse("Thursday, 01-Jan-70 00:00:00 GMT").getTime()).isEqualTo(0L);
|
assertThat(HttpDate.parse("Thursday, 01-Jan-70 00:00:00 GMT")!!.time).isEqualTo(0L)
|
||||||
assertThat(HttpDate.parse("Friday, 06-Jun-14 12:30:30 GMT").getTime()).isEqualTo(1402057830000L);
|
assertThat(HttpDate.parse("Friday, 06-Jun-14 12:30:30 GMT")!!.time).isEqualTo(1402057830000L)
|
||||||
|
|
||||||
// ANSI C's asctime(): should use GMT, not platform default.
|
// ANSI C's asctime(): should use GMT, not platform default.
|
||||||
assertThat(HttpDate.parse("Thu Jan 1 00:00:00 1970").getTime()).isEqualTo(0L);
|
assertThat(HttpDate.parse("Thu Jan 1 00:00:00 1970")!!.time).isEqualTo(0L)
|
||||||
assertThat(HttpDate.parse("Fri Jun 6 12:30:30 2014").getTime()).isEqualTo(1402057830000L);
|
assertThat(HttpDate.parse("Fri Jun 6 12:30:30 2014")!!.time).isEqualTo(1402057830000L)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void format() throws Exception {
|
@Test @Throws(Exception::class)
|
||||||
assertThat(HttpDate.format(new Date(0))).isEqualTo("Thu, 01 Jan 1970 00:00:00 GMT");
|
fun format() {
|
||||||
assertThat(HttpDate.format(new Date(1402057830000L))).isEqualTo(
|
assertThat(HttpDate.format(Date(0L))).isEqualTo("Thu, 01 Jan 1970 00:00:00 GMT")
|
||||||
"Fri, 06 Jun 2014 12:30:30 GMT");
|
assertThat(HttpDate.format(Date(1402057830000L))).isEqualTo("Fri, 06 Jun 2014 12:30:30 GMT")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void parseNonStandardStrings() throws Exception {
|
@Test @Throws(Exception::class)
|
||||||
|
fun parseNonStandardStrings() {
|
||||||
// RFC 822, updated by RFC 1123 with any TZ
|
// RFC 822, updated by RFC 1123 with any TZ
|
||||||
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 GMT-01:00").getTime()).isEqualTo(3600000L);
|
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 GMT-01:00")!!.time).isEqualTo(3600000L)
|
||||||
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 PST").getTime()).isEqualTo(28800000L);
|
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 PST")!!.time).isEqualTo(28800000L)
|
||||||
// Ignore trailing junk
|
// Ignore trailing junk
|
||||||
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 GMT JUNK").getTime()).isEqualTo(0L);
|
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 GMT JUNK")!!.time).isEqualTo(0L)
|
||||||
// Missing timezones treated as bad.
|
// Missing timezones treated as bad.
|
||||||
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00")).isNull();
|
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00")).isNull()
|
||||||
// Missing seconds treated as bad.
|
// Missing seconds treated as bad.
|
||||||
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00 GMT")).isNull();
|
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00 GMT")).isNull()
|
||||||
// Extra spaces treated as bad.
|
// Extra spaces treated as bad.
|
||||||
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00 GMT")).isNull();
|
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00 GMT")).isNull()
|
||||||
// Missing leading zero treated as bad.
|
// Missing leading zero treated as bad.
|
||||||
assertThat(HttpDate.parse("Thu, 1 Jan 1970 00:00 GMT")).isNull();
|
assertThat(HttpDate.parse("Thu, 1 Jan 1970 00:00 GMT")).isNull()
|
||||||
|
|
||||||
// RFC 850, obsoleted by RFC 1036 with any TZ.
|
// RFC 850, obsoleted by RFC 1036 with any TZ.
|
||||||
assertThat(HttpDate.parse("Thursday, 01-Jan-1970 00:00:00 GMT-01:00").getTime()).isEqualTo(
|
assertThat(HttpDate.parse("Thursday, 01-Jan-1970 00:00:00 GMT-01:00")!!.time)
|
||||||
3600000L);
|
.isEqualTo(3600000L)
|
||||||
assertThat(HttpDate.parse("Thursday, 01-Jan-1970 00:00:00 PST").getTime()).isEqualTo(28800000L);
|
assertThat(HttpDate.parse("Thursday, 01-Jan-1970 00:00:00 PST")!!.time)
|
||||||
|
.isEqualTo(28800000L)
|
||||||
// Ignore trailing junk
|
// Ignore trailing junk
|
||||||
assertThat(HttpDate.parse("Thursday, 01-Jan-1970 00:00:00 PST JUNK").getTime()).isEqualTo(
|
assertThat(HttpDate.parse("Thursday, 01-Jan-1970 00:00:00 PST JUNK")!!.time)
|
||||||
28800000L);
|
.isEqualTo(28800000L)
|
||||||
|
|
||||||
// ANSI C's asctime() format
|
// ANSI C's asctime() format
|
||||||
// This format ignores the timezone entirely even if it is present and uses GMT.
|
// This format ignores the timezone entirely even if it is present and uses GMT.
|
||||||
assertThat(HttpDate.parse("Fri Jun 6 12:30:30 2014 PST").getTime()).isEqualTo(1402057830000L);
|
assertThat(HttpDate.parse("Fri Jun 6 12:30:30 2014 PST")!!.time).isEqualTo(1402057830000L)
|
||||||
// Ignore trailing junk.
|
// Ignore trailing junk.
|
||||||
assertThat(HttpDate.parse("Fri Jun 6 12:30:30 2014 JUNK").getTime()).isEqualTo(1402057830000L);
|
assertThat(HttpDate.parse("Fri Jun 6 12:30:30 2014 JUNK")!!.time).isEqualTo(1402057830000L)
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -44,7 +44,7 @@ public final class RecordingProxySelector extends ProxySelector {
|
|||||||
|
|
||||||
@Override public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
|
@Override public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
|
||||||
InetSocketAddress socketAddress = (InetSocketAddress) sa;
|
InetSocketAddress socketAddress = (InetSocketAddress) sa;
|
||||||
failures.add(Util.format("%s %s:%d %s",
|
failures.add(Util.INSTANCE.format("%s %s:%d %s",
|
||||||
uri, socketAddress, socketAddress.getPort(), ioe.getMessage()));
|
uri, socketAddress, socketAddress.getPort(), ioe.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,7 +28,8 @@ public final class StatusLineTest {
|
|||||||
String message = "Temporary Redirect";
|
String message = "Temporary Redirect";
|
||||||
int version = 1;
|
int version = 1;
|
||||||
int code = 200;
|
int code = 200;
|
||||||
StatusLine statusLine = StatusLine.parse("HTTP/1." + version + " " + code + " " + message);
|
StatusLine statusLine = StatusLine.Companion.parse(
|
||||||
|
"HTTP/1." + version + " " + code + " " + message);
|
||||||
assertThat(statusLine.message).isEqualTo(message);
|
assertThat(statusLine.message).isEqualTo(message);
|
||||||
assertThat(statusLine.protocol).isEqualTo(Protocol.HTTP_1_1);
|
assertThat(statusLine.protocol).isEqualTo(Protocol.HTTP_1_1);
|
||||||
assertThat(statusLine.code).isEqualTo(code);
|
assertThat(statusLine.code).isEqualTo(code);
|
||||||
@@ -37,7 +38,7 @@ public final class StatusLineTest {
|
|||||||
@Test public void emptyMessage() throws IOException {
|
@Test public void emptyMessage() throws IOException {
|
||||||
int version = 1;
|
int version = 1;
|
||||||
int code = 503;
|
int code = 503;
|
||||||
StatusLine statusLine = StatusLine.parse("HTTP/1." + version + " " + code + " ");
|
StatusLine statusLine = StatusLine.Companion.parse("HTTP/1." + version + " " + code + " ");
|
||||||
assertThat(statusLine.message).isEqualTo("");
|
assertThat(statusLine.message).isEqualTo("");
|
||||||
assertThat(statusLine.protocol).isEqualTo(Protocol.HTTP_1_1);
|
assertThat(statusLine.protocol).isEqualTo(Protocol.HTTP_1_1);
|
||||||
assertThat(statusLine.code).isEqualTo(code);
|
assertThat(statusLine.code).isEqualTo(code);
|
||||||
@@ -50,7 +51,7 @@ public final class StatusLineTest {
|
|||||||
@Test public void emptyMessageAndNoLeadingSpace() throws IOException {
|
@Test public void emptyMessageAndNoLeadingSpace() throws IOException {
|
||||||
int version = 1;
|
int version = 1;
|
||||||
int code = 503;
|
int code = 503;
|
||||||
StatusLine statusLine = StatusLine.parse("HTTP/1." + version + " " + code);
|
StatusLine statusLine = StatusLine.Companion.parse("HTTP/1." + version + " " + code);
|
||||||
assertThat(statusLine.message).isEqualTo("");
|
assertThat(statusLine.message).isEqualTo("");
|
||||||
assertThat(statusLine.protocol).isEqualTo(Protocol.HTTP_1_1);
|
assertThat(statusLine.protocol).isEqualTo(Protocol.HTTP_1_1);
|
||||||
assertThat(statusLine.code).isEqualTo(code);
|
assertThat(statusLine.code).isEqualTo(code);
|
||||||
@@ -58,7 +59,7 @@ public final class StatusLineTest {
|
|||||||
|
|
||||||
// https://github.com/square/okhttp/issues/386
|
// https://github.com/square/okhttp/issues/386
|
||||||
@Test public void shoutcast() throws IOException {
|
@Test public void shoutcast() throws IOException {
|
||||||
StatusLine statusLine = StatusLine.parse("ICY 200 OK");
|
StatusLine statusLine = StatusLine.Companion.parse("ICY 200 OK");
|
||||||
assertThat(statusLine.message).isEqualTo("OK");
|
assertThat(statusLine.message).isEqualTo("OK");
|
||||||
assertThat(statusLine.protocol).isEqualTo(Protocol.HTTP_1_0);
|
assertThat(statusLine.protocol).isEqualTo(Protocol.HTTP_1_0);
|
||||||
assertThat(statusLine.code).isEqualTo(200);
|
assertThat(statusLine.code).isEqualTo(200);
|
||||||
@@ -109,7 +110,7 @@ public final class StatusLineTest {
|
|||||||
|
|
||||||
private void assertInvalid(String statusLine) throws IOException {
|
private void assertInvalid(String statusLine) throws IOException {
|
||||||
try {
|
try {
|
||||||
StatusLine.parse(statusLine);
|
StatusLine.Companion.parse(statusLine);
|
||||||
fail();
|
fail();
|
||||||
} catch (ProtocolException expected) {
|
} catch (ProtocolException expected) {
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,6 @@ import static okhttp3.internal.http2.Http2.TYPE_HEADERS;
|
|||||||
import static okhttp3.internal.http2.Http2.TYPE_PING;
|
import static okhttp3.internal.http2.Http2.TYPE_PING;
|
||||||
import static okhttp3.internal.http2.Http2.TYPE_PUSH_PROMISE;
|
import static okhttp3.internal.http2.Http2.TYPE_PUSH_PROMISE;
|
||||||
import static okhttp3.internal.http2.Http2.TYPE_SETTINGS;
|
import static okhttp3.internal.http2.Http2.TYPE_SETTINGS;
|
||||||
import static okhttp3.internal.http2.Http2.frameLog;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public final class FrameLogTest {
|
public final class FrameLogTest {
|
||||||
@@ -89,7 +88,7 @@ public final class FrameLogTest {
|
|||||||
*/
|
*/
|
||||||
@Test public void allFormattedFlagsWithValidBits() {
|
@Test public void allFormattedFlagsWithValidBits() {
|
||||||
List<String> formattedFlags = new ArrayList<>(0x40); // Highest valid flag is 0x20.
|
List<String> formattedFlags = new ArrayList<>(0x40); // Highest valid flag is 0x20.
|
||||||
for (byte i = 0; i < 0x40; i++) formattedFlags.add(Http2.formatFlags(TYPE_HEADERS, i));
|
for (byte i = 0; i < 0x40; i++) formattedFlags.add(Http2.INSTANCE.formatFlags(TYPE_HEADERS, i));
|
||||||
|
|
||||||
assertThat(formattedFlags).containsExactly(
|
assertThat(formattedFlags).containsExactly(
|
||||||
"",
|
"",
|
||||||
@@ -158,4 +157,8 @@ public final class FrameLogTest {
|
|||||||
"00111111"
|
"00111111"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String frameLog(boolean inbound, int streamId, int length, int type, int flags) {
|
||||||
|
return Http2.INSTANCE.frameLog(inbound, streamId, length, type, flags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -51,7 +51,7 @@ public final class MockHttp2Peer implements Closeable {
|
|||||||
private final BlockingQueue<InFrame> inFrames = new LinkedBlockingQueue<>();
|
private final BlockingQueue<InFrame> inFrames = new LinkedBlockingQueue<>();
|
||||||
private int port;
|
private int port;
|
||||||
private final ExecutorService executor = Executors.newSingleThreadExecutor(
|
private final ExecutorService executor = Executors.newSingleThreadExecutor(
|
||||||
Util.threadFactory("MockHttp2Peer", false));
|
Util.INSTANCE.threadFactory("MockHttp2Peer", false));
|
||||||
private ServerSocket serverSocket;
|
private ServerSocket serverSocket;
|
||||||
private Socket socket;
|
private Socket socket;
|
||||||
|
|
||||||
|
@@ -31,13 +31,13 @@ public class Jdk8WithJettyBootPlatformTest {
|
|||||||
assumeTrue(System.getProperty("java.specification.version").equals("1.8"));
|
assumeTrue(System.getProperty("java.specification.version").equals("1.8"));
|
||||||
platform.assumeJettyBootEnabled();
|
platform.assumeJettyBootEnabled();
|
||||||
|
|
||||||
assertThat(Jdk8WithJettyBootPlatform.buildIfSupported()).isNotNull();
|
assertThat(Jdk8WithJettyBootPlatform.Companion.buildIfSupported()).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotBuildWithOther() {
|
public void testNotBuildWithOther() {
|
||||||
assumeFalse(System.getProperty("java.specification.version").equals("1.8"));
|
assumeFalse(System.getProperty("java.specification.version").equals("1.8"));
|
||||||
|
|
||||||
assertThat(Jdk8WithJettyBootPlatform.buildIfSupported()).isNull();
|
assertThat(Jdk8WithJettyBootPlatform.Companion.buildIfSupported()).isNull();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,12 +27,12 @@ public class Jdk9PlatformTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildsWhenJdk9() {
|
public void buildsWhenJdk9() {
|
||||||
assertThat(Jdk9Platform.buildIfSupported()).isNotNull();
|
assertThat(Jdk9Platform.Companion.buildIfSupported()).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findsAlpnMethods() {
|
public void findsAlpnMethods() {
|
||||||
Jdk9Platform platform = Jdk9Platform.buildIfSupported();
|
Jdk9Platform platform = Jdk9Platform.Companion.buildIfSupported();
|
||||||
|
|
||||||
assertThat(platform.getProtocolMethod.getName()).isEqualTo("getApplicationProtocol");
|
assertThat(platform.getProtocolMethod.getName()).isEqualTo("getApplicationProtocol");
|
||||||
assertThat(platform.setProtocolMethod.getName()).isEqualTo("setApplicationProtocols");
|
assertThat(platform.setProtocolMethod.getName()).isEqualTo("setApplicationProtocols");
|
||||||
|
@@ -518,28 +518,28 @@ public final class HostnameVerifierTest {
|
|||||||
|
|
||||||
@Test public void verifyAsIpAddress() {
|
@Test public void verifyAsIpAddress() {
|
||||||
// IPv4
|
// IPv4
|
||||||
assertThat(Util.verifyAsIpAddress("127.0.0.1")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("127.0.0.1")).isTrue();
|
||||||
assertThat(Util.verifyAsIpAddress("1.2.3.4")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("1.2.3.4")).isTrue();
|
||||||
|
|
||||||
// IPv6
|
// IPv6
|
||||||
assertThat(Util.verifyAsIpAddress("::1")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("::1")).isTrue();
|
||||||
assertThat(Util.verifyAsIpAddress("2001:db8::1")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("2001:db8::1")).isTrue();
|
||||||
assertThat(Util.verifyAsIpAddress("::192.168.0.1")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("::192.168.0.1")).isTrue();
|
||||||
assertThat(Util.verifyAsIpAddress("::ffff:192.168.0.1")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("::ffff:192.168.0.1")).isTrue();
|
||||||
assertThat(Util.verifyAsIpAddress("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210")).isTrue();
|
||||||
assertThat(Util.verifyAsIpAddress("1080:0:0:0:8:800:200C:417A")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("1080:0:0:0:8:800:200C:417A")).isTrue();
|
||||||
assertThat(Util.verifyAsIpAddress("1080::8:800:200C:417A")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("1080::8:800:200C:417A")).isTrue();
|
||||||
assertThat(Util.verifyAsIpAddress("FF01::101")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("FF01::101")).isTrue();
|
||||||
assertThat(Util.verifyAsIpAddress("0:0:0:0:0:0:13.1.68.3")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("0:0:0:0:0:0:13.1.68.3")).isTrue();
|
||||||
assertThat(Util.verifyAsIpAddress("0:0:0:0:0:FFFF:129.144.52.38")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("0:0:0:0:0:FFFF:129.144.52.38")).isTrue();
|
||||||
assertThat(Util.verifyAsIpAddress("::13.1.68.3")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("::13.1.68.3")).isTrue();
|
||||||
assertThat(Util.verifyAsIpAddress("::FFFF:129.144.52.38")).isTrue();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("::FFFF:129.144.52.38")).isTrue();
|
||||||
|
|
||||||
// Hostnames
|
// Hostnames
|
||||||
assertThat(Util.verifyAsIpAddress("go")).isFalse();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("go")).isFalse();
|
||||||
assertThat(Util.verifyAsIpAddress("localhost")).isFalse();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("localhost")).isFalse();
|
||||||
assertThat(Util.verifyAsIpAddress("squareup.com")).isFalse();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("squareup.com")).isFalse();
|
||||||
assertThat(Util.verifyAsIpAddress("www.nintendo.co.jp")).isFalse();
|
assertThat(Util.INSTANCE.verifyAsIpAddress("www.nintendo.co.jp")).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private X509Certificate certificate(String certificate) throws Exception {
|
private X509Certificate certificate(String certificate) throws Exception {
|
||||||
|
@@ -764,7 +764,7 @@ public final class WebSocketHttpTest {
|
|||||||
.setStatus("HTTP/1.1 101 Switching Protocols")
|
.setStatus("HTTP/1.1 101 Switching Protocols")
|
||||||
.setHeader("Connection", "Upgrade")
|
.setHeader("Connection", "Upgrade")
|
||||||
.setHeader("Upgrade", "websocket")
|
.setHeader("Upgrade", "websocket")
|
||||||
.setHeader("Sec-WebSocket-Accept", WebSocketProtocol.acceptHeader(key));
|
.setHeader("Sec-WebSocket-Accept", WebSocketProtocol.INSTANCE.acceptHeader(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void websocketScheme(String scheme) {
|
private void websocketScheme(String scheme) {
|
||||||
|
@@ -299,7 +299,8 @@ public final class WebSocketReaderTest {
|
|||||||
data.write(ByteString.decodeHex("880203ed")); // Close with code 1005
|
data.write(ByteString.decodeHex("880203ed")); // Close with code 1005
|
||||||
data.write(ByteString.decodeHex("880203ee")); // Close with code 1006
|
data.write(ByteString.decodeHex("880203ee")); // Close with code 1006
|
||||||
for (int i = 1012; i <= 2999; i++) {
|
for (int i = 1012; i <= 2999; i++) {
|
||||||
data.write(ByteString.decodeHex("8802" + Util.format("%04X", i))); // Close with code 'i'
|
data.write(ByteString.decodeHex(
|
||||||
|
"8802" + Util.INSTANCE.format("%04X", i))); // Close with code 'i'
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
@@ -95,7 +95,7 @@ public final class WebSocketWriterTest {
|
|||||||
sink.close();
|
sink.close();
|
||||||
|
|
||||||
assertData("817e");
|
assertData("817e");
|
||||||
assertData(Util.format("%04x", length));
|
assertData(Util.INSTANCE.format("%04x", length));
|
||||||
assertData(bytes);
|
assertData(bytes);
|
||||||
assertThat(data.exhausted()).isTrue();
|
assertThat(data.exhausted()).isTrue();
|
||||||
}
|
}
|
||||||
@@ -199,7 +199,7 @@ public final class WebSocketWriterTest {
|
|||||||
// Write directly to the unbuffered sink. This ensures it will become single frame.
|
// Write directly to the unbuffered sink. This ensures it will become single frame.
|
||||||
sink.write(payload.clone(), byteCount);
|
sink.write(payload.clone(), byteCount);
|
||||||
assertData("027e"); // 'e' == 4-byte follow-up length.
|
assertData("027e"); // 'e' == 4-byte follow-up length.
|
||||||
assertData(Util.format("%04X", payload.completeSegmentByteCount()));
|
assertData(Util.INSTANCE.format("%04X", payload.completeSegmentByteCount()));
|
||||||
assertData(payload.readByteArray());
|
assertData(payload.readByteArray());
|
||||||
|
|
||||||
sink.close();
|
sink.close();
|
||||||
@@ -219,7 +219,7 @@ public final class WebSocketWriterTest {
|
|||||||
// Write directly to the unbuffered sink. This ensures it will become single frame.
|
// Write directly to the unbuffered sink. This ensures it will become single frame.
|
||||||
sink.write(payload.clone(), byteCount);
|
sink.write(payload.clone(), byteCount);
|
||||||
assertData("027f"); // 'f' == 16-byte follow-up length.
|
assertData("027f"); // 'f' == 16-byte follow-up length.
|
||||||
assertData(Util.format("%016X", byteCount));
|
assertData(Util.INSTANCE.format("%016X", byteCount));
|
||||||
assertData(payload.readByteArray(byteCount));
|
assertData(payload.readByteArray(byteCount));
|
||||||
|
|
||||||
sink.close();
|
sink.close();
|
||||||
|
Reference in New Issue
Block a user