Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Add Authorization header to API requests #142

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/main/kotlin/fr/jais/scraper/utils/API.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ object API {
}

private fun post(url: String, json: String): HttpResponse<String> {
val request = HttpRequest.newBuilder()
val requestBuilder = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))

if (!Const.secureKey.isNullOrBlank()) {
requestBuilder.header("Authorization", Const.secureKey)
}

val request = requestBuilder.POST(HttpRequest.BodyPublishers.ofString(json))
.build()
return Const.httpClient.send(request, HttpResponse.BodyHandlers.ofString())
}
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/fr/jais/scraper/utils/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ object Const {
val multipleSpaceRegex = "\\s+".toRegex()
const val calendarBaseUrl = "https://anime.icotaku.com"
val apiUrl = System.getenv("API_URL") ?: "http://localhost:8080/"
val secureKey: String? = System.getenv("SECURE_KEY")
}