1
0
Fork 0
mirror of https://git.sr.ht/~oppen/ariane synced 2024-12-27 02:10:30 +00:00

handle redirects

This commit is contained in:
Öppen 2020-08-18 20:06:08 +01:00
parent 861d3a8619
commit 079022112f
2 changed files with 13 additions and 10 deletions

View file

@ -99,7 +99,6 @@ class GeminiDatasource: Datasource{
return return
} }
// OUT >>>>>>>>>>>>>>>>>>>>>>>>>> // OUT >>>>>>>>>>>>>>>>>>>>>>>>>>
val outputStreamWriter = OutputStreamWriter(socket.outputStream) val outputStreamWriter = OutputStreamWriter(socket.outputStream)
val bufferedWriter = BufferedWriter(outputStreamWriter) val bufferedWriter = BufferedWriter(outputStreamWriter)
@ -132,6 +131,7 @@ class GeminiDatasource: Datasource{
val header = GeminiResponse.parseHeader(headerLine) val header = GeminiResponse.parseHeader(headerLine)
when { when {
header.code == GeminiResponse.REDIRECT -> request(URI.create(header.meta), onUpdate)
header.code != GeminiResponse.SUCCESS -> onUpdate(TvaState.ResponseError(header)) header.code != GeminiResponse.SUCCESS -> onUpdate(TvaState.ResponseError(header))
header.meta.startsWith("text/gemini") -> getGemtext(socket, uri, header, onUpdate) header.meta.startsWith("text/gemini") -> getGemtext(socket, uri, header, onUpdate)
header.meta.startsWith("text/") -> getString(socket, uri, header, onUpdate) header.meta.startsWith("text/") -> getString(socket, uri, header, onUpdate)

View file

@ -12,16 +12,19 @@ object GeminiResponse {
fun parseHeader(header: String): Header{ fun parseHeader(header: String): Header{
var meta = "" var meta = ""
if(header.startsWith("2")){ when {
val segments = header.trim().split(" ") header.startsWith("2") -> {
meta = when { val segments = header.trim().split(" ")
segments.size > 1 -> segments[1] meta = when {
else -> "text/gemini; charset=utf-8" segments.size > 1 -> segments[1]
else -> "text/gemini; charset=utf-8"
}
} }
}else{ else -> {
meta = when { meta = when {
header.contains(" ") -> header.substring(meta.indexOf(" ") + 1) header.contains(" ") -> header.substring(header.indexOf(" ") + 1)
else -> header else -> header
}
} }
} }