8000 [HttpFoundation] Remove Cache-Control when using https download via I… · symfony/symfony@b2080c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit b2080c4

Browse files
Johannes Klaussfabpot
Johannes Klauss
authored andcommitted
[HttpFoundation] Remove Cache-Control when using https download via IE<9 (fixes #6750)
1 parent 7d143aa commit b2080c4

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ public function prepare(Request $request)
253253
$this->headers->set('expires', -1);
254254
}
255255

256+
/**
257+
* Check if we need to remove Cache-Control for ssl encrypted downloads when using IE < 9
258+
* @link http://support.microsoft.com/kb/323308
259+
*/
260+
if (false !== stripos($this->headers->get('Content-Disposition'), 'attachment') && preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) == 1 && true === $request->isSecure()) {
261+
if(intval(preg_replace("/(MSIE )(.*?);/", "$2", $match[0])) < 9) {
262+
$this->headers->remove('Cache-Control');
263+
}
264+
}
265+
256266
return $this;
257267
}
258268

src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,75 @@ public function testContentTypeCharset()
326326
$this->assertEquals('text/css; charset=UTF-8', $response->headers->get('Content-Type'));
327327
}
328328

329+
public function testNoCacheControlHeaderOnAttachmentUsingHTTPSAndMSIE()
330+
{
331+
// Check for HTTPS and IE 8
332+
$request = new Request();
333+
$request->server->set('HTTPS', true);
334+
$request->server->set('HTTP_USER_AGENT', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)');
335+
336+
$response = new Response();
337+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
338+
$response->prepare($request);
339+
340+
$this->assertFalse($response->headers->has('Cache-Control'));
341+
342+
// Check for IE 10 and HTTPS
343+
$request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)');
344+
345+
$response = new Response();
346+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
347+
$response->prepare($request);
348+
349+
$this->assertTrue($response->headers->has('Cache-Control'));
350+
351+
// Check for IE 9 and HTTPS
352+
$request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)');
353+
354+
$response = new Response();
355+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
356+
$response->prepare($request);
357+
358+
$this->assertTrue($response->headers->has('Cache-Control'));
359+
360+
// Check for IE 9 and HTTP
361+
$request->server->set('HTTPS', false);
362+
363+
$response = new Response();
364+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
365+
$response->prepare($request);
366+
367+
$this->assertTrue($response->headers->has('Cache-Control'));
368+
369+
// Check for IE 8 and HTTP
370+
$request->server->set('HTTP_USER_AGENT', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)');
371+
372+
$response = new Response();
373+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
374+
$response->prepare($request);
375+
376+
$this->assertTrue($response->headers->has('Cache-Control'));
377+
378+
// Check for non-IE and HTTPS
379+
$request->server->set('HTTPS', true);
380+
$request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17');
381+
382+
$response = new Response();
383+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
384+
$response->prepare($request);
385+
386+
$this->assertTrue($response->headers->has('Cache-Control'));
387+
388+
// Check for non-IE and HTTP
389+
$request->server->set('HTTPS', false);
390+
391+
$response = new Response();
392+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
393+
$response->prepare($request);
394+
395+
$this->assertTrue($response->headers->has('Cache-Control'));
396+
}
397+
329398
public function testPrepareDoesNothingIfContentTypeIsSet()
330399
{
331400
$response = new Response('foo');

0 commit comments

Comments
 (0)
0