Skip to content

Duplicate chunks on JSON response #380

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

Closed
agaskell opened this issue Jul 21, 2014 · 4 comments
Closed

Duplicate chunks on JSON response #380

agaskell opened this issue Jul 21, 2014 · 4 comments
Labels

Comments

@agaskell
Copy link

I came across this question on Stack Overflow and I was able to reproduce. If the response size is large enough the response body will be duplicated.

Code from the question:

Controller

// Get list of worlds
exports.index = function(req, res) {
  World.find(function (err, worlds) {
    if(err) { return handleError(res, err); }
    res.json(200, worlds);
  });
};

Model

'use strict';

var mongoose = require('mongoose'),
    Schema = mongoose.Schema;

var WorldSchema = new Schema({
  name: String,
  info: String,
  active: Boolean,
  tiles: [Schema.Types.Mixed]
});

module.exports = mongoose.model('World', WorldSchema);

Seed

 var newWorld = new WorldModel({
                    _id: planet._objectId,
                    name: "SimDD World",
                    tiles : seed()
                });
                newWorld.save();

...

var seed = function () {
    var data = [];
    for (var i = 0; i < planet.HEIGHT; i++) {
        for (var j = 0; j < planet.WIDTH; j++) {
            data.push({
                coords:{
                    x:i,
                    y:j
                },
                type:'.'
            });
        }
    }
    return data;
}
@DaftMonk
Copy link
Member

I tested this and was able reproduce it as well.

It appears to be caused by the compression middleware. Removing app.use(compression()); from the express config seems to fix this.

@JaKXz JaKXz added the bug label Jul 22, 2014
@meeDamian
Copy link
Contributor

Maybe it's a good idea to report a bug here?

@DaftMonk
Copy link
Member

Actually even though I was seeing duplicate responses in chrome and firefox, when I actually looked at the network tab, or used postman, or node request, I was only seeing one object. So I'm not sure this is a bug afterall.

@uniquer
Copy link

uniquer commented Dec 19, 2014

As @DaftMonk mentioned it is seen in browsers and not in postman. I checked the HTTP request headers and when I add 'Accept' Header as html in postman the same problem is seen in postman as well. So I believe the browsers are handled/rendered differently with Accept type with html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants