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

View file

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