question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simplify Node Http Response Logic

See original GitHub issue

Currently a http response exists in two forms:

  1. context.res = bodyValue; // res is interpreted as 200 with body bodyValue
  2. context.res = { body: bodyValue, headers: ..., status: ... } // res is fully specified object

Removing option 1 is something we ought to consider, as it has some negatives:

  • We are forced to guess whether the returned object is a response based on existence of ‘body’ property, which in a couple cases is incorrect:
    • bodyValue has a body property (workaround is nested body inside body)
    • a response object is returned with only headers and status
  • The ‘magic’ code of 1 doesn’t save lines of code
    • context.res = bodyValue; context.done(); vs context.res.send(bodyValue);
  • We would decrease the matrix of things we need to test (currently, different behavior in content type handling between 1 and 2)
  • Simplified documentation and examples with a single recommended way of interacting with http in node

#978 #814

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mamasocommented, Dec 12, 2016

@stefan-akelius At present all function triggers are routed through a C# process. We use edgejs for interop between node and C#. The requests are served in C# so unfortunately we don’t have access to a node generated IncomingMessage or ServerResponse (I’d love to support those types natively as well).

2reactions
johnnliucommented, Dec 1, 2016

figured this one out. 1.0 don’t like raw body content. can’t validate webhook that wanted text/plain response. argh.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Anatomy of an HTTP Transaction
Let's simplify the previous example to make a simple echo server, which just sends whatever data is received in the request right back...
Read more >
node.js - How to limit content length response of simplified ...
I would like request() to stop downloading after 10MB. Usually, when request gets an answer it gets all the HTTP headers and everything...
Read more >
Best Practices for Node.js Error-handling
This article will introduce you to error-handling in Node.js and demonstrate some of ... incorrectly applying the same logic everywhere to deal with...
Read more >
Node JS Tutorial: The Basics
Whenever a new request is received, the request event is called, providing two objects: a request (an http.IncomingMessage object) and a response (an...
Read more >
Node.js Error Handling Best Practices
It's a way to see bugs in your code. Following this logic, error handling is a way to find these bugs and solve...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found