Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript truncated over Servlet Connection
    primarykey
    data
    text
    <p>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 <code>localhost:8080/Proxy?requestURL=example.com</code>.</p> <p>When priting the content of the java script to the console, they are complete. But the response at the browser is truncated.</p> <p>I am writing like this:</p> <pre><code>ServletOutputStream sos = resp.getOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(sos); .. String str = content_of_get_request .. writer.write(str); writer.flush(); writer.close(); </code></pre> <p>The strange thing is, when I request directly the Javascript that was loaded during the page request like this:</p> <pre><code>localhost:8080/Proxy?requestURL=anotherexaple.com/needed.js </code></pre> <p>The whole content is returned to the browser.</p> <p>It would be great if someone had an idea. Regards</p> <p>UPDATE:</p> <p>The problem was the way how I created the response String:</p> <pre><code>while ((line = rd.readLine()) != null) { response.append(line); } </code></pre> <p>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.</p> <p>Fix:</p> <p>Just adding a "\n" to the line fixes the issue.</p> <pre><code>response.append(line+"\n"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload