Troubleshooting a PDF download tool, I was surprised to find out that some mobile browsers behave unexpectedly when trying to directly access a PDF resource through HTTP. While it was pretty obvious that they are lightweight and do not have PDF viewing plugins embedded as their desktop counterparts, even downloading the resource was behaving strangely in some of them.
I tested on my Samsung Galaxy S (GTi9000), a Palm Pre Plus, a Blackberry Torch (9800) and an iPhone 4. All browsers are WebKit based. The test case was pretty simple - download a PDF file from my domain. The PDF was ~200KB in size, to keep the tests quick.
To debug the actual HTTP traffic of the devices, I interposed Fiddler as a reverse proxy between my domain and them. This way, I was able to log all the headers and content of all the HTTP requests and responses made.
Let’s start with the responses, the server was not configured in any way to serve PDFs, so it gave the same response regardless of the request headers it received.
123456789
HTTP/1.1200OK
Date:Tue,02Aug201109:18:05GMT
Accept-Ranges:bytes
ETag:"2f257-4e36a6c5-0"
Last-Modified:Mon,01Aug201113:14:45GMT
Content-Type:application/pdf
Content-Length:193111
Connection:Keep-Alive
Age:13251
The caching headers are automatically inserted by the server, but they did not seem to affect the devices since the content was being downloaded for every request.
Now for the interesting part: besides the iPhone browser, all others make two requests for the file, which means the content is downloaded twice!
The BlackBerry first sends a complete request and then repeats it identically:
12345678
GET/a.pdf HTTP/1.1
Host:improve.ro
Connection:keep-alive
User-Agent:Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en-GB) AppleWebKit/534.1+(KHTML,likeGecko)Version/6.0.0.246 Mobile Safari/534.1+
User-Agent:Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_4 like Mac OS X; en-us) AppleWebKit/533.17.9(KHTML,likeGecko)Version/5.0.2 Mobile/8K2Safari/6533.18.5