Add a 3 second cache control for unsettled LNURL verify requests (#948)

This commit is contained in:
Ross Savage
2025-06-09 18:00:07 +00:00
committed by GitHub
parent 5789089c4e
commit f2c8e18600
4 changed files with 5 additions and 2 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -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")