Skip to content

Commit

Permalink
refactor(ort-utils): Extract common request builder code
Browse files Browse the repository at this point in the history
While originally the `put` code did not have a `cacheControl`, it should
not hurt to have it there.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Feb 20, 2024
1 parent b4675eb commit ca1b12c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions utils/ort/src/main/kotlin/storage/HttpFileStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit ca1b12c

Please sign in to comment.