How to use RequestExecutionOptions class of com.github.kittinunf.fuel.core package

Best Fuel code snippet using com.github.kittinunf.fuel.core.RequestExecutionOptions

Request.kt

Source:Request.kt Github

copy

Full Screen

...12 val method: Method13 var url: URL14 val headers: Headers15 var parameters: Parameters16 var executionOptions: RequestExecutionOptions17 val body: Body18 val enabledFeatures: RequestFeatures19 /**20 * Add a [ProgressCallback] tracking the [Body] of the [Request]21 *22 * @see body23 * @see com.github.kittinunf.fuel.core.requests.UploadRequest.progress24 *25 * @return self26 */27 fun requestProgress(handler: ProgressCallback): Request28 /**29 * Add a [ProgressCallback] tracking the [Body] of the [Response]30 *31 * @see com.github.kittinunf.fuel.core.requests.DownloadRequest.progress32 *33 * @return self34 */35 fun responseProgress(handler: ProgressCallback): Request36 /**37 * Overwrite the [Request] [timeout] in milliseconds38 *39 * @note [Client] must implement this behaviour40 * @note the default client sets [java.net.HttpURLConnection.setConnectTimeout]41 *42 * @param timeout [Int] timeout in milliseconds43 * @return self44 */45 fun timeout(timeout: Int): Request46 /**47 * Overwrite the [Request] [timeout] in milliseconds48 *49 * @note [Client] must implement this behaviour50 * @note the default client sets [java.net.HttpURLConnection.setReadTimeout]51 *52 * @param timeout [Int] timeout in milliseconds53 * @return self54 */55 fun timeoutRead(timeout: Int): Request56 /**57 * Overwrite [RequestExecutionOptions] http cache usage flag58 *59 * @note [Client] must implement this behaviour60 * @note The default client sends `Cache-Control: none` if this flag is false, defaults to true61 *62 * @see java.net.HttpURLConnection.setUseCaches63 * @param useHttpCache [Boolean] true if suggest client to allow cached responses, false otherwise64 */65 fun useHttpCache(useHttpCache: Boolean): Request66 /**67 * Follow redirects as handled by instances of RedirectInterceptors68 * i.e. [com.github.kittinunf.fuel.core.interceptors.redirectResponseInterceptor]69 *70 * @param allowRedirects [Boolean] true if allowing, false if not71 * @return self72 */73 fun allowRedirects(allowRedirects: Boolean): Request74 /**75 * Returns a string representation of the request.76 *77 * @see com.github.kittinunf.fuel.core.extensions.httpString78 * @see com.github.kittinunf.fuel.core.extensions.cUrlString79 *80 * @return [String] the string representation81 */82 override fun toString(): String83 /**84 * Get the current values of the header, after normalisation of the header85 * @param header [String] the header name86 * @return the current values (or empty if none)87 */88 operator fun get(header: String): HeaderValues89 /**90 * Set the values of the header, overriding what's there, after normalisation of the header91 *92 * @param header [String] the header name93 * @param values [Collection<*>] the values to be transformed through #toString94 * @return self95 */96 operator fun set(header: String, values: Collection<*>): Request97 /**98 * Set the value of the header, overriding what's there, after normalisation of the header99 *100 * @param header [String] the header name101 * @param value [Any] the value to be transformed through #toString102 */103 operator fun set(header: String, value: Any): Request104 /**105 * Get the current values106 *107 * @see get(header: String)108 * @return [HeaderValues] the current values109 */110 fun header(header: String): HeaderValues111 /**112 * Replace the headers with the map provided113 *114 * @note In earlier versions the mapOf variant of this function worked differently than the vararg pairs variant,115 * which has been changed to make any call to header(...) always overwrite the values and any call to116 * appendHeader(...) will try to append the value.117 *118 * @see set(header: String, values: Collection<*>)119 * @see set(header: String, value: Any)120 *121 * @param map [Map<String, Any>] map of headers to replace. Value can be a list or single value122 * @return [Request] the modified request123 */124 fun header(map: Map<String, Any>): Request125 /**126 * Replace the headers with the pairs provided127 *128 * @note In earlier versions the mapOf variant of this function worked differently than the vararg pairs variant,129 * which has been changed to make any call to header(...) always overwrite the values and any call to130 * appendHeader(...) will try to append the value.131 *132 * @see set(header: String, values: Collection<*>)133 * @see set(header: String, value: Any)134 *135 * @param pairs [Pair<String, Any>] map of headers to replace. Value can be a list or single value136 * @return [Request] the modified request137 */138 fun header(vararg pairs: Pair<String, Any>): Request139 /**140 * Replace the header with the provided values141 *142 * @see set(header: String, values: Collection<*>)143 *144 * @param header [String] the header to set145 * @param values [List<Any>] the values to set the header to146 * @return [Request] the modified request147 */148 fun header(header: String, values: Collection<*>): Request149 /**150 * Replace the header with the provided value151 *152 * @see set(header: String, values: List<Any>)153 *154 * @param header [String] the header to set155 * @param value [Any] the value to set the header to156 * @return [Request] the modified request157 */158 fun header(header: String, value: Any): Request159 /**160 * Replace the header with the provided values161 *162 * @see set(header: String, values: List<Any>)163 *164 * @param header [String] the header to set165 * @param values [Any] the values to set the header to166 * @return [Request] the modified request167 */168 fun header(header: String, vararg values: Any): Request169 /**170 * Appends the value to the header or sets it if there was none yet171 *172 * @param header [String] the header name to append to173 * @param value [Any] the value to be transformed through #toString174 */175 fun appendHeader(header: String, value: Any): Request176 /**177 * Appends the value to the header or sets it if there was none yet178 *179 * @param header [String] the header name to append to180 * @param values [Any] the value to be transformed through #toString181 */182 fun appendHeader(header: String, vararg values: Any): Request183 /**184 * Append each pair, using the key as header name and value as header content185 *186 * @param pairs [Pair<String, Any>]187 */188 fun appendHeader(vararg pairs: Pair<String, Any>): Request189 /**190 * Execute the [Request] asynchronously, using the [handler], into a [ByteArray]191 *192 * @param handler [ResponseResultHandler] the handler to report the [Request], [Response] and Result of [ByteArray]193 * @return [CancellableRequest] the request in flight194 */195 fun response(handler: ResponseResultHandler<ByteArray>): CancellableRequest196 /**197 * Execute the [Request] asynchronously, using the [handler], into a [ByteArray]198 *199 * @param handler [ResultHandler] the handler to report the Result of [ByteArray]200 * @return [CancellableRequest] the request in flight201 */202 fun response(handler: ResultHandler<ByteArray>): CancellableRequest203 /**204 * Execute the [Request] asynchronously, using the [handler], into a [ByteArray]205 *206 * @param handler [ResponseHandler] the handler to report the [Request], [Response], and [ByteArray] or [FuelError]207 * @return [CancellableRequest] the request in flight208 */209 fun response(handler: ResponseHandler<ByteArray>): CancellableRequest210 /**211 * Execute the [Request] asynchronously, using the [handler], into a [ByteArray]212 *213 * @param handler [Handler] the handler to report the [ByteArray] or [FuelError]214 * @return [CancellableRequest] the request in flight215 */216 fun response(handler: Handler<ByteArray>): CancellableRequest217 /**218 * Execute the [Request] asynchronously, using the [handler], into a [Charsets.UTF_8] [String]219 *220 * @param handler [ResponseResultHandler] the handler to report the [Request], [Response] and Result of [String]221 * @return [CancellableRequest] the request in flight222 */223 fun responseString(handler: ResponseResultHandler<String>): CancellableRequest224 /**225 * Execute the [Request] asynchronously, using the [handler], into a [String]226 *227 * @param charset [Charset] the charset to use for the [String]228 * @param handler [ResponseResultHandler] the handler to report the [Request], [Response] and Result of [String]229 * @return [CancellableRequest] the request in flight230 */231 fun responseString(charset: Charset = Charsets.UTF_8, handler: ResponseResultHandler<String>): CancellableRequest232 /**233 * Execute the [Request] asynchronously, using the [handler], into a [Charsets.UTF_8] [String]234 *235 * @param handler [ResultHandler] the handler to report the Result of [String]236 * @return [CancellableRequest] the request in flight237 */238 fun responseString(handler: ResultHandler<String>): CancellableRequest239 /**240 * Execute the [Request] asynchronously, using the [handler], into a [String]241 *242 * @param charset [Charset] the charset to use for the [String]243 * @param handler [ResultHandler] the handler to report the Result of [String]244 * @return [CancellableRequest] the request in flight245 */246 fun responseString(charset: Charset = Charsets.UTF_8, handler: ResultHandler<String>): CancellableRequest247 /**248 * Execute the [Request] asynchronously, using the [handler], into a [Charsets.UTF_8] [String]249 *250 * @param handler [ResponseHandler] the handler to report the [Request], [Response], and [String] or [FuelError]251 * @return [CancellableRequest] the request in flight252 */253 fun responseString(handler: ResponseHandler<String>): CancellableRequest254 /**255 * Execute the [Request] asynchronously, using the [handler], into a [String]256 *257 * @param charset [Charset] the charset to use for the [String]258 * @param handler [ResponseHandler] the handler to report the [Request], [Response], and [String] or [FuelError]259 * @return [CancellableRequest] the request in flight260 */261 fun responseString(charset: Charset = Charsets.UTF_8, handler: ResponseHandler<String>): CancellableRequest262 /**263 * Execute the [Request] asynchronously, using the [handler], into a [Charsets.UTF_8] [String]264 *265 * @param handler [Handler] the handler to report the [String] or [FuelError]266 * @return [CancellableRequest] the request in flight267 */268 fun responseString(handler: Handler<String>): CancellableRequest269 /**270 * Execute the [Request] asynchronously, using the [handler], into a [String]271 * @param charset [Charset] the charset to use for the [String]272 * @param handler [Handler] the handler to report the [String] or [FuelError]273 * @return [CancellableRequest] the request in flight274 */275 fun responseString(charset: Charset = Charsets.UTF_8, handler: Handler<String>): CancellableRequest276 /**277 * Execute the [Request] asynchronously, using the [handler], into a [T]278 *279 * @param deserializer [ResponseDeserializable] instance that can turn [Response] into [T]280 * @param handler [ResponseResultHandler] the handler to report the [Request], [Response] and Result of [T]281 * @return [CancellableRequest] the request in flight282 */283 fun <T : Any> responseObject(deserializer: ResponseDeserializable<T>, handler: ResponseResultHandler<T>): CancellableRequest284 /**285 * Execute the [Request] asynchronously, using the [handler], into a [T]286 *287 * @param deserializer [ResponseDeserializable] instance that can turn [Response] into [T]288 * @param handler [ResponseHandler] the handler to report the [Request], [Response], and [T] or [FuelError]289 * @return [CancellableRequest] the request in flight290 */291 fun <T : Any> responseObject(deserializer: ResponseDeserializable<T>, handler: ResponseHandler<T>): CancellableRequest292 /**293 * Execute the [Request] asynchronously, using the [handler], into a [T]294 *295 * @param deserializer [ResponseDeserializable] instance that can turn [Response] into [T]296 * @param handler [ResultHandler] the handler to report the Result of [T]297 * @return [CancellableRequest] the request in flight298 */299 fun <T : Any> responseObject(deserializer: ResponseDeserializable<T>, handler: ResultHandler<T>): CancellableRequest300 /**301 * Execute the [Request] asynchronously, using the [handler], into a [T]302 *303 * @param deserializer [ResponseDeserializable] instance that can turn [Response] into [T]304 * @param handler [Handler] the handler to report the [T] or [FuelError]305 * @return [CancellableRequest] the request in flight306 */307 fun <T : Any> responseObject(deserializer: ResponseDeserializable<T>, handler: Handler<T>): CancellableRequest308 /**309 * Execute the [Request] synchronously, into a [ByteArray]310 *311 * @note this is a synchronous execution and can not be cancelled312 *313 * @return [ResponseResultOf] the response result of [ByteArray]314 */315 fun response(): ResponseResultOf<ByteArray>316 /**317 * Execute the [Request] synchronously, into a [String]318 *319 * @note this is a synchronous execution and can not be cancelled320 *321 * @param charset [Charset] the character set to use for the string322 * @return [ResponseResultOf] the response result of [String]323 */324 fun responseString(charset: Charset = Charsets.UTF_8): ResponseResultOf<String>325 /**326 * Execute the [Request] synchronously, into a [Charsets.UTF_8] [String]327 *328 * @note this is a synchronous execution and can not be cancelled329 *330 * @return [ResponseResultOf] the response result of [String]331 */332 fun responseString(): ResponseResultOf<String>333 /**334 * Execute the [Request] synchronously, into a [T]335 *336 * @note this is a synchronous execution and can not be cancelled337 *338 * @param deserializer [ResponseDeserializable] instance that can turn the [Response] into a [T]339 * @return [ResponseResultOf] the response result of [T]340 */341 fun <T : Any> responseObject(deserializer: ResponseDeserializable<T>): ResponseResultOf<T>342 /**343 * Sets the body to be read from a generic body source.344 *345 * @note in earlier versions the body callback would be called multiple times in order to maybe get the size. But346 * that would lead to closed streams being unable to be read. If the size is known, set it before anything else.347 *348 * @param openStream [BodySource] a function that yields a stream349 * @param calculateLength [Number?] size in +bytes+ if it is known350 * @param charset [Charset] the charset to write with351 * @param repeatable [Boolean] loads the body into memory upon reading352 *353 * @return [Request] the request354 */355 fun body(openStream: BodySource, calculateLength: BodyLength? = null, charset: Charset = Charsets.UTF_8, repeatable: Boolean = false): Request356 /**357 * Sets the body from a generic stream358 *359 * @note the stream will be read from the position it's at. Make sure you rewind it if you want it to be read from360 * the start.361 *362 * @param stream [InputStream] a stream to read from363 * @param calculateLength [Number?] size in bytes if it is known364 * @param charset [Charset] the charset to write with365 * @param repeatable [Boolean] loads the body into memory upon reading366 *367 * @return [Request] the request368 */369 fun body(stream: InputStream, calculateLength: BodyLength? = null, charset: Charset = Charsets.UTF_8, repeatable: Boolean = false): Request370 /**371 * Sets the body from a byte array372 *373 * @param bytes [ByteArray] the bytes to write374 * @param charset [Charset] the charset to write with375 * @return [Request] the request376 */377 fun body(bytes: ByteArray, charset: Charset = Charsets.UTF_8): Request378 /**379 * Sets the body from a string380 *381 * @param body [String] the string to write382 * @param charset [Charset] the charset to write with383 * @return [Request] the request384 */385 fun body(body: String, charset: Charset = Charsets.UTF_8): Request386 /**387 * Sets the body to the contents of a file.388 *389 * @note this does *NOT* make this a multipart upload. For that you can use the upload request. This function can be390 * used if you want to upload the single contents of a text based file as an inline body.391 *392 * @note when charset is not UTF-8, this forces the client to use chunked encoding, because file.length() gives the393 * length of the file in bytes without considering the charset. If the charset is to be considered, the file needs394 * to be read in its entirety which defeats the purpose of using a file.395 *396 * @param file [File] the file to write to the body397 * @param charset [Charset] the charset to write with398 * @return [Request] the request399 */400 fun body(file: File, charset: Charset = Charsets.UTF_8): Request401 /**402 * Sets the body to a defined [Body]403 *404 * @param body [Body] the body to assign405 * @return [Request] the request406 */407 fun body(body: Body): Request408 /**409 * Add a [InterruptCallback] to the [RequestExecutionOptions]410 *411 * @see RequestExecutionOptions.interruptCallbacks412 *413 * @return self414 */415 fun interrupt(interrupt: InterruptCallback): Request416 /**417 * Override a default [ResponseValidator] to the [RequestExecutionOptions]418 *419 * @see RequestExecutionOptions.responseValidator420 *421 * @return self422 */423 fun validate(validator: ResponseValidator): Request424 /**425 * Attach tag to the request426 *427 * @note tag is a generic purpose tagging for Request. This can be used to attach arbitrarily object to the Request instance.428 * @note Tags internally is represented as hashMap that uses class as a key.429 *430 * @param t [Any]431 * @return [Request] the modified request432 */433 fun tag(t: Any): Request...

Full Screen

Full Screen

DefaultRequest.kt

Source:DefaultRequest.kt Github

copy

Full Screen

...9import com.github.kittinunf.fuel.core.Method10import com.github.kittinunf.fuel.core.Parameters11import com.github.kittinunf.fuel.core.ProgressCallback12import com.github.kittinunf.fuel.core.Request13import com.github.kittinunf.fuel.core.RequestExecutionOptions14import com.github.kittinunf.fuel.core.RequestFeatures15import com.github.kittinunf.fuel.core.ResponseDeserializable16import com.github.kittinunf.fuel.core.ResponseHandler17import com.github.kittinunf.fuel.core.ResponseResultHandler18import com.github.kittinunf.fuel.core.ResponseValidator19import com.github.kittinunf.fuel.core.ResultHandler20import com.github.kittinunf.fuel.core.Tags21import com.github.kittinunf.fuel.core.deserializers.ByteArrayDeserializer22import com.github.kittinunf.fuel.core.deserializers.StringDeserializer23import com.github.kittinunf.fuel.core.response24import java.io.ByteArrayInputStream25import java.io.File26import java.io.FileInputStream27import java.io.InputStream28import java.net.URL29import java.net.URLConnection30import java.nio.charset.Charset31import kotlin.reflect.KClass32data class DefaultRequest(33 override val method: Method,34 override var url: URL,35 override val headers: Headers = Headers(),36 override var parameters: Parameters = listOf(),37 internal var _body: Body = DefaultBody(),38 override val enabledFeatures: RequestFeatures = mutableMapOf(),39 private val tags: Tags = mutableMapOf()40) : Request {41 override lateinit var executionOptions: RequestExecutionOptions42 override val body: Body get() = _body43 /**44 * Get the current values of the header, after normalisation of the header45 * @param header [String] the header name46 * @return the current values (or empty if none)47 */48 override operator fun get(header: String): HeaderValues {49 return headers[header]50 }51 /**52 * Set the values of the header, overriding what's there, after normalisation of the header53 *54 * @param header [String] the header name55 * @param values [Collection<*>] the values to be transformed through #toString56 * @return self57 */58 override operator fun set(header: String, values: Collection<*>): Request {59 headers[header] = values.map { it.toString() }60 return request61 }62 /**63 * Set the value of the header, overriding what's there, after normalisation of the header64 *65 * @param header [String] the header name66 * @param value [Any] the value to be transformed through #toString67 */68 override operator fun set(header: String, value: Any): Request {69 when (value) {70 is Collection<*> -> this[header] = value71 else -> headers[header] = value.toString()72 }73 return request74 }75 /**76 * Get the current values77 *78 * @see get(header: String)79 * @return [HeaderValues] the current values80 */81 override fun header(header: String) = get(header)82 /**83 * Replace the headers with the map provided84 *85 * @note In earlier versions the mapOf variant of this function worked differently than the vararg pairs variant,86 * which has been changed to make any call to header(...) always overwrite the values and any call to87 * appendHeader(...) will try to append the value.88 *89 * @see set(header: String, values: Collection<*>)90 * @see set(header: String, value: Any)91 *92 * @param map [Map<String, Any>] map of headers to replace. Value can be a list or single value93 * @return [Request] the modified request94 */95 override fun header(map: Map<String, Any>): Request {96 headers.putAll(Headers.from(map))97 return request98 }99 /**100 * Replace the headers with the pairs provided101 *102 * @note In earlier versions the mapOf variant of this function worked differently than the vararg pairs variant,103 * which has been changed to make any call to header(...) always overwrite the values and any call to104 * appendHeader(...) will try to append the value.105 *106 * @see set(header: String, values: Collection<*>)107 * @see set(header: String, value: Any)108 *109 * @param pairs [Pair<String, Any>] map of headers to replace. Value can be a list or single value110 * @return [Request] the modified request111 */112 override fun header(vararg pairs: Pair<String, Any>): Request {113 headers.putAll(Headers.from(*pairs))114 return request115 }116 /**117 * Replace the header with the provided values118 *119 * @see set(header: String, values: Collection<*>)120 *121 * @param header [String] the header to set122 * @param values [List<Any>] the values to set the header to123 * @return [Request] the modified request124 */125 override fun header(header: String, values: Collection<*>) = set(header, values)126 /**127 * Replace the header with the provided value128 *129 * @see set(header: String, values: List<Any>)130 *131 * @param header [String] the header to set132 * @param value [Any] the value to set the header to133 * @return [Request] the modified request134 */135 override fun header(header: String, value: Any): Request = set(header, value)136 /**137 * Replace the header with the provided values138 *139 * @see set(header: String, values: List<Any>)140 *141 * @param header [String] the header to set142 * @param values [Any] the values to set the header to143 * @return [Request] the modified request144 */145 override fun header(header: String, vararg values: Any) = set(header, values.toList())146 /**147 * Appends the value to the header or sets it if there was none yet148 *149 * @param header [String] the header name to append to150 * @param value [Any] the value to be transformed through #toString151 */152 override fun appendHeader(header: String, value: Any): Request {153 headers.append(header, value)154 return request155 }156 /**157 * Appends the value to the header or sets it if there was none yet158 *159 * @param header [String] the header name to append to160 * @param values [Any] the value to be transformed through #toString161 */162 override fun appendHeader(header: String, vararg values: Any): Request {163 headers.append(header, values.toList())164 return request165 }166 /**167 * Append each pair, using the key as header name and value as header content168 *169 * @param pairs [Pair<String, Any>]170 */171 override fun appendHeader(vararg pairs: Pair<String, Any>): Request {172 pairs.forEach { pair -> appendHeader(pair.first, pair.second) }173 return request174 }175 /**176 * Sets the body to be read from a generic body source.177 *178 * @note in earlier versions the body callback would be called multiple times in order to maybe get the size. But179 * that would lead to closed streams being unable to be read. If the size is known, set it before anything else.180 *181 * @param openStream [BodySource] a function that yields a stream182 * @param calculateLength [Number?] size in +bytes+ if it is known183 * @param charset [Charset] the charset to write with184 * @param repeatable [Boolean] loads the body into memory upon reading185 *186 * @return [Request] the request187 */188 override fun body(openStream: BodySource, calculateLength: BodyLength?, charset: Charset, repeatable: Boolean): Request {189 _body = DefaultBody190 .from(openStream = openStream, calculateLength = calculateLength, charset = charset)191 .let { body -> if (repeatable) body.asRepeatable() else body }192 return request193 }194 /**195 * Sets the body from a generic stream196 *197 * @note the stream will be read from the position it's at. Make sure you rewind it if you want it to be read from198 * the start.199 *200 * @param stream [InputStream] a stream to read from201 * @param calculateLength [Number?] size in bytes if it is known202 * @param charset [Charset] the charset to write with203 * @param repeatable [Boolean] loads the body into memory upon reading204 *205 * @return [Request] the request206 */207 override fun body(stream: InputStream, calculateLength: BodyLength?, charset: Charset, repeatable: Boolean) =208 body(openStream = { stream }, calculateLength = calculateLength, charset = charset, repeatable = repeatable)209 /**210 * Sets the body from a byte array211 *212 * @param bytes [ByteArray] the bytes to write213 * @param charset [Charset] the charset to write with214 * @return [Request] the request215 */216 override fun body(bytes: ByteArray, charset: Charset) =217 body(stream = ByteArrayInputStream(bytes), calculateLength = { bytes.size.toLong() }, charset = charset, repeatable = true)218 /**219 * Sets the body from a string220 *221 * @param body [String] the string to write222 * @param charset [Charset] the charset to write with223 * @return [Request] the request224 */225 override fun body(body: String, charset: Charset): Request =226 body(bytes = body.toByteArray(charset), charset = charset)227 .let {228 if (header(Headers.CONTENT_TYPE).lastOrNull().isNullOrBlank())229 header(Headers.CONTENT_TYPE, "text/plain; charset=${charset.name()}")230 else it231 }232 /**233 * Sets the body to the contents of a file.234 *235 * @note this does *NOT* make this a multipart upload. For that you can use the upload request. This function can be236 * used if you want to upload the single contents of a text based file as an inline body.237 *238 * @note when charset is not UTF-8, this forces the client to use chunked encoding, because file.length() gives the239 * length of the file in bytes without considering the charset. If the charset is to be considered, the file needs240 * to be read in its entirety which defeats the purpose of using a file.241 *242 * @param file [File] the file to write to the body243 * @param charset [Charset] the charset to write with244 * @return [Request] the request245 */246 override fun body(file: File, charset: Charset): Request = when (charset) {247 Charsets.UTF_8 -> body({ FileInputStream(file) }, { file.length() }, charset)248 else -> body({ FileInputStream(file) }, null, charset)249 }.let {250 if (header(Headers.CONTENT_TYPE).lastOrNull().isNullOrBlank()) {251 val contentType = URLConnection.guessContentTypeFromName(file.name)252 header(Headers.CONTENT_TYPE, "$contentType; charset=${charset.name()}")253 } else {254 it255 }256 }257 /**258 * Sets the body to a defined [Body]259 *260 * @param body [Body] the body to assign261 * @return [Request] the request262 */263 override fun body(body: Body): Request {264 _body = body265 return request266 }267 /**268 * Add a [ProgressCallback] tracking the [Body] of the [Request]269 *270 * @see body271 * @see com.github.kittinunf.fuel.core.requests.UploadRequest.progress272 *273 * @return self274 */275 override fun requestProgress(handler: ProgressCallback): Request {276 executionOptions.requestProgress += handler277 return request278 }279 /**280 * Add a [ProgressCallback] tracking the [Body] of the [com.github.kittinunf.fuel.core.Response]281 *282 * @see com.github.kittinunf.fuel.core.requests.DownloadRequest.progress283 *284 * @return self285 */286 override fun responseProgress(handler: ProgressCallback): Request {287 executionOptions.responseProgress += handler288 return request289 }290 /**291 * Add a [InterruptCallback] to the [RequestExecutionOptions]292 *293 * @see RequestExecutionOptions.interruptCallbacks294 *295 * @return self296 */297 override fun interrupt(interrupt: InterruptCallback) = request.also {298 it.executionOptions.interruptCallbacks.plusAssign(interrupt)299 }300 /**301 * Overwrite the [Request] [timeout] in milliseconds302 *303 * @note [com.github.kittinunf.fuel.core.Client] must implement this behaviour304 * @note the default client sets [java.net.HttpURLConnection.setConnectTimeout]305 *306 * @param timeout [Int] timeout in milliseconds307 * @return self308 */309 override fun timeout(timeout: Int) = request.also {310 it.executionOptions.timeoutInMillisecond = timeout311 }312 /**313 * Overwrite the [Request] [timeout] in milliseconds314 *315 * @note [com.github.kittinunf.fuel.core.Client] must implement this behaviour316 * @note the default client sets [java.net.HttpURLConnection.setReadTimeout]317 *318 * @param timeout [Int] timeout in milliseconds319 * @return self320 */321 override fun timeoutRead(timeout: Int) = request.also {322 it.executionOptions.timeoutReadInMillisecond = timeout323 }324 /**325 * Follow redirects as handled by instances of RedirectInterceptors326 * i.e. [com.github.kittinunf.fuel.core.interceptors.redirectResponseInterceptor]327 *328 * @note The interceptor must implement this behaviour329 * @note The provided RedirectResponseInterceptor defaults to true330 *331 * @param allowRedirects [Boolean] true if allowing, false if not332 * @return self333 */334 override fun allowRedirects(allowRedirects: Boolean) = request.also {335 it.executionOptions.allowRedirects = allowRedirects336 }337 /**338 * Overwrite [RequestExecutionOptions] http cache usage flag339 *340 * @note [com.github.kittinunf.fuel.core.Client] must implement this behaviour341 * @note The default client sends `Cache-Control: none` if this flag is false, defaults to true342 *343 * @see java.net.HttpURLConnection.setUseCaches344 * @param useHttpCache [Boolean] true if suggest client to allow cached responses, false otherwise345 */346 override fun useHttpCache(useHttpCache: Boolean) = request.also {347 it.executionOptions.useHttpCache = useHttpCache348 }349 /**350 * Overwrite [RequestExecutionOptions] response validator block351 *352 * @note The default responseValidator is to throw [com.github.kittinunf.fuel.core.HttpException]353 * @note if the response http status code is not in the range of (100 - 399) which should consider as failure response354 *355 * @param validator [ResponseValidator]356 * @return [Request] the modified request357 */358 override fun validate(validator: ResponseValidator) = request.also {359 it.executionOptions.responseValidator = validator360 }361 /**362 * Attach tag to the request363 *364 * @note tag is a generic purpose tagging for Request. This can be used to attach arbitrarily object to the Request instance....

Full Screen

Full Screen

FuelManager.kt

Source:FuelManager.kt Github

copy

Full Screen

...166 val unsetBaseHeaders = request.headers.keys.fold(Headers.from(baseHeaders.orEmpty())) {167 result, it -> result.remove(it); result168 }169 return request.header(unsetBaseHeaders).apply {170 executionOptions = RequestExecutionOptions(171 client = client,172 socketFactory = socketFactory,173 hostnameVerifier = hostnameVerifier,174 callbackExecutor = callbackExecutor,175 requestTransformer = requestInterceptors.foldRight({ r: Request -> r }) { f, acc -> f(acc) },176 responseTransformer = responseInterceptors.foldRight({ _: Request, res: Response -> res }) { f, acc -> f(acc) },177 executorService = executorService178 ).also { executor ->179 executor.timeoutInMillisecond = timeoutInMillisecond180 executor.timeoutReadInMillisecond = timeoutReadInMillisecond181 executor.forceMethods = forceMethods182 }183 }184 }...

Full Screen

Full Screen

RequestExecutionOptions.kt

Source:RequestExecutionOptions.kt Github

copy

Full Screen

...8typealias RequestTransformer = (Request) -> Request9typealias ResponseTransformer = (Request, Response) -> Response10typealias InterruptCallback = (Request) -> Unit11typealias ResponseValidator = (Response) -> Boolean12data class RequestExecutionOptions(13 val client: Client,14 val socketFactory: SSLSocketFactory? = null,15 val hostnameVerifier: HostnameVerifier? = null,16 val executorService: ExecutorService,17 val callbackExecutor: Executor,18 val requestTransformer: RequestTransformer,19 var responseTransformer: ResponseTransformer20) {21 val requestProgress: Progress = Progress()22 val responseProgress: Progress = Progress()23 var timeoutInMillisecond: Int = 15_00024 var timeoutReadInMillisecond: Int = 15_00025 var decodeContent: Boolean? = null26 var allowRedirects: Boolean? = null...

Full Screen

Full Screen

FuelTransport.kt

Source:FuelTransport.kt Github

copy

Full Screen

1package com.hylamobile.voorhees.client23import com.github.kittinunf.fuel.core.RequestExecutionOptions4import com.github.kittinunf.fuel.core.extensions.jsonBody5import com.github.kittinunf.fuel.httpPost6import com.hylamobile.voorhees.jsonrpc.Request7import com.hylamobile.voorhees.jsonrpc.jsonString8import java.nio.charset.Charset910class FuelTransport(serverConfig: ServerConfig) : Transport(serverConfig) {1112 override fun getResponseAsString(request: Request): String =13 serverConfig.url.httpPost()14 .apply { updateOptions(executionOptions) }15 .jsonBody(request.jsonString)16 .response()17 .third18 .get().toString(Charset.forName("UTF-8"))1920 private fun updateOptions(options: RequestExecutionOptions) {21 serverConfig.connectTimeout?.also { options.timeoutInMillisecond = it }22 serverConfig.readTimeout?.also { options.timeoutReadInMillisecond = it }23 }24} ...

Full Screen

Full Screen

RequestExecutionOptions

Using AI Code Generation

copy

Full Screen

1RequestExecutionOptions().apply { followRedirects = true }2RequestExecutionOptions().apply { followRedirects = false }3RequestExecutionOptions().apply { followRedirects = true }4RequestExecutionOptions().apply { followRedirects = false }5RequestExecutionOptions().apply { followRedirects = true }6RequestExecutionOptions().apply { followRedirects = false }7RequestExecutionOptions().apply { followRedirects = true }8RequestExecutionOptions().apply { followRedirects = false }9RequestExecutionOptions().apply { followRedirects = true }10RequestExecutionOptions().apply { followRedirects = false }11RequestExecutionOptions().apply { followRedirects = true }12RequestExecutionOptions().apply { followRedirects = false }13RequestExecutionOptions().apply { followRedirects = true }14RequestExecutionOptions().apply { followRedirects = false }15RequestExecutionOptions().apply { followRedirects = true }

Full Screen

Full Screen

RequestExecutionOptions

Using AI Code Generation

copy

Full Screen

1RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }2RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }3RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }4RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }5RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }6RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }7RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }8RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }9RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }10RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }11RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }12RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }13RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }14RequestExecutionOptions().apply { timeoutReadInMillisecond = 1000 }

Full Screen

Full Screen

RequestExecutionOptions

Using AI Code Generation

copy

Full Screen

1RequestExecutionOptions().apply {2}3RequestExecutionOptions().apply {4}5RequestExecutionOptions().apply {6}7RequestExecutionOptions().apply {8}9RequestExecutionOptions().apply {10}11RequestExecutionOptions().apply {12}13RequestExecutionOptions().apply {14}15RequestExecutionOptions().apply {16}17RequestExecutionOptions().apply {18}19RequestExecutionOptions().apply {20}21RequestExecutionOptions().apply {22}23RequestExecutionOptions().apply {24}25RequestExecutionOptions().apply {26}27RequestExecutionOptions().apply {28}

Full Screen

Full Screen

RequestExecutionOptions

Using AI Code Generation

copy

Full Screen

1RequestExecutionOptions().apply { 2}3RequestExecutionOptions().apply { 4}5RequestExecutionOptions().apply { 6}7RequestExecutionOptions().apply { 8}9RequestExecutionOptions().apply { 10}11RequestExecutionOptions().apply { 12}13RequestExecutionOptions().apply { 14}15RequestExecutionOptions().apply { 16}17RequestExecutionOptions().apply { 18}19RequestExecutionOptions().apply {

Full Screen

Full Screen

RequestExecutionOptions

Using AI Code Generation

copy

Full Screen

1RequestExecutionOptions().apply {2}3RequestExecutionOptions().apply {4}5RequestExecutionOptions().apply {6}7RequestExecutionOptions().apply {8}9RequestExecutionOptions().apply {10}11RequestExecutionOptions().apply {12}13RequestExecutionOptions().apply {14}15RequestExecutionOptions().apply {16}17RequestExecutionOptions().apply {

Full Screen

Full Screen

RequestExecutionOptions

Using AI Code Generation

copy

Full Screen

1RequestExecutionOptions().apply {2parameters = listOf("param1" to "value1", "param2" to "value2")3headers = listOf("header1" to "value1", "header2" to "value2")4cookies = listOf("cookie1" to "value1", "cookie2" to "value2")5}6RequestExecutionOptions().apply {7parameters = listOf("param1" to "value1", "param2" to "value2")8headers = listOf("header1" to "value1", "header2" to "value2")9cookies = listOf("cookie1" to "value1", "cookie2" to "value2")10}11RequestExecutionOptions().apply {12parameters = listOf("param1" to "value1", "param2" to "value2")13headers = listOf("header1" to "value1", "header2" to "value2")14cookies = listOf("cookie1" to "value1", "cookie2" to "value2")15}16RequestExecutionOptions().apply {17parameters = listOf("param1" to "value1", "param2" to "value2")18headers = listOf("header1" to "value1", "header2" to "value2")19cookies = listOf("cookie1" to "value1", "cookie2" to "value2")20}21RequestExecutionOptions().apply {22parameters = listOf("param1" to "value1", "param2" to "value2")23headers = listOf("header1" to "

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Fuel automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in RequestExecutionOptions

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful