Skip to content

304 Page Not Modified returns content after headers #13

@eoinsha

Description

@eoinsha

RFC 2616 for HTTP/1.1 dictates that a 304 Page-Not-Modified should have no body.

... The 304 response MUST NOT contain a message-body, and thus is always terminated by the first empty line after the header fields....

lightnode currently uses the chunked encoding header for all responses, including 304s. This results in a "0\r\n" following the message headers.

The following change to move the chunked header to the else clause resolves the issue for me.

                       //REMOVED headers['transfer-encoding'] = 'chunked'
                        headers['server'] = 'lightnode'

                        if (Date.parse(file.header.mtime) <= Date.parse(req.headers['if-modified-since'])) {
                                resp.writeHead(304, headers)
                                resp.end()
                                return
                        }
                        else {
                                headers['transfer-encoding'] = 'chunked' // ADDED

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions