Skip to content

check body length instead of 304 code to determine there is no body #399

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/steps/decorateUserRes.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function decorateProxyResBody(container) {
var req = container.user.req;
var res = container.user.res;

if (res.statusCode === 304) {
debug('Skipping userResDecorator on response 304');
if (proxyResData.length === 0) {
debug('Skipping userResDecorator on response with empty proxyResData');
return Promise.resolve(container);
}

Expand Down
2 changes: 1 addition & 1 deletion test/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('proxies status code', function () {
server.close();
});

[304, 404, 200, 401, 500].forEach(function (status) {
[301, 302, 304, 404, 200, 401, 500].forEach(function (status) {
it('on ' + status, function (done) {
request(proxyServer)
.get('/status/' + status)
Expand Down
44 changes: 26 additions & 18 deletions test/userResDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,46 @@ var assert = require('assert');
var express = require('express');
var request = require('supertest');
var proxy = require('../');
var http = require('http');

describe('userResDecorator', function () {

describe('when handling a 304', function () {
describe('when handling no body', function () {
this.timeout(10000);

var app;
var slowTarget;
var serverReference;
var noBodyTarget;
var serverReference;
var responseCode;

beforeEach(function () {
app = express();
slowTarget = express();
slowTarget.use(function (req, res) { res.sendStatus(304); });
serverReference = slowTarget.listen(12345);
noBodyTarget = new http.Server();
noBodyTarget.on('request', function (req, res) {
res.writeHead(responseCode, { 'Content-Length': '0' });
res.end();
});
serverReference = noBodyTarget.listen(12345);
});

afterEach(function () {
serverReference.close();
});

it('skips any handling', function (done) {
app.use('/proxy', proxy('http://127.0.0.1:12345', {
userResDecorator: function (/*res*/) {
throw new Error('expected to never get here because this step should be skipped for 304');
}
}));

request(app)
.get('/proxy')
.expect(304)
.end(done);
[200, 201, 204, 205, 301, 302, 304, 400, 500].forEach(function (status) {
it('skips any handling for ' + status, function (done) {
responseCode = status;
app.use('/proxy', proxy('http://127.0.0.1:12345', {
userResDecorator: function (/*res*/) {
throw new Error('expected to never get here because this step should be skipped for ' +
status + ' with no body');
}
}));

request(app)
.get('/proxy')
.expect(status)
.end(done);
});
});
});

Expand Down