Skip to content

Commit

Permalink
Optimizing mapType
Browse files Browse the repository at this point in the history
When using RequestHandler component the code tries to guess the extension by checking the Accept header. The current code maps all the types sent as acceptable by the requester (usually browser) and just use the first. This is just a quicker solution where moving the order of the items on the array makes the code to reduce around 400 loops with in_array check inside for requests coming from the most common browsers (Chrome, Safari, Firefox, IE).
  • Loading branch information
jrbasso committed May 31, 2016
1 parent 445e0cc commit 4a2b8d8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Network/Response.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class Response
'html' => ['text/html', '*/*'], 'html' => ['text/html', '*/*'],
'json' => 'application/json', 'json' => 'application/json',
'xml' => ['application/xml', 'text/xml'], 'xml' => ['application/xml', 'text/xml'],
'xhtml' => ['application/xhtml+xml', 'application/xhtml', 'text/xhtml'],
'webp' => 'image/webp',
'rss' => 'application/rss+xml', 'rss' => 'application/rss+xml',
'ai' => 'application/postscript', 'ai' => 'application/postscript',
'bcpio' => 'application/x-bcpio', 'bcpio' => 'application/x-bcpio',
Expand Down Expand Up @@ -283,7 +285,6 @@ class Response
'javascript' => 'application/javascript', 'javascript' => 'application/javascript',
'form' => 'application/x-www-form-urlencoded', 'form' => 'application/x-www-form-urlencoded',
'file' => 'multipart/form-data', 'file' => 'multipart/form-data',
'xhtml' => ['application/xhtml+xml', 'application/xhtml', 'text/xhtml'],
'xhtml-mobile' => 'application/vnd.wap.xhtml+xml', 'xhtml-mobile' => 'application/vnd.wap.xhtml+xml',
'atom' => 'application/atom+xml', 'atom' => 'application/atom+xml',
'amf' => 'application/x-amf', 'amf' => 'application/x-amf',
Expand All @@ -292,7 +293,6 @@ class Response
'wmlscript' => 'text/vnd.wap.wmlscript', 'wmlscript' => 'text/vnd.wap.wmlscript',
'wbmp' => 'image/vnd.wap.wbmp', 'wbmp' => 'image/vnd.wap.wbmp',
'woff' => 'application/x-font-woff', 'woff' => 'application/x-font-woff',
'webp' => 'image/webp',
'appcache' => 'text/cache-manifest', 'appcache' => 'text/cache-manifest',
'manifest' => 'text/cache-manifest', 'manifest' => 'text/cache-manifest',
'htc' => 'text/x-component', 'htc' => 'text/x-component',
Expand Down

0 comments on commit 4a2b8d8

Please sign in to comment.