From fed338e91e05793d04445be7601b25a1ee36d70d Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 20 Feb 2024 09:54:38 +0100 Subject: [PATCH] refactor(ort-utils): Extract common request builder code While originally the `put` code did not have a `cacheControl`, it should not hurt to have it there. Signed-off-by: Sebastian Schuberth --- .../ort/src/main/kotlin/storage/HttpFileStorage.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/utils/ort/src/main/kotlin/storage/HttpFileStorage.kt b/utils/ort/src/main/kotlin/storage/HttpFileStorage.kt index 0e03034f93476..0cb0f87406396 100644 --- a/utils/ort/src/main/kotlin/storage/HttpFileStorage.kt +++ b/utils/ort/src/main/kotlin/storage/HttpFileStorage.kt @@ -80,10 +80,13 @@ class HttpFileStorage( } } - override fun exists(path: String): Boolean { - val request = Request.Builder() + private fun requestBuilder(): Request.Builder = + Request.Builder() .headers(headers.toHeaders()) .cacheControl(CacheControl.Builder().maxAge(cacheMaxAgeInSeconds, TimeUnit.SECONDS).build()) + + override fun exists(path: String): Boolean { + val request = requestBuilder() .head() .url(urlForPath(path)) .build() @@ -92,9 +95,7 @@ class HttpFileStorage( } override fun read(path: String): InputStream { - val request = Request.Builder() - .headers(headers.toHeaders()) - .cacheControl(CacheControl.Builder().maxAge(cacheMaxAgeInSeconds, TimeUnit.SECONDS).build()) + val request = requestBuilder() .get() .url(urlForPath(path)) .build() @@ -117,8 +118,7 @@ class HttpFileStorage( override fun write(path: String, inputStream: InputStream) { inputStream.use { - val request = Request.Builder() - .headers(headers.toHeaders()) + val request = requestBuilder() .put(it.readBytes().toRequestBody()) .url(urlForPath(path)) .build()