setting a Content-Type in CakePHP when the response is large-ish (>4kB) -
quite simply, i'm trying generate , download csv file cakephp controller. no problem generating csv, , works until response >= 4096 bytes.
the following controller illustrates problem:
class testtypecontroller extends controller { public function csv($size = 100) { # set content type configure::write('debug', 0); $this->autorender = false; $this->response->type('csv'); # send response ($i = 0; $i < $size; $i++) echo 'x'; } } when call http://baseurl/test_type/csv/4095, i'm prompted save file, , content-type header text/csv. response headers are:
http/1.1 200 ok date: tue, 05 jun 2012 14:28:56 gmt server: apache/2.2.22 (ubuntu) x-powered-by: php/5.3.10-1ubuntu3.1 content-length: 4095 keep-alive: timeout=5, max=98 connection: keep-alive content-type: text/csv; charset=utf-8 when call http://baseurl/test_type/csv/4096, file printed screen, , response headers are:
http/1.1 200 ok date: tue, 05 jun 2012 14:28:53 gmt server: apache/2.2.22 (ubuntu) x-powered-by: php/5.3.10-1ubuntu3.1 vary: accept-encoding content-encoding: gzip content-length: 38 keep-alive: timeout=5, max=100 connection: keep-alive content-type: text/html obviously, 4kb limit content-encoding starts gzipping response. i'm not familiar how content-type meant react, i'd prefer remain text/csv.
the same problem occurs using requesthandlercomponent manage type of response.
i'm using cakephp 2.2.0-rc1, i've verified problem exists stable 2.1.3. ideas? pointers in right direction?
the answer pretty simple -- controller should returning csv data instead of echoing it.
Comments
Post a Comment