Skip to content

Commit 99c997c

Browse files
fviernausschuberth
authored andcommitted
refactor(fossid-webapp): Move TimeoutInterceptor to top level
Improve the readability of the service interface. Signed-off-by: Frank Viernau <[email protected]>
1 parent 9f1bfe4 commit 99c997c

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

clients/fossid-webapp/src/main/kotlin/FossIdRestService.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,6 @@ interface FossIdRestService {
115115
}
116116
}
117117

118-
/**
119-
* An interceptor to set the timeout of the requests based on the call headers. If no timeout header is present,
120-
* default timeout of the client is used.
121-
*/
122-
object TimeoutInterceptor : Interceptor {
123-
override fun intercept(chain: Interceptor.Chain): okhttp3.Response {
124-
val request = chain.request()
125-
val newReadTimeout = request.header(READ_TIMEOUT_HEADER)
126-
127-
val readTimeout = newReadTimeout?.toIntOrNull() ?: chain.readTimeoutMillis()
128-
129-
return chain.withReadTimeout(readTimeout, TimeUnit.MILLISECONDS).proceed(request)
130-
}
131-
}
132-
133118
@POST("api.php")
134119
suspend fun getProject(@Body body: PostRequestBody): PolymorphicDataResponseBody<Project>
135120

@@ -238,3 +223,18 @@ interface FossIdRestService {
238223
@GET("index.php?form=login")
239224
suspend fun getLoginPage(): ResponseBody
240225
}
226+
227+
/**
228+
* An interceptor to set the timeout of the requests based on the call headers. If no timeout header is present,
229+
* default timeout of the client is used.
230+
*/
231+
private object TimeoutInterceptor : Interceptor {
232+
override fun intercept(chain: Interceptor.Chain): okhttp3.Response {
233+
val request = chain.request()
234+
val newReadTimeout = request.header(READ_TIMEOUT_HEADER)
235+
236+
val readTimeout = newReadTimeout?.toIntOrNull() ?: chain.readTimeoutMillis()
237+
238+
return chain.withReadTimeout(readTimeout, TimeUnit.MILLISECONDS).proceed(request)
239+
}
240+
}

0 commit comments

Comments
 (0)