When is an HTTP response finished?

前端 未结 2 1106
醉酒成梦
醉酒成梦 2020-12-04 03:35

I am writing a simple HTTP client in .NET for learning purposes. I am using the .NET Socket class, which ultimately uses Winsock. I do not want to use the WebRequest, HttpWe

相关标签:
2条回答
  • 2020-12-04 04:08

    Your understanding is mostly correct, with some minor corrections, per RFC 2616 Section 4.4:

    Read and parse HTTP headers
    if not successful:
        throw error
    if response can contain message body:
        if HTTP version is 1.1+ and Transfer-encoding is not identity:
            while true:
                read line, extract delimited ASCII hexadecimal, the chunk size
                if not successful:
                    throw error
                 if chunk size is 0:
                    break while loop
                 read chunk size number of bytes
            read and parse trailing HTTP headers
        else if Content-Length is specified:
            read Content-Length number of bytes
        else if Content-Type is "multipart/byteranges":
            read and parse MIME-encoded chunks until terminating MIME boundary is reached
        else:
            read until connection is closed
    
    0 讨论(0)
  • 2020-12-04 04:18

    You should look at http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p1-messaging-24.html#message.body.length (if this doesn't answer your question then please send back to the Working Group).

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