GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc(http): res.write(data) followed by res.end() is not actually equivalent to res.end(data) · Issue #26005 · nodejs/node

doc(http): res.write(data) followed by res.end() is not actually equivalent to res.end(data) #26005

New issue
Copy link
New issue
Copy link
Closed
Closed
doc(http): res.write(data) followed by res.end() is not actually equivalent to res.end(data)#26005
Copy link
Labels
docIssues and PRs related to Node.js documentation.good first issueIssues that are suitable for first-time contributors.httpIssues and PRs related to the http subsystem.

Description

@peat-psuwit
peat-psuwit
opened on Feb 8, 2019
Issue body actions
  • Version: v11.9.0
  • Platform: Linux (My hostname) 4.15.0-45-generic #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux (Xubuntu 18.04)
  • Subsystem: Documentation of HTTP module

In the document for method end([data][, encoding][, callback]) of class http.ServerResponse, there's a following text:

If data is specified, it is equivalent to calling response.write(data, encoding) followed by response.end(callback).

However, this is not actually true when there's only single response.write(data), demonstrable with the following code:

const http = require('http');

const HELLO = 'Hello!\n';

const server1 = http.createServer(function (req, res) {
  res.write(HELLO);
  res.end();
});

const server2 = http.createServer(function (req, res) {
  res.end(HELLO);
});

server1.listen(9001);
server2.listen(9002);

By using curl -v, this happens:

$ curl -v http://localhost:9001/ # response.write(data) follow by response.end()
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9001 (#0)
> GET / HTTP/1.1
> Host: localhost:9001
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Fri, 08 Feb 2019 10:26:25 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
< 
Hello!
* Connection #0 to host localhost left intact

$ curl -v http://localhost:9002/ # response.end(data)
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9002 (#0)
> GET / HTTP/1.1
> Host: localhost:9002
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Fri, 08 Feb 2019 10:26:31 GMT
< Connection: keep-alive
< Content-Length: 7
< 
Hello!
* Connection #0 to host localhost left intact
$ 

So, it appears that response.write(data) follow by response.end() cause Node.js to use chunked encoding, while response.end(data) cause Node.js to not using chunked encoding and include Content-Length header. This small distinction is important with some client. For example, Windows 10's MDM enrollment system will not accept chunked response.

Activity

  1. peat-psuwit
    added 3 commits that reference this issue on Feb 8, 2019

    server: send response to client with res.end()

    d9ed4b5

    server: add option enableChunkedEncoding

    01fb356

    server: add option enableChunkedEncoding

    20390f2
  2. ChALkeR
    added
    docIssues and PRs related to Node.js documentation.
    httpIssues and PRs related to the http subsystem.
    on Feb 8, 2019
  3. jsdevel
    added a commit that references this issue on Feb 11, 2019

    server: add option enableChunkedEncoding (#1043)

    6bb6936
  4. lpinca commented on Mar 4, 2019

    @lpinca
    lpinca
    on Mar 4, 2019
    Member
    More actions

    @peat-psuwit are you interested in submitting a PR to fix the documentation?

  5. lpinca
    added
    good first issueIssues that are suitable for first-time contributors.
    on Mar 4, 2019
  6. peat-psuwit commented on Mar 4, 2019

    @peat-psuwit
    peat-psuwit
    on Mar 4, 2019
    Author
    More actions

    Hmm, I'm not sure how I should change the document. Also, after I read some comment in the source I start to wonder if the current behavior is not an intended behavior.

  7. lpinca commented on Mar 4, 2019

    @lpinca
    lpinca
    on Mar 4, 2019
    Member
    More actions

    I think current behavior is intended, but the sentence you quoted is misleading. Perhaps remove it or reword it to match current behavior?

    cc: @nodejs/http

  8. lpinca commented on Mar 4, 2019

    @lpinca
    lpinca
    on Mar 4, 2019
    Member
    More actions

    Current behavior was defined in #1062. Before that both cases in your example returned Transfer-Encoding: chunked.

  9. BridgeAR
    added a commit that references this issue on Mar 13, 2019

    doc: fix misleading sentence in http.md

    1706a2d
  10. BridgeAR
    closed this as completedin 1706a2don Mar 13, 2019
  11. BridgeAR
    added 3 commits that reference this issue on Mar 14, 2019

    doc: fix misleading sentence in http.md

    deb6826

    doc: fix misleading sentence in http.md

    7309539

    doc: fix misleading sentence in http.md

    b9cfaa3
  12. BethGriggs
    added a commit that references this issue on Apr 16, 2019

    doc: fix misleading sentence in http.md

    0a976ec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.good first issueIssues that are suitable for first-time contributors.httpIssues and PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.