vaadin / vaadin/framework

Unable to detect if a request is an AJAX request

Open
#11,378 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
1.8k
Forks
717
Avg merge
2d 6h
Merged PRs (30d)
3

Description

I'm currently using Vaadin 8 and trying to set up a new authentication process that needs to comply with (when the user is not authenticated):

AJAX request: 401 Unauthorized
Other requests: 302 Redirect

The framework already tries to inspect the request and determine if it is an AJAX one by one of the criteria below:
There is a header X-Requested-With with XMLHttpRequest
There is either a header or a parameter with is_ajax_request

Vaadin only set the following headers:
Accept
Accept-Language
Accept-Encoding
Origin
User-Agent
Connection
Content-Type
Cookie
Content-Length
Referer
Host

And there is also no is_ajax_request parameter.

So, the only way I could achieve the desired behaviour was either using the deprecated com.vaadin.server.ServletPortletHelper#isUIDLRequest or doing something as ugly as context?.fullRequestURL?.contains("/UIDL") ?: false.

Can Vaadin implement a proper way of detecting if a request is an AJAX one or not?

Thanks in Advance.

Information:

  • Vaadin Framework version (e.g. 8.6.0)
  • Browser version: Chrome latest
  • Web container name and version: Wildlfy

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the deprecated com.vaadin.server.ServletPortletHelper#isUIDLRequest method and the request handling associated with the /UIDL endpoint. Determine how Vaadin can expose a supported AJAX-request check, then verify that unauthenticated AJAX and other requests can be distinguished for the requested response behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.