@@ -41,70 +41,69 @@ class MediaApiClient(val timeout: Timeout = Timeout.DEFAULT, val retry: Retry =
41
41
42
42
private val log = KotlinLogging .logger {}
43
43
44
- private val client =
45
- HttpClient {
46
- install(Resources )
47
- install(ContentNegotiation ) { json(dev.suresh.json) }
48
-
49
- install(ContentEncoding ) {
50
- deflate(1.0F )
51
- gzip(0.9F )
52
- }
53
-
54
- install(HttpRequestRetry ) {
55
- maxRetries = retry.attempts
56
- retryOnException(retryOnTimeout = true )
57
- retryOnServerErrors()
58
- constantDelay(millis = retry.maxDelay.inWholeMilliseconds)
59
- }
60
-
61
- install(HttpTimeout ) {
62
- connectTimeoutMillis = timeout.connection.inWholeMilliseconds
63
- requestTimeoutMillis = timeout.read.inWholeMilliseconds
64
- socketTimeoutMillis = timeout.write.inWholeMilliseconds
65
- }
66
-
67
- install(HttpCookies )
68
-
69
- install(Logging ) {
70
- logger = Logger .DEFAULT
71
- level = LogLevel .INFO
72
- sanitizeHeader { header -> header == HttpHeaders .Authorization }
73
- }
74
-
75
- engine { pipelining = true }
76
-
77
- followRedirects = true
78
-
79
- install(UserAgent ) { agent = " Image API Client" }
80
-
81
- install(DefaultRequest ) {
82
- url(" https://suresh.dev/" )
83
- headers.appendIfNameAndValueAbsent(
84
- HttpHeaders .ContentType , ContentType .Application .Json .toString())
85
- }
86
-
87
- // install(Auth) {
88
- // basic {
89
- // credentials {
90
- // sendWithoutRequest { true }
91
- // BasicAuthCredentials(username = "", password = "")
92
- // }
93
- // }
94
- // }
95
- //
96
- // expectSuccess = false
97
- //
98
- // HttpResponseValidator {
99
- // validateResponse {
100
- // when (it.status.value) {
101
- // in 300..399 -> throw RedirectResponseException(it, "Redirect error")
102
- // in 400..499 -> throw ClientRequestException(it, "Client error")
103
- // in 500..599 -> throw ServerResponseException(it, "Server error")
104
- // }
105
- // }
106
- // }
107
- }
44
+ private val client = HttpClient {
45
+ install(Resources )
46
+ install(ContentNegotiation ) { json(dev.suresh.json) }
47
+
48
+ install(ContentEncoding ) {
49
+ deflate(1.0F )
50
+ gzip(0.9F )
51
+ }
52
+
53
+ install(HttpRequestRetry ) {
54
+ maxRetries = retry.attempts
55
+ retryOnException(retryOnTimeout = true )
56
+ retryOnServerErrors()
57
+ constantDelay(millis = retry.maxDelay.inWholeMilliseconds)
58
+ }
59
+
60
+ install(HttpTimeout ) {
61
+ connectTimeoutMillis = timeout.connection.inWholeMilliseconds
62
+ requestTimeoutMillis = timeout.read.inWholeMilliseconds
63
+ socketTimeoutMillis = timeout.write.inWholeMilliseconds
64
+ }
65
+
66
+ install(HttpCookies )
67
+
68
+ install(Logging ) {
69
+ logger = Logger .DEFAULT
70
+ level = LogLevel .INFO
71
+ sanitizeHeader { header -> header == HttpHeaders .Authorization }
72
+ }
73
+
74
+ engine { pipelining = true }
75
+
76
+ followRedirects = true
77
+
78
+ install(UserAgent ) { agent = " Image API Client" }
79
+
80
+ install(DefaultRequest ) {
81
+ url(" https://suresh.dev/" )
82
+ headers.appendIfNameAndValueAbsent(
83
+ HttpHeaders .ContentType , ContentType .Application .Json .toString())
84
+ }
85
+
86
+ // install(Auth) {
87
+ // basic {
88
+ // credentials {
89
+ // sendWithoutRequest { true }
90
+ // BasicAuthCredentials(username = "", password = "")
91
+ // }
92
+ // }
93
+ // }
94
+ //
95
+ // expectSuccess = false
96
+ //
97
+ // HttpResponseValidator {
98
+ // validateResponse {
99
+ // when (it.status.value) {
100
+ // in 300..399 -> throw RedirectResponseException(it, "Redirect error")
101
+ // in 400..499 -> throw ClientRequestException(it, "Client error")
102
+ // in 500..599 -> throw ServerResponseException(it, "Server error")
103
+ // }
104
+ // }
105
+ // }
106
+ }
108
107
109
108
suspend fun images () = client.get(ImgRes ()).body<List <Image >>()
110
109
0 commit comments