Skip to content

Request headers may potentially not have a proper ending (\r\n\r\n).  #1981

@webcarrot

Description

@webcarrot

Bug Description

It's possible that proper ending of request headers (\r\n\r\n) will be not send immediately together with headers chunk due to:

👉🏻 https://github.com/nodejs/undici/blob/main/lib/client.js#L1677

socket.write(`${header}transfer-encoding: chunked\r\n`, 'ascii')

Potential fix:

    if (bytesWritten === 0) {
      if (!expectsPayload) {
        socket[kReset] = true
      }

      if (contentLength === null) {
        socket.write(`${header}transfer-encoding: chunked\r\n\r\n`, 'ascii')
        socket.write(`${len.toString(16)}\r\n`, 'ascii')
      } else {
        socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'ascii')
      }

    } else if (contentLength === null) {
        socket.write(`\r\n${len.toString(16)}\r\n`, 'ascii')
    }

Reproducible By

It's quite random and depends on Socket/system behaviours - "Sometimes" 😉

👀 👉🏻 Additional context

Expected Behavior

Chunk containing request headers always contains proper headers ending - \r\n\r\n.

Additional context

Related issue: uNetworking/uWebSockets.js#879

In this issue I have tried to emulate behaviour of undici - especially: uNetworking/uWebSockets.js#879 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions