Skip to content

Commit

Permalink
Grails Web: Improvements for HttpServletReuest.isXhr
Browse files Browse the repository at this point in the history
Fixes issue: groovy.lang.MissingMethodException: No signature of method: org.apache.catalina.connector.RequestFacade.isXhr() is applicable for argument types: () values: []
  • Loading branch information
rainboyan committed Mar 25, 2023
1 parent ef4a090 commit 89d53c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class HttpServletResponseExtension {
def parser = new DefaultAcceptHeaderParser(getMimeTypes())
String header = null

boolean disabledForUserAgent = !(useAcceptHeaderXhr && request.xhr) && disableForUserAgents != null &&
boolean disabledForUserAgent = !(useAcceptHeaderXhr && isAjaxRequest(request)) && disableForUserAgents != null &&
userAgent ? disableForUserAgents.matcher(userAgent).find() : false
if (msie) {
header = '*/*'
Expand All @@ -283,4 +283,8 @@ class HttpServletResponseExtension {
result
}

private static boolean isAjaxRequest(HttpServletRequest request) {
request.getHeader('X-Requested-With') == 'XMLHttpRequest'
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ class HttpServletRequestExtension {
results
}

static boolean isXhr(HttpServletRequest instance) {
static boolean isXhr(HttpServletRequest request) {
// TODO grails.web.xhr.identifier support
instance.getHeader('X-Requested-With') == 'XMLHttpRequest'
request.getHeader('X-Requested-With') == 'XMLHttpRequest'
}

static boolean isGet(HttpServletRequest request) {
Expand Down

0 comments on commit 89d53c1

Please sign in to comment.