common-plugin / com.cognifide.gradle.common.http / HttpClient

HttpClient

open class HttpClient

Constructors

<init>

HttpClient(common: CommonExtension)

Properties

authorizationPreemptive

val authorizationPreemptive: Property<Boolean!>!

baseUrl

val baseUrl: Property<String!>!

basicCredentials

var basicCredentials: Pair<String?, String?>

basicPassword

val basicPassword: Property<String!>!

basicUser

val basicUser: Property<String!>!

client

val client: CloseableHttpClient!

connectionIgnoreSsl

val connectionIgnoreSsl: Property<Boolean!>!

connectionRetries

val connectionRetries: Property<Boolean!>!

connectionTimeout

val connectionTimeout: Property<Int!>!

multipartBinaryType

val multipartBinaryType: Property<ContentType!>!

multipartTextType

val multipartTextType: Property<ContentType!>!

proxyHost

val proxyHost: Property<String!>!

proxyPort

val proxyPort: Property<Int!>!

proxyScheme

val proxyScheme: Property<String!>!

responseChecks

val responseChecks: Property<Boolean!>!

Functions

asHtml

fun asHtml(response: HttpResponse): Document
fun asHtml(htmlString: String): Document

asJson

fun asJson(response: HttpResponse): DocumentContext
fun asJson(jsonString: String): DocumentContext

asObjectFromJson

fun <T : Any> asObjectFromJson(response: HttpResponse): T
fun <T> asObjectFromJson(response: HttpResponse, clazz: Class<T>): T

asStream

fun asStream(response: HttpResponse): InputStream

asString

fun asString(response: HttpResponse): String

asXml

fun asXml(response: HttpResponse): Document
fun asXml(xmlString: String): Document

baseUrl

Fix for HttpClient's: 'escaped absolute path not valid' https://stackoverflow.com/questions/13652681/httpclient-invalid-uri-escaped-absolute-path-not-valid

open fun baseUrl(uri: String): String

checkHtml

fun checkHtml(response: HttpResponse, validator: Document.() -> Boolean): Unit

checkStatus

fun checkStatus(response: HttpResponse, statusCodes: IntRange = STATUS_CODE_VALID): Unit
fun checkStatus(response: HttpResponse, statusCode: Int): Unit
fun checkStatus(response: HttpResponse, statusCodes: List<Int>): Unit

checkText

fun checkText(response: HttpResponse, containedText: String, ignoreCase: Boolean = true): Unit

clientBuilder

fun clientBuilder(builder: HttpClientBuilder.() -> Unit): Unit

createEntityMultipart

open fun createEntityMultipart(params: Map<String, Any?>): HttpEntity

createEntityUrlencoded

open fun createEntityUrlencoded(params: Map<String, Any?>): HttpEntity

delete

fun delete(uri: String): Unit
fun <T> delete(uri: String, handler: HttpClient.(HttpResponse) -> T): T
fun <T> delete(uri: String, handler: HttpClient.(HttpResponse) -> T, options: HttpDelete.() -> Unit): T

download

fun download(fileUrl: String): File
fun download(fileUrl: String, target: File): Unit

downloadTo

fun downloadTo(fileUrl: String, dir: File): File

execute

open fun <T> execute(method: HttpRequestBase, handler: HttpClient.(HttpResponse) -> T): T
fun execute(method: HttpRequestBase): Unit

get

fun get(uri: String): Unit
fun <T> get(uri: String, handler: HttpClient.(HttpResponse) -> T): T
fun <T> get(uri: String, handler: HttpClient.(HttpResponse) -> T, options: HttpGet.() -> Unit): T

head

fun head(uri: String): Unit
fun <T> head(uri: String, handler: HttpClient.(HttpResponse) -> T): T
fun <T> head(uri: String, handler: HttpClient.(HttpResponse) -> T, options: HttpHead.() -> Unit): T

patch

fun patch(path: String): Unit
fun <T> patch(uri: String, handler: HttpClient.(HttpResponse) -> T): T
fun <T> patch(uri: String, handler: HttpClient.(HttpResponse) -> T, options: HttpPatch.() -> Unit): T

post

fun post(url: String, params: Map<String, Any?> = mapOf()): Unit
fun <T> post(uri: String, params: Map<String, Any?> = mapOf(), handler: HttpClient.(HttpResponse) -> T): T
fun <T> post(uri: String, handler: HttpClient.(HttpResponse) -> T): T
fun <T> post(uri: String, handler: HttpClient.(HttpResponse) -> T, options: HttpPost.() -> Unit): T

postMultipart

fun postMultipart(uri: String, params: Map<String, Any?> = mapOf()): Unit
fun <T> postMultipart(uri: String, params: Map<String, Any?> = mapOf(), handler: HttpClient.(HttpResponse) -> T): T

postUrlencoded

fun postUrlencoded(uri: String, params: Map<String, Any?> = mapOf()): Unit
fun <T> postUrlencoded(uri: String, params: Map<String, Any?> = mapOf(), handler: HttpClient.(HttpResponse) -> T): T

put

fun put(uri: String): Unit
fun <T> put(uri: String, handler: HttpClient.(HttpResponse) -> T): T
fun <T> put(uri: String, handler: HttpClient.(HttpResponse) -> T, options: HttpPut.() -> Unit): T

request

fun <T> request(method: String, uri: String, handler: HttpClient.(HttpResponse) -> T): T

requestConfigurer

fun requestConfigurer(configurer: HttpRequestBase.() -> Unit): Unit

responseChecker

fun responseChecker(checker: (HttpResponse) -> Unit): Unit

responseHandler

fun responseHandler(handler: (HttpResponse) -> Unit): Unit

throwStatusException

open fun throwStatusException(response: HttpResponse): Unit

useDefaults

fun HttpClientBuilder.useDefaults(): Unit

Companion Object Properties

STATUS_CODE_VALID

val STATUS_CODE_VALID: IntRange