Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response 304. But chrome can't Parse. #268

Closed
hanxi opened this issue Dec 13, 2015 · 4 comments
Closed

Response 304. But chrome can't Parse. #268

hanxi opened this issue Dec 13, 2015 · 4 comments
Milestone

Comments

@hanxi
Copy link

hanxi commented Dec 13, 2015

I use webserver in android 4.3 . In index.html include some css and js file. When refresh browser, some request css and js file are response 304 and the response text are not normal, They are begin some binary bytes with http header.

@ritchieGitHub
Copy link
Member

we need more details to be able to help you. What does the webserver log say? did you trace the communication using a sniffer? (wireshark)

@hanxi
Copy link
Author

hanxi commented Dec 21, 2015

I use SimpleWebServer with this in android.

mHTTPSrv = new SimpleWebServer(null, port, wwwRoot, true, "*");

Then in PC Chrome visit this webserver, and refresh twice. the console error is this:
image

And response is this:
image

trace is this:

12-21 14:02:06.367 27723-29409/info.hanxi.phoneservice E/fi.iki.elonen.NanoHTTPD: Could not send response to the client
                                                                                  java.net.SocketException: sendto failed: EPIPE (Broken pipe)
                                                                                      at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:510)
                                                                                      at libcore.io.IoBridge.sendto(IoBridge.java:479)
                                                                                      at java.net.PlainSocketImpl.write(PlainSocketImpl.java:508)
                                                                                      at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
                                                                                      at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:270)
                                                                                      at java.io.OutputStream.write(OutputStream.java:82)
                                                                                      at fi.iki.elonen.NanoHTTPD$Response$ChunkedOutputStream.write(NanoHTTPD.java:1261)
                                                                                      at fi.iki.elonen.NanoHTTPD$Response$ChunkedOutputStream.write(NanoHTTPD.java:1247)
                                                                                      at java.util.zip.GZIPOutputStream.writeLong(GZIPOutputStream.java:112)
                                                                                      at java.util.zip.GZIPOutputStream.finish(GZIPOutputStream.java:95)
                                                                                      at fi.iki.elonen.NanoHTTPD$Response.sendBodyWithCorrectEncoding(NanoHTTPD.java:1451)
                                                                                      at fi.iki.elonen.NanoHTTPD$Response.sendBodyWithCorrectTransferAndEncoding(NanoHTTPD.java:1440)
                                                                                      at fi.iki.elonen.NanoHTTPD$Response.send(NanoHTTPD.java:1429)
                                                                                      at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:852)
                                                                                      at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:189)
                                                                                      at java.lang.Thread.run(Thread.java:841)
                                                                                   Caused by: libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe)
                                                                                      at libcore.io.Posix.sendtoBytes(Native Method)
                                                                                      at libcore.io.Posix.sendto(Posix.java:155)
                                                                                      at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
                                                                                      at libcore.io.IoBridge.sendto(IoBridge.java:477)
                                                                                      at java.net.PlainSocketImpl.write(PlainSocketImpl.java:508) 
                                                                                      at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46) 
                                                                                      at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:270) 
                                                                                      at java.io.OutputStream.write(OutputStream.java:82) 
                                                                                      at fi.iki.elonen.NanoHTTPD$Response$ChunkedOutputStream.write(NanoHTTPD.java:1261) 
                                                                                      at fi.iki.elonen.NanoHTTPD$Response$ChunkedOutputStream.write(NanoHTTPD.java:1247) 
                                                                                      at java.util.zip.GZIPOutputStream.writeLong(GZIPOutputStream.java:112) 
                                                                                      at java.util.zip.GZIPOutputStream.finish(GZIPOutputStream.java:95) 
                                                                                      at fi.iki.elonen.NanoHTTPD$Response.sendBodyWithCorrectEncoding(NanoHTTPD.java:1451) 
                                                                                      at fi.iki.elonen.NanoHTTPD$Response.sendBodyWithCorrectTransferAndEncoding(NanoHTTPD.java:1440) 
                                                                                      at fi.iki.elonen.NanoHTTPD$Response.send(NanoHTTPD.java:1429) 
                                                                                      at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:852) 
                                                                                      at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:189) 
                                                                                      at java.lang.Thread.run(Thread.java:841) 

@giridharkannan
Copy link

This issue happens because Transfer-Encoding: chunked is set, which is because Content-Encoding: gzip is set for 304 response.
For time being your could override useGzipWhenAccepted method to solve this issue.

    @Override
    protected boolean useGzipWhenAccepted(Response r) {
        return super.useGzipWhenAccepted(r) && r.getStatus() != Response.Status.NOT_MODIFIED;
    }

@hanxi
Copy link
Author

hanxi commented Jan 14, 2016

@giridharkannan Thanks a lot! It solved my problem.

// SimpleWebServer.java
...
public class SimpleWebServer extends NanoHTTPD {

    @Override
    protected boolean useGzipWhenAccepted(Response r) {
        return super.useGzipWhenAccepted(r) && r.getStatus() != Response.Status.NOT_MODIFIED;
    }
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants