[1.7.x] Added a test to verify headers set by default middleware; refs #23939.

Backport of 50c1d8f24b0d04c813b3dd34720df86446091afa from master