1
0
Fork 0
mirror of https://github.com/Corewala/Buran synced 2024-12-22 07:42:43 +00:00

Fixed redirect drop bug

This commit is contained in:
Corewala 2023-02-04 19:46:26 -05:00
parent 0fdffee966
commit 73afc7c684

View file

@ -133,7 +133,7 @@ class GeminiDatasource(private val context: Context, val history: BuranHistory):
val bufferedReader = BufferedReader(headerInputReader)
val headerLine = bufferedReader.readLine()
println("Buran: response header: $headerLine")
println("Buran response header: $headerLine")
if(headerLine == null){
if(currentRequestAddress == uri.toString()){
@ -144,23 +144,27 @@ class GeminiDatasource(private val context: Context, val history: BuranHistory):
val header = GeminiResponse.parseHeader(headerLine)
when {
currentRequestAddress != uri.toString() -> {}
header.code == GeminiResponse.INPUT -> onUpdate(GemState.ResponseInput(uri, header))
header.code == GeminiResponse.REDIRECT -> onUpdate(GemState.Redirect(header.meta))
header.code == GeminiResponse.CLIENT_CERTIFICATE_REQUIRED -> onUpdate(GemState.ClientCertRequired(uri, header))
header.code != GeminiResponse.SUCCESS -> onUpdate(GemState.ResponseError(header))
header.meta.startsWith("text/gemini") -> getGemtext(bufferedReader, requestEntity.trim().toURI(), header, onUpdate)
header.meta.startsWith("text/") -> getString(socket, uri, header, onUpdate)
header.meta.startsWith("image/") -> getBinary(socket, uri, header, onUpdate)
else -> {
//File served over Gemini but not handled in-app, eg .pdf
if(forceDownload){
getBinary(socket, uri, header, onUpdate)
}else{
onUpdate(GemState.ResponseUnknownMime(uri, header))
if(currentRequestAddress == uri.toString()){
currentRequestAddress = null
when {
header.code == GeminiResponse.INPUT -> onUpdate(GemState.ResponseInput(uri, header))
header.code == GeminiResponse.REDIRECT -> onUpdate(GemState.Redirect(header.meta))
header.code == GeminiResponse.CLIENT_CERTIFICATE_REQUIRED -> onUpdate(GemState.ClientCertRequired(uri, header))
header.code != GeminiResponse.SUCCESS -> onUpdate(GemState.ResponseError(header))
header.meta.startsWith("text/gemini") -> getGemtext(bufferedReader, requestEntity.trim().toURI(), header, onUpdate)
header.meta.startsWith("text/") -> getString(socket, uri, header, onUpdate)
header.meta.startsWith("image/") -> getBinary(socket, uri, header, onUpdate)
else -> {
//File served over Gemini but not handled in-app, eg .pdf
if(forceDownload){
getBinary(socket, uri, header, onUpdate)
}else{
onUpdate(GemState.ResponseUnknownMime(uri, header))
}
}
}
}else{
println("Buran dropped response from $uri: request cancelled or superseded")
}
//Close input
@ -172,7 +176,6 @@ class GeminiDatasource(private val context: Context, val history: BuranHistory):
bufferedWriter.close()
outWriter.close()
currentRequestAddress = null
socket.close()
}