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

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

Closed
webcarrot opened this issue Mar 2, 2023 · 1 comment · Fixed by #1982
Closed

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

webcarrot opened this issue Mar 2, 2023 · 1 comment · Fixed by #1982
Labels
bug Something isn't working

Comments

@webcarrot
Copy link

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)

@ronag
Copy link
Member

ronag commented Mar 2, 2023

undici does the right thing here, but I guess it wouldn't hurt to send them at the same time.

ronag added a commit that referenced this issue Mar 2, 2023
Ensures that headers and chunk len + body can be passed in same packet.

Fixes: #1981
ronag added a commit that referenced this issue Mar 2, 2023
Ensures that headers and chunk len + body can be passed in same packet.

Fixes: #1981
ronag added a commit that referenced this issue Mar 2, 2023
Ensures that headers and chunk len + body can be passed in same packet.

Fixes: #1981
metcoder95 pushed a commit to metcoder95/undici that referenced this issue Jul 21, 2023
Ensures that headers and chunk len + body can be passed in same packet.

Fixes: nodejs#1981
crysmags pushed a commit to crysmags/undici that referenced this issue Feb 27, 2024
Ensures that headers and chunk len + body can be passed in same packet.

Fixes: nodejs#1981
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants