I have written a Servlet that should act like a web-proxy. But some of the Javascript GET calls only return part of the original content when I am loading a page, like localhost:8080/Proxy?requestURL=example.com
.
When priting the content of the java script to the console, they are complete. But the response at the browser is truncated.
I am writing like this:
ServletOutputStream sos = resp.getOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(sos);
..
String str = content_of_get_request
..
writer.write(str);
writer.flush();
writer.close();
The strange thing is, when I request directly the Javascript that was loaded during the page request like this:
localhost:8080/Proxy?requestURL=anotherexaple.com/needed.js
The whole content is returned to the browser.
It would be great if someone had an idea. Regards
UPDATE:
The problem was the way how I created the response String:
while ((line = rd.readLine()) != null)
{
response.append(line);
}
I read one line from a Stream and appended it on a StringBuffer, but it appears that firefox and chrome had a problem with that. It seems that some browsers implement a maximum line length for JavaScript, however there is no maximum line length mentioned in the RFC HTTP 1.1 standard.
Fix:
Just adding a "\n" to the line fixes the issue.
response.append(line+"\n");