HTTP Server Not Sending Complete File To WGET, Firefox. Connection reset by peer?

前端 未结 2 1430
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-26 17:03

I\'m writing an HTTP server, and am having trouble sending larger files. If I grab them with netcat, the output seems perfect. If I use a browser or wget, I only get the complet

相关标签:
2条回答
  • 2021-01-26 17:34

    I don't know if it is necessary, but when I inspect the headers being sent by a simple website, there are quotes around the values:

    Accept-Ranges:"bytes"
    Cache-Control:"max-age=25920000"
    Connection:"Keep-Alive"
    Content-Length:"4777"
    Content-Type:"image/gif"
    Date:"Wed, 01 Jul 2015 17:55:52 GMT"
    Expires:"Tue, 26 Apr 2016 17:55:52 GMT"
    Keep-Alive:"timeout=30, max=100"
    Last-Modified:"Mon, 28 Apr 1997 01:25:47 GMT"
    Server:"Apache/1.3.28 (Unix) mod_gzip/1.3.19.1a mod_perl/1.28"
    

    Is it possible the content type is not correct?

    0 讨论(0)
  • 2021-01-26 17:41

    My guess is that the error is related to code you have not shown here.

    It is a common mistake in simple implementation to not fully read the request but instead only read the first line or some bytes to determine the requested page, then send the response and finally close.

    Since at the time of the close there are still unread data from the client, this will result in Connection reset by peer. You don't see this effect with nc because the request you send with nc is probably shorter than the request from the browser and thus all data from the request are read in case of nc, but not in case of browser.

    Apart from that your response is invalid even if browsers accept it. Your status line (the first line) stops after the status code instead of adding the reason phrase, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1. Also, you use \n instead of \r\n as line delimiter.

    0 讨论(0)
提交回复
热议问题