This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Work around issue with GET requests with json content type and invali…

…d body

Related to senchalabs/connect#680
  • Loading branch information...
evdb committed Nov 30, 2012
1 parent ca40625 commit c19ec848c0421f27f9aac54c2d1b91ac2bde58f7
Showing with 24 additions and 0 deletions.
  1. +9 −0 server.js
  2. +15 −0 tests/api/basics.js
View
@@ -15,6 +15,15 @@ var express = require('express'),
var app = express();
+// Intercept JSON content type GET requests and change the header.
+// this is a workaround for https://github.com/senchalabs/connect/issues/680 which hopefully will be fixed upstream
+app.use( function (req, res, next) {
+ if ( req.method == "GET" && req.headers['content-type'] == 'application/json' ) {
+ delete req.headers['content-type'];
+ }
+ next();
+});
+
// match the hosting app host...
app.use(
express.vhost(
View
@@ -31,6 +31,21 @@ module.exports = {
test_server_helpers.stop_server(tearDown_done);
},
+ "GET with content-type of json and no body": function (test) {
+ // this is a workaround for https://github.com/senchalabs/connect/issues/680 which hopefully will be fixed upstream
+ test.expect(1);
+ this.rest
+ .get('',{
+ headers: {'Content-Type': 'application/json'}, // set json...
+ data: '', // ... but include no data
+ })
+ .on('complete', function(data, response) {
+ test.equal(response.statusCode, 200, "got 200 response");
+ test.done();
+ });
+
+ },
+
"access API docs": function (test) {
test.expect(2);

0 comments on commit c19ec84

Please sign in to comment.