From 1e252e0b45b41b2c3d216c1d2542d592380bf495 Mon Sep 17 00:00:00 2001 From: Behind The Math Date: Sat, 6 Jan 2018 21:22:29 -0500 Subject: [PATCH] Add User-Agent header to CORS preflight requests Fixes #1659. This mirrors the behavior of other browsers, and fixes broken XHR requests to APIs that require a User-Agent header for all requests, such as api.github.com. --- lib/jsdom/living/xhr-utils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/jsdom/living/xhr-utils.js b/lib/jsdom/living/xhr-utils.js index fc5e43c1a6..2e721d57f6 100644 --- a/lib/jsdom/living/xhr-utils.js +++ b/lib/jsdom/living/xhr-utils.js @@ -349,6 +349,8 @@ function createClient(xhr) { preflightRequestHeaders["Access-Control-Request-Headers"] = nonSimpleHeaders.join(", "); } + preflightRequestHeaders["User-Agent"] = requestHeaders["User-Agent"]; + flag.preflight = true; const preflightOptions = {