mirror of
https://github.com/square/okhttp.git
synced 2025-07-31 05:04:26 +03:00
committed by
Jesse Wilson
parent
fbfb5f8461
commit
dcf5c8ceb6
@ -705,7 +705,7 @@ class MockWebServer : ExternalResource(), Closeable {
|
|||||||
.url("$scheme://$authority/")
|
.url("$scheme://$authority/")
|
||||||
.headers(request.headers)
|
.headers(request.headers)
|
||||||
.build()
|
.build()
|
||||||
val statusParts = response.getStatus().split(" ".toRegex(), 3)
|
val statusParts = response.getStatus().split(' ', limit = 3)
|
||||||
val fancyResponse = Response.Builder()
|
val fancyResponse = Response.Builder()
|
||||||
.code(Integer.parseInt(statusParts[1]))
|
.code(Integer.parseInt(statusParts[1]))
|
||||||
.message(statusParts[2])
|
.message(statusParts[2])
|
||||||
@ -970,7 +970,7 @@ class MockWebServer : ExternalResource(), Closeable {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val http2Headers = ArrayList<Header>()
|
val http2Headers = ArrayList<Header>()
|
||||||
val statusParts = response.getStatus().split(" ".toRegex(), 3).toTypedArray()
|
val statusParts = response.getStatus().split(' ', limit = 3)
|
||||||
if (statusParts.size < 2) {
|
if (statusParts.size < 2) {
|
||||||
throw AssertionError("Unexpected status: ${response.getStatus()}")
|
throw AssertionError("Unexpected status: ${response.getStatus()}")
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ class Main : Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (header in headers.orEmpty()) {
|
for (header in headers.orEmpty()) {
|
||||||
val parts = header.split(":".toRegex(), 2).toTypedArray()
|
val parts = header.split(':', limit = 2)
|
||||||
request.header(parts[0], parts[1])
|
request.header(parts[0], parts[1])
|
||||||
}
|
}
|
||||||
referer?.let {
|
referer?.let {
|
||||||
@ -205,7 +205,7 @@ class Main : Runnable {
|
|||||||
private fun mediaType(): MediaType? {
|
private fun mediaType(): MediaType? {
|
||||||
val mimeType = headers?.let {
|
val mimeType = headers?.let {
|
||||||
for (header in it) {
|
for (header in it) {
|
||||||
val parts = header.split(":".toRegex()).toTypedArray()
|
val parts = header.split(':')
|
||||||
if ("Content-Type".equals(parts[0], ignoreCase = true)) {
|
if ("Content-Type".equals(parts[0], ignoreCase = true)) {
|
||||||
it.remove(header)
|
it.remove(header)
|
||||||
return@let parts[1].trim()
|
return@let parts[1].trim()
|
||||||
|
@ -45,7 +45,7 @@ object DnsRecordCodec {
|
|||||||
writeShort(0) // additional
|
writeShort(0) // additional
|
||||||
|
|
||||||
val nameBuf = Buffer()
|
val nameBuf = Buffer()
|
||||||
val labels = host.split('.').dropLastWhile { it.isEmpty() }.toTypedArray()
|
val labels = host.split('.').dropLastWhile { it.isEmpty() }
|
||||||
for (label in labels) {
|
for (label in labels) {
|
||||||
val utf8ByteCount = label.utf8Size()
|
val utf8ByteCount = label.utf8Size()
|
||||||
if (utf8ByteCount != label.length.toLong()) {
|
if (utf8ByteCount != label.length.toLong()) {
|
||||||
|
@ -39,7 +39,6 @@ import java.util.concurrent.Executor
|
|||||||
import java.util.concurrent.LinkedBlockingQueue
|
import java.util.concurrent.LinkedBlockingQueue
|
||||||
import java.util.concurrent.ThreadPoolExecutor
|
import java.util.concurrent.ThreadPoolExecutor
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.regex.Pattern
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cache that uses a bounded amount of space on a filesystem. Each cache entry has a string key
|
* A cache that uses a bounded amount of space on a filesystem. Each cache entry has a string key
|
||||||
@ -317,8 +316,7 @@ class DiskLruCache internal constructor(
|
|||||||
when {
|
when {
|
||||||
secondSpace != -1 && firstSpace == CLEAN.length && line.startsWith(CLEAN) -> {
|
secondSpace != -1 && firstSpace == CLEAN.length && line.startsWith(CLEAN) -> {
|
||||||
val parts = line.substring(secondSpace + 1)
|
val parts = line.substring(secondSpace + 1)
|
||||||
.split(" ".toRegex())
|
.split(' ')
|
||||||
.toTypedArray()
|
|
||||||
entry.readable = true
|
entry.readable = true
|
||||||
entry.currentEditor = null
|
entry.currentEditor = null
|
||||||
entry.setLengths(parts)
|
entry.setLengths(parts)
|
||||||
@ -670,8 +668,7 @@ class DiskLruCache internal constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun validateKey(key: String) {
|
private fun validateKey(key: String) {
|
||||||
val matcher = LEGAL_KEY_PATTERN.matcher(key)
|
require(LEGAL_KEY_PATTERN.matches(key)) { "keys must match regex [a-z0-9_-]{1,120}: \"$key\"" }
|
||||||
require(matcher.matches()) { "keys must match regex [a-z0-9_-]{1,120}: \"$key\"" }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -905,7 +902,7 @@ class DiskLruCache internal constructor(
|
|||||||
|
|
||||||
/** Set lengths using decimal numbers like "10123". */
|
/** Set lengths using decimal numbers like "10123". */
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
internal fun setLengths(strings: Array<String>) {
|
internal fun setLengths(strings: List<String>) {
|
||||||
if (strings.size != valueCount) {
|
if (strings.size != valueCount) {
|
||||||
throw invalidLengths(strings)
|
throw invalidLengths(strings)
|
||||||
}
|
}
|
||||||
@ -928,8 +925,8 @@ class DiskLruCache internal constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
private fun invalidLengths(strings: Array<String>): IOException {
|
private fun invalidLengths(strings: List<String>): IOException {
|
||||||
throw IOException("unexpected journal line: ${strings.contentToString()}")
|
throw IOException("unexpected journal line: $strings")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -970,7 +967,7 @@ class DiskLruCache internal constructor(
|
|||||||
@JvmField val MAGIC = "libcore.io.DiskLruCache"
|
@JvmField val MAGIC = "libcore.io.DiskLruCache"
|
||||||
@JvmField val VERSION_1 = "1"
|
@JvmField val VERSION_1 = "1"
|
||||||
@JvmField val ANY_SEQUENCE_NUMBER: Long = -1
|
@JvmField val ANY_SEQUENCE_NUMBER: Long = -1
|
||||||
@JvmField val LEGAL_KEY_PATTERN = Pattern.compile("[a-z0-9_-]{1,120}")
|
@JvmField val LEGAL_KEY_PATTERN = "[a-z0-9_-]{1,120}".toRegex()
|
||||||
@JvmField val CLEAN = "CLEAN"
|
@JvmField val CLEAN = "CLEAN"
|
||||||
@JvmField val DIRTY = "DIRTY"
|
@JvmField val DIRTY = "DIRTY"
|
||||||
@JvmField val REMOVE = "REMOVE"
|
@JvmField val REMOVE = "REMOVE"
|
||||||
|
Reference in New Issue
Block a user