grunt-connect-proxy: Unable to download pdf files through the proxy

Hi everyone,

I am unable to download pdf files through the proxy served by an ordinary servlet at /myapp/pdfservlet/ on my tomcat server. When I try without proxy, pdf files are correctly downloaded.

Here is my proxy configuration:

{
    context: '/', // the context of the data service
    host: localhost, // wherever the data service is running
    port: 8080, // the port that the data service is running on
    ws: true, // Proxy websocket
    rewrite: { '^/myapp/realtime/fallback':  '/myapp/realtime'},
        excludedFileTypes: ['pdf', 'jar', 'gz']
}

Here is the request/response given by Chrome:

Remote Address:127.0.0.1:9000
Request URL:http://localhost:9000/myapp/pdfservlet
Request Method:GET
Status Code:200 OK

Request Headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,de;q=0.2,es;q=0.2
Connection:keep-alive
Host:localhost:9000
Referer:http://localhost:9000/myapp/jsp/foo.jsp
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.103 Safari/537.36

Response Headers
connection:close
content-disposition:filename="foo.pdf"
content-language:fr-FR
content-type:application/pdf;charset=UTF-8
date:Wed, 10 Sep 2014 17:36:13 GMT
server:Apache-Coyote/1.1
transfer-encoding:chunked

It also happens on .gz files. It seems that the connection is closed before the end of the file because the pdf is just blank.

Am I missing something?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 20

Commits related to this issue

Most upvoted comments

I just found the solution for my case! For the record, I was using grunt-connect-proxy#0.1.11. My project was generated by Yeoman. Yeoman generated automatically a package.json containing:

"devDependencies": {
    ...
    "grunt-connect-proxy": "0.1.11",
    "grunt-contrib-connect": "0.7.1",
    ...
}

In package.json, I changed the grunt-contrib-connect version to 0.5.0 which is the one pulled by grunt-connect-proxy#0.1.11.

That solved pdf and gz corruption ! Don’t forget to disable your browser cache for your pdf fetch tests.

I’ve got the same problem…

var http = require('http'),
    httpProxy = require('http-proxy'),
    proxy = httpProxy.createProxyServer({});

http.createServer(function(req, res) {

    proxy.web(req, res, { target: req.url });

}).listen(8005, function() {
    console.log('proxy listening on port 8005');
});

this works…

wget http://security.ubuntu.com/ubuntu/pool/main/p/php5/libapache2-mod-php5_5.3.10-1ubuntu3.15_amd64.deb

this does not…

wget -e http_proxy=127.0.0.1:8005 http://security.ubuntu.com/ubuntu/pool/main/p/php5/libapache2-mod-php5_5.3.10-1ubuntu3.15_amd64.deb