mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2026-02-01 04:14:26 +01:00
Add a 3 second cache control for unsettled LNURL verify requests (#948)
This commit is contained in:
@@ -5,6 +5,7 @@ object Constants {
|
||||
const val SHUTDOWN_DELAY_MS = 60 * 1000L
|
||||
|
||||
// Cache Control
|
||||
const val CACHE_CONTROL_MAX_AGE_THREE_SEC = 3
|
||||
const val CACHE_CONTROL_MAX_AGE_DAY = 60 * 60 * 24
|
||||
const val CACHE_CONTROL_MAX_AGE_WEEK = 60 * 60 * 24 * 7
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import breez_sdk_liquid.BindingLiquidSdk
|
||||
import breez_sdk_liquid.GetPaymentRequest
|
||||
import breez_sdk_liquid.PaymentDetails
|
||||
import breez_sdk_liquid.PaymentState
|
||||
import breez_sdk_liquid_notification.Constants.CACHE_CONTROL_MAX_AGE_THREE_SEC
|
||||
import breez_sdk_liquid_notification.Constants.CACHE_CONTROL_MAX_AGE_WEEK
|
||||
import breez_sdk_liquid_notification.Constants.DEFAULT_LNURL_PAY_VERIFY_NOTIFICATION_TITLE
|
||||
import breez_sdk_liquid_notification.Constants.DEFAULT_LNURL_PAY_VERIFY_NOTIFICATION_FAILURE_TITLE
|
||||
@@ -79,7 +80,7 @@ class LnurlPayVerifyJob(
|
||||
throw InvalidLnurlPayException("Not found")
|
||||
}
|
||||
|
||||
val maxAge = if (response.settled) CACHE_CONTROL_MAX_AGE_WEEK else 0
|
||||
val maxAge = if (response.settled) CACHE_CONTROL_MAX_AGE_WEEK else CACHE_CONTROL_MAX_AGE_THREE_SEC
|
||||
val success = replyServer(Json.encodeToString(response), request.replyURL, maxAge)
|
||||
notifyChannel(
|
||||
context,
|
||||
|
||||
@@ -2,6 +2,7 @@ import Foundation
|
||||
|
||||
struct Constants {
|
||||
// Cache Control
|
||||
static let CACHE_CONTROL_MAX_AGE_THREE_SEC = 3
|
||||
static let CACHE_CONTROL_MAX_AGE_DAY = 60 * 60 * 24
|
||||
static let CACHE_CONTROL_MAX_AGE_WEEK = 60 * 60 * 24 * 7
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class LnurlPayVerifyTask : LnurlPayTask {
|
||||
if response == nil {
|
||||
throw InvalidLnurlPayError.notFound
|
||||
}
|
||||
let maxAge = response!.settled ? Constants.CACHE_CONTROL_MAX_AGE_WEEK : 0
|
||||
let maxAge = response!.settled ? Constants.CACHE_CONTROL_MAX_AGE_WEEK : Constants.CACHE_CONTROL_MAX_AGE_THREE_SEC
|
||||
replyServer(encodable: response, replyURL: request!.reply_url, maxAge: maxAge)
|
||||
} catch let e {
|
||||
self.logger.log(tag: TAG, line: "failed to process lnurl verify: \(e)", level: "ERROR")
|
||||
|
||||
Reference in New Issue
Block a user