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

Commit

Permalink
Add Authorization header to API requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Sep 28, 2023
1 parent 67ab9d0 commit a1cd615
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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")
}

0 comments on commit a1cd615

Please sign in to comment.