Fix HTTP/0.9 when not allowed errors (#253)
* Fix `HTTP/0.9 when not allowed` errors * tweak retry callback * throw ex in debug mode
This commit is contained in:
1 parent
575935f5ac
commit
86d5710969
3 files changed
+48
-1
No files matched your search
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- A home screen editor allowing to enable/disable feeds, and change their order.
|
- A home screen editor allowing to enable/disable feeds, and change their order.
|
||||||
- The editor can be accessed from the Settings screen.
|
- The editor can be accessed from the Settings screen.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- `HTTP/0.9 when not allowed` errors by adding a retry to web requests
|
||||||
|
|
||||||
## [0.18.1] - 2024-01-02
|
## [0.18.1] - 2024-01-02
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -123,6 +123,21 @@ namespace Invidious
|
|||||||
request.CacheSeconds(60 * 60 * 5)
|
request.CacheSeconds(60 * 60 * 5)
|
||||||
request.Cancellation(cancellation)
|
request.Cancellation(cancellation)
|
||||||
|
|
||||||
|
request.TryCount(2)
|
||||||
|
request.RetryCallback(function(context as object) as boolean
|
||||||
|
response = context.response
|
||||||
|
' In some cases, video info requests return "HTTP/0.9 when not allowed" errors.
|
||||||
|
' Retrying should usually fix the issue.
|
||||||
|
if response.StatusCode() = HttpClient.CurlErrors.CURLE_UNSUPPORTED_PROTOCOL
|
||||||
|
errorMessage = response.ErrorMessage()
|
||||||
|
if errorMessage.Contains("HTTP/0.9")
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
|
return false
|
||||||
|
end function)
|
||||||
|
|
||||||
return request.Await()
|
return request.Await()
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#const DISABLE_CACHE = false
|
#const DISABLE_CACHE = false
|
||||||
|
|
||||||
import "pkg:/source/utils/CryptoUtils.bs"
|
import "pkg:/source/utils/CryptoUtils.bs"
|
||||||
|
import "pkg:/source/utils/ErrorUtils.bs"
|
||||||
import "pkg:/source/utils/Logging.bs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
import "pkg:/source/utils/StringUtils.bs"
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
@@ -237,6 +238,11 @@ namespace HttpClient
|
|||||||
return m
|
return m
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function RetryCallback(callback as function) as HttpRequest
|
||||||
|
m._retryCallback = callback
|
||||||
|
return m
|
||||||
|
end function
|
||||||
|
|
||||||
function NoCache() as HttpRequest
|
function NoCache() as HttpRequest
|
||||||
m._noCache = true
|
m._noCache = true
|
||||||
return m
|
return m
|
||||||
@@ -368,7 +374,7 @@ namespace HttpClient
|
|||||||
response = invalid
|
response = invalid
|
||||||
|
|
||||||
response = m.AwaitInternal()
|
response = m.AwaitInternal()
|
||||||
if response.IsSuccess() or response.TimedOut() or response.IsCancelled() or response.StatusCode() < 500
|
if response.IsSuccess() or response.TimedOut() or response.IsCancelled()
|
||||||
return response
|
return response
|
||||||
end if
|
end if
|
||||||
triesLeft -= 1
|
triesLeft -= 1
|
||||||
@@ -378,6 +384,28 @@ namespace HttpClient
|
|||||||
tryNumber = m._tryCount - triesLeft + 1
|
tryNumber = m._tryCount - triesLeft + 1
|
||||||
LogInfo("Request failed ID:", m.urlTransfer.GetIdentity(), "ErrorMessage:", response.ErrorMessage(), `\nRetrying: (`, tryNumber, "/", m._tryCount, ") in", backoffMs, "ms")
|
LogInfo("Request failed ID:", m.urlTransfer.GetIdentity(), "ErrorMessage:", response.ErrorMessage(), `\nRetrying: (`, tryNumber, "/", m._tryCount, ") in", backoffMs, "ms")
|
||||||
|
|
||||||
|
if IsFunction(m._retryCallback)
|
||||||
|
try
|
||||||
|
shouldRetry = m._retryCallback({
|
||||||
|
tryNumber: tryNumber
|
||||||
|
tryCount: m._tryCount
|
||||||
|
request: m
|
||||||
|
response: response
|
||||||
|
})
|
||||||
|
|
||||||
|
if IsBool(shouldRetry) and not shouldRetry
|
||||||
|
LogInfo("Retry callback returned false. Not retrying.")
|
||||||
|
return response
|
||||||
|
end if
|
||||||
|
catch error
|
||||||
|
#if DEBUG
|
||||||
|
throw error
|
||||||
|
#else
|
||||||
|
LogError("Retry callback failed:", ErrorUtils.Format(error))
|
||||||
|
#end if
|
||||||
|
end try
|
||||||
|
end if
|
||||||
|
|
||||||
m.urlTransfer = invalid
|
m.urlTransfer = invalid
|
||||||
m._cache = invalid
|
m._cache = invalid
|
||||||
m._sent = invalid
|
m._sent = invalid
|
||||||
|
|||||||
Reference in new issue
Block a user