|
|
@ -1,7 +1,10 @@ |
|
|
|
package org.openrs2.http |
|
|
|
package org.openrs2.http |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.common.net.HttpHeaders |
|
|
|
|
|
|
|
import com.google.common.net.MediaType |
|
|
|
import java.io.IOException |
|
|
|
import java.io.IOException |
|
|
|
import java.net.http.HttpResponse |
|
|
|
import java.net.http.HttpResponse |
|
|
|
|
|
|
|
import java.nio.charset.Charset |
|
|
|
|
|
|
|
|
|
|
|
private val DEFAULT_EXPECTED_STATUS_CODES = setOf(200) |
|
|
|
private val DEFAULT_EXPECTED_STATUS_CODES = setOf(200) |
|
|
|
|
|
|
|
|
|
|
@ -11,3 +14,12 @@ public fun <T> HttpResponse<T>.checkStatusCode(expectedStatusCodes: Set<Int> = D |
|
|
|
throw IOException("Unexpected status code: $status") |
|
|
|
throw IOException("Unexpected status code: $status") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public val <T> HttpResponse<T>.contentType: MediaType? |
|
|
|
|
|
|
|
get() = headers().firstValue(HttpHeaders.CONTENT_TYPE).map(MediaType::parse).orElse(null) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public val <T> HttpResponse<T>.charset: Charset? |
|
|
|
|
|
|
|
get() { |
|
|
|
|
|
|
|
val contentType = contentType ?: return null |
|
|
|
|
|
|
|
return contentType.charset().orNull() |
|
|
|
|
|
|
|
} |
|
|
|