Skip to content

Short circuit the postback request to avoid the google 413 error after payment#47

Open
jim-daf wants to merge 1 commit intoLivotovLabs:masterfrom
jim-daf:fix/postback-413-issue-40
Open

Short circuit the postback request to avoid the google 413 error after payment#47
jim-daf wants to merge 1 commit intoLivotovLabs:masterfrom
jim-daf:fix/postback-413-issue-40

Conversation

@jim-daf
Copy link
Copy Markdown

@jim-daf jim-daf commented Apr 22, 2026

Avoid the google 413 page after a successful payment

Resolves #40

The default postback URL in the library is https://www.google.com. After
the user confirms the payment the ACS server posts the result form back to
that URL. The form is big enough that google answers with HTTP 413 and the
WebView paints google's error page for a moment before the activity is
torn down. End users see this as a confusing error after a successful
payment.

By the time shouldInterceptRequest runs for the postback URL we already
have everything we need from the form. The actual network request is
pointless and is the only thing producing the 413. The fix is to return an
empty document for that one request so it never leaves the device.

if (isPostbackUrl(url)) {
    Thread.sleep(1500);
    return new WebResourceResponse("text/html", "UTF-8", new ByteArrayInputStream(new byte[0]));
}

Why this is safe

The postback URL is by definition a sentinel. The library does not need
anything from its response. Callers that pass their own postback URL keep
the same behaviour because the short circuit only kicks in for URLs that
match isPostbackUrl, and the response body returned is empty rather than
a redirect or error page.

Testing

Reproduced the 413 against the default postback URL with a 3D Secure
sandbox transaction. With the patch applied the WebView quietly resolves
the postback and the listener fires without any visible error page.

When the gateway uses the default postback URL (https://www.google.com)
the ACS form is large enough that google answers HTTP 413 and the user
sees that error page before the activity finishes. The library has
already captured the form data at this point so the actual network
request is pointless.

Return an empty WebResourceResponse for the postback URL so the
request is short circuited and no error page is shown.

Fixes LivotovLabs#40
@jim-daf jim-daf marked this pull request as ready for review April 22, 2026 18:39
Copilot AI review requested due to automatic review settings April 22, 2026 18:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to prevent a brief Google “HTTP 413 request too large” error page flash after a successful 3DS payment by short-circuiting the default postback navigation in WebViewClient.shouldInterceptRequest, returning an empty document instead of allowing the POST to reach a real host.

Changes:

  • Return an empty WebResourceResponse for requests identified as the postback URL to avoid the network request (and resulting 413).
  • Add ByteArrayInputStream import to support the empty response body.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 83 to 85
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (isPostbackUrl(url)) {
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldInterceptRequest(WebView, String) is deprecated and may not be invoked on API 21+ (WebView prefers shouldInterceptRequest(WebView, WebResourceRequest)). If that happens, the postback short-circuit won’t run on most modern devices, so the 413 flash can remain. Consider overriding the WebResourceRequest variant as well and delegating to shared logic so the behavior is consistent across API levels.

Copilot uses AI. Check for mistakes.
Comment on lines +93 to 98
// The default postback URL is a real host (for example google.com)
// and the ACS form payload can be large enough to trigger a 413
// error from that host. Return an empty document so the request
// never actually leaves the device.
return new WebResourceResponse("text/html", "UTF-8", new ByteArrayInputStream(new byte[0]));
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change short-circuits all requests that match isPostbackUrl(url), but postbackUrl can be provided by callers (see authorize(..., postbackUrl)). That means ACS POSTs will no longer reach a caller-provided postback endpoint, which is a behavioral/API change compared to returning null and letting the request proceed. If the intent is only to avoid the default google.com 413, consider gating the empty response to the library’s default postback URL (or making this behavior explicitly opt-in).

Copilot uses AI. Check for mistakes.
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
// Ignore
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The InterruptedException is swallowed. Since shouldInterceptRequest runs on a worker thread, clearing the interrupt can interfere with cancellation/shutdown logic. Consider restoring the interrupted status (e.g., Thread.currentThread().interrupt()) before returning.

Suggested change
// Ignore
Thread.currentThread().interrupt();

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google error 413. That's an error after confirm payment

2 participants