Fix bad logic in xhr that tries to avoid double-setting Content-Type

Fixes #18237.

(cherry picked from commit 33e102dfe99c201efdb817931167261cf4985e9b)
(cherry picked from commit e6074b1e97131d86c0cf978d9f8c7856f380557d)
(cherry picked from commit 4695f6ac912fc56f63c556a1ca3101066b444074)