Support custom headers for page requests
parent
96d437b2a8
commit
bb1dd74277
@ -0,0 +1,18 @@
|
|||||||
|
package org.koitharu.kotatsu.core.model
|
||||||
|
|
||||||
|
import okhttp3.Headers
|
||||||
|
import okhttp3.Request
|
||||||
|
|
||||||
|
data class RequestDraft(
|
||||||
|
val url: String,
|
||||||
|
val headers: Headers
|
||||||
|
) {
|
||||||
|
|
||||||
|
val isValid: Boolean
|
||||||
|
get() = url.isNotEmpty()
|
||||||
|
|
||||||
|
fun newBuilder(): Request.Builder = Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.get()
|
||||||
|
.headers(headers)
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network
|
||||||
|
|
||||||
|
object CommonHeaders {
|
||||||
|
|
||||||
|
const val REFERER = "Referer"
|
||||||
|
const val USER_AGENT = "User-Agent"
|
||||||
|
const val ACCEPT = "Accept"
|
||||||
|
const val CONTENT_DISPOSITION = "Content-Disposition"
|
||||||
|
}
|
||||||
@ -1,9 +1,10 @@
|
|||||||
package org.koitharu.kotatsu.utils.ext
|
package org.koitharu.kotatsu.utils.ext
|
||||||
|
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
|
import org.koitharu.kotatsu.core.network.CommonHeaders
|
||||||
|
|
||||||
val Response.mimeType: String?
|
val Response.mimeType: String?
|
||||||
get() = body?.contentType()?.run { "$type/$subtype" }
|
get() = body?.contentType()?.run { "$type/$subtype" }
|
||||||
|
|
||||||
val Response.contentDisposition: String?
|
val Response.contentDisposition: String?
|
||||||
get() = header("Content-Disposition")
|
get() = header(CommonHeaders.CONTENT_DISPOSITION)
|
||||||
Loading…
Reference in New Issue