How can I check if XHR is working with HTTP / 2.0?

How can I check if XMLHttpRequest has been executed using HTTP / 2.0? At the moment I am doing the following, but of course this only works in Firefox.

if (req.getResponseHeader('X-Firefox-Spdy')) {
  if (req.getResponseHeader('X-Firefox-Spdy').startsWith('h2')) {
    return true
  }
}

      

+3


source to share


1 answer


Since the status bar is excluded from the returned string getAllResponseHeaders

and HTTP / 2 does not define how the version ... that is included in the HTTP / 1.1 status bar is migrated , you cannot detect the version in reliable mode.

However, some versions of some browsers, notably Safari 10-do, carry over the version by adding HTTP/2.0

property reasons before the phrase statusText

.



if (req.statusText.startsWith('HTTP/2.0 '))
  // HTTP/2.0 enabled
else
  // we don't know either way

      

+3


source







All Articles