1

I've built a simple concurrent web server with TCP sockets in Java.

When I make a GET request to my web server:

http://localhost:32000/examples/index.html

It works fine on Firefox and Internet Explorer, the html page (a very simple one) is loaded ok, but not on Chrome.

The thing is that with Chrome the response is 200 OK Status, but the content of the html page is never loaded. At the console, at network, I get the next status field:

"(failed) net::ERR_CONTENT_LENGTH_MISMATCH"

but the response headers in the Chrome console are as follow (content-length is included!!):

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 365
Access-Control-Allow-Origin: *

The GET request:

    GET /example/index.html HTTP/1.1
    Host: localhost:32000
    Connection: keep-alive
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
    Accept-Encoding: gzip, deflate, sdch
    Accept-Language: es-ES,es;q=0.8,en;q=0.6

Maybe is a response headers problem, I'v tried including "Access-Control-Allow-Origin: *" but it hasn't solved it.

Any idea where this problem may originate? If you need any piece of web server code don't hesitate on ask for it.

daniegarcia254
  • 1,157
  • 4
  • 17
  • 36
  • FWIW: I ran into the same issue with Chrome. Switched to https, and it worked. Switched back to http, cleared the cache and reloaded -- still broken. Cleared cache and reloaded (a second time), now it works. Yikes! Note: My server was using different tech (node.js serving a large xml file), which makes me wonder if Chrome has a bug. – two-bit-fool Mar 13 '15 at 15:48
  • Does the bug persist after you clear cache and reload? What about on other machines on the same network? – two-bit-fool Mar 13 '15 at 16:17
  • @two-bit-fool That wasn't the solution neither the problem in my case, as I explain in my answer – daniegarcia254 Mar 18 '15 at 07:44
  • 1
    Chrome would still be the primary suspect in my mind, otherwise you'd see the bug in other browsers. I suspect that the change you made on the server is "working around" the bug because the buffered response uses a different code path in Chrome. Either way, glad you found a way around the issue. Cheers! – two-bit-fool Mar 19 '15 at 11:42

2 Answers2

0

Probably a bug in Google Chrome.

Heroku started seeing interrupted requests with Chrome several months ago.

...the latest Chrome which I have seen other apps have issue with as well..

I ran into a similar issue (with a Node.js app streaming a large xml file on Heroku). No problems when using https. No problem using (the same version of) Chrome on a different computer on the same network.

After clearing the cache and reloading, it still failed, but gave a different error when parsing the XML. So, I cleared the cached and reloaded again -- problem gone.

Community
  • 1
  • 1
two-bit-fool
  • 4,978
  • 6
  • 28
  • 26
0

Finally I found myself a solution for my problem.

It works by switching a piece of code, the one that writes into the client output:

    out = new PrintWriter(client.getOutputStream());

    private void returnFileContent(File f) throws IOException{
        BufferedReader br = new BufferedReader(new FileReader(f));
        String linea;

        while ((line = br.readLine())!=null){
            out.println(line); out.flush();
        }
        br.close();
    }

Before that I used the client outputStream directly. Still I don't really understand why that worked on Firefox/Explorer but not on Chrome.

NEW PROBLEM

Now, my server must serve gif images. This is the code I use for it:

    httpHeader= (h+" 200 OK \n" +
                            "Content-Type: image/gif"+"\n" +
                            "Content-Length: "+f.length()+"\n\n");
                    //Send header to the client
                    out.println(cabecera);
                    out.flush();
                    //Send gif file content to the cliente
                    returnGIF(f);


    private void returnGIF(File f) throws IOException{
        FileInputStream fis = new FileInputStream(f.getPath());
        int b=0;
        while ((b=fis.read()) != -1){
            out_bis.write(b);
        }
        fis.close();
    }

The web browser is getting the data of the gif file with a 200 Status OK and the right file size, but I'm not able to accomplish that the browser shows the image, it always shows an empty image with the alternative text. Path of the images is also ok.

I've tried differents methods of serve the image to the client, none of them has worked for me so far.

daniegarcia254
  • 1,157
  • 4
  • 17
  • 36