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.

Hi,There I did some testing on my demo app, find some strange result. My demo app has a healthcheck, it returns with a ‘ack’ in the response (suppose ‘ack’ should be in response’s body). code fragment shows below app.get(‘/demoapp/healthcheck’, function (request, response) { response.writeHead(200, {‘Content-Type’: ‘text/plain’}); response.end(‘ack’); });

Then my test code shows below var should = require(‘should’); var assert = require(‘assert’); var request = require(‘supertest’);

describe(‘Routing’, function() { var url = ‘http://localhost:8080’;

describe(‘demoservice’, function() { it(‘do health check’, function(done) {

request(url)
.get('/demoapp/healthcheck')    
.expect(200,function(){
    console.log('expect status');
}) //Status code
.end(function(err, res) {
      if (err) {
        throw err;
      }     
      console.log(res);
      console.log(res.text);
      console.log(res.body);    
      res.text.should.have.match(/^ack/);
      done();
    });
});

}); });

In the console, output is so weird, res shows it’s ‘body’ is {}, but it has ‘text’ ‘ackack’ (not typo,it’s real two ack), is there anybody can tell me why? Thanks in advance.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:2
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kszafrancommented, Sep 28, 2018

In my case it turned out that I didn’t set the Content-Type header in responses.

Previously I was calling res.send(object), so the header was set to application/json automatically, but after changing the code to use res.write(...) and res.end(...) I had to set it myself. After that, superagent would read the whole chunked response correctly.

1reaction
gjohnsoncommented, Jul 8, 2014

Looks like a bug when you provide a callback to expect() and also .end(). It ends up calling .end() internally twice, which is what creates the “ackack” instead of just “ack”.

I suggest don’t provide a callback to .end() for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

req.body empty on posts - node.js - Stack Overflow
Whenever I make a post in nodejs using express and body-parser req.body is an empty object. var express = require('express') var bodyParser = ......
Read more >
req.body is empty in POST requests : r/node - Reddit
Hi! I know this is basically a noob question but please bear with me. I noticed that POST requests on my node server...
Read more >
MVC's detection of an empty body in model binding changed
The mechanism to detect an empty request body during MVC model binding now uses IHttpRequestBodyDetectionFeature.CanHaveBody. This property is ...
Read more >
Why is my message empty? - Apache Camel
In Camel the message body can be of any types. Some types are safely readable multiple times, and therefore do not 'suffer' from...
Read more >
wp_remote_post sends empty body - WordPress.org
on the api side if i try to read the request body it is an empty JSON. As i thought that was an...
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