|
| 1 | +package ru.epserv.proxycheck.v3.impl |
| 2 | + |
| 3 | +import org.jetbrains.annotations.ApiStatus |
| 4 | +import java.net.ProxySelector |
| 5 | +import java.net.URI |
| 6 | +import kotlin.time.Duration |
| 7 | +import kotlin.time.Duration.Companion.minutes |
| 8 | +import kotlin.time.Duration.Companion.seconds |
| 9 | + |
| 10 | +/** |
| 11 | + * Configuration for [ProxyCheckApiImpl]. |
| 12 | + * |
| 13 | + * @property connection connection establishment configuration |
| 14 | + * @property timeout configuration for various timeouts |
| 15 | + * @property unsupported configuration settings that may result in untested and/or unstable behavior |
| 16 | + * @since 1.0.0 |
| 17 | + * @author metabrix |
| 18 | + */ |
| 19 | +@ApiStatus.AvailableSince("1.0.0") |
| 20 | +data class ProxyCheckApiImplConfiguration( |
| 21 | + var connection: ConnectionConfiguration = ConnectionConfiguration(), |
| 22 | + var timeout: TimeoutConfiguration = TimeoutConfiguration(), |
| 23 | + var unsupported: UnsupportedConfiguration = UnsupportedConfiguration(), |
| 24 | +) { |
| 25 | + /** |
| 26 | + * Updates the connection establishment configuration. |
| 27 | + * |
| 28 | + * @param configure configuration action |
| 29 | + * @since 1.0.0 |
| 30 | + * @author metabrix |
| 31 | + */ |
| 32 | + @ApiStatus.AvailableSince("1.0.0") |
| 33 | + fun connection(configure: ConnectionConfiguration.() -> Unit) { |
| 34 | + this.connection.apply(configure) |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Updates the timeout configuration. |
| 39 | + * |
| 40 | + * @param block configuration action |
| 41 | + * @since 1.0.0 |
| 42 | + * @author metabrix |
| 43 | + */ |
| 44 | + @ApiStatus.AvailableSince("1.0.0") |
| 45 | + fun timeout(block: TimeoutConfiguration.() -> Unit) { |
| 46 | + this.timeout.apply(block) |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Updates the unsupported configuration. |
| 51 | + * |
| 52 | + * @param block configuration action |
| 53 | + * @since 1.0.0 |
| 54 | + * @author metabrix |
| 55 | + */ |
| 56 | + @ApiStatus.AvailableSince("1.0.0") |
| 57 | + fun unsupported(block: UnsupportedConfiguration.() -> Unit) { |
| 58 | + this.unsupported.apply(block) |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Connection establishment configuration. |
| 63 | + * |
| 64 | + * @property apiEndpoint API endpoint URI, defaults to `https://proxycheck.io/v3/` |
| 65 | + * @property proxySelector proxy selector, defaults to the system default |
| 66 | + * @since 1.0.0 |
| 67 | + * @author metabrix |
| 68 | + */ |
| 69 | + @ApiStatus.AvailableSince("1.0.0") |
| 70 | + data class ConnectionConfiguration( |
| 71 | + @ApiStatus.AvailableSince("1.0.0") |
| 72 | + var apiEndpoint: URI = URI.create("https://proxycheck.io/v3/"), |
| 73 | + @ApiStatus.AvailableSince("1.0.0") |
| 74 | + var proxySelector: ProxySelector = ProxySelector.getDefault(), |
| 75 | + ) |
| 76 | + |
| 77 | + /** |
| 78 | + * Configuration for various timeouts. |
| 79 | + * |
| 80 | + * @property connectTimeout connection establishment timeout, defaults to 10 seconds |
| 81 | + * @property readTimeout read timeout, defaults to 10 seconds |
| 82 | + * @property shutdownTimeout timeout for graceful shutdown, defaults to 1 minute |
| 83 | + * @since 1.0.0 |
| 84 | + * @author metabrix |
| 85 | + */ |
| 86 | + @ApiStatus.AvailableSince("1.0.0") |
| 87 | + data class TimeoutConfiguration( |
| 88 | + @ApiStatus.AvailableSince("1.0.0") |
| 89 | + var connectTimeout: Duration = 10.seconds, |
| 90 | + @ApiStatus.AvailableSince("1.0.0") |
| 91 | + var readTimeout: Duration = 10.seconds, |
| 92 | + @ApiStatus.AvailableSince("1.0.0") |
| 93 | + var shutdownTimeout: Duration = 1.minutes, |
| 94 | + ) |
| 95 | + |
| 96 | + /** |
| 97 | + * Configuration settings that may result in untested and/or unstable behavior. |
| 98 | + * |
| 99 | + * @property apiVersion API version override, defaults to the version that this library build |
| 100 | + * is targeting. While older or newer versions may work just fine, the library was not |
| 101 | + * tested against them and provides no stability guarantees. |
| 102 | + * @since 1.0.0 |
| 103 | + * @author metabrix |
| 104 | + */ |
| 105 | + @ApiStatus.AvailableSince("1.0.0") |
| 106 | + data class UnsupportedConfiguration( |
| 107 | + @ApiStatus.AvailableSince("1.0.0") |
| 108 | + var apiVersion: String = "12-August-2025", |
| 109 | + ) |
| 110 | +} |
0 commit comments