Skip to content
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

text data for post/put/patch not setting content-type #7

Open
bberry6 opened this issue Aug 5, 2015 · 1 comment
Open

text data for post/put/patch not setting content-type #7

bberry6 opened this issue Aug 5, 2015 · 1 comment
Assignees
Milestone

Comments

@bberry6
Copy link

bberry6 commented Aug 5, 2015

Heres some example code...

var express = require('express');
var bodyParser = require('body-parser');
var bhttp = require('bhttp');

var app = express();
//app.use(bodyParser.json());
app.use(bodyParser.text());

app.post('/', function (req, res) {
  console.log("Server::headers: ",req.headers);
  console.log("Server::body: ",req.body);
  console.log("Server::params: ",req.params);
  res.sendStatus(200);
});

var server = app.listen(3000, function(){
   var opts = {
      url: "http://localhost:3000/",
      data: 'test'
   };
   bhttp.post(opts.url, opts.data)
   .then(function(res){
      console.log("Client::statusCode: ", res.statusCode);
      return bhttp.post(opts.url, opts.data, {headers: {"content-type":"text/plain"}});
   })
   .then(function(res){
      console.log("Client::statusCode: ", res.statusCode);
      process.exit();
   });
});

And the output...

Server::headers:  { 'user-agent': 'bhttp/1.2.1',
  'content-length': '4',
  host: 'localhost:3000',
  connection: 'close' }
Server::body:  {}
Client::statusCode:  200
Server::headers:  { 'content-type': 'text/plain',
  'user-agent': 'bhttp/1.2.1',
  'content-length': '4',
  host: 'localhost:3000',
  connection: 'close' }
Server::body:  test
Client::statusCode:  200

There isn't any content-type passed in the first post. Only when manually defining the content type can the text/plain type be set.

Thanks!

@joepie91 joepie91 added this to the patch-next milestone Aug 18, 2015
@joepie91 joepie91 self-assigned this Aug 18, 2015
@joepie91
Copy link
Owner

To do:

  • Investigate what the RFC says about the default Content-Type; whether one exists, and what it is.
  • Investigate whether there may be any edge cases, where defaulting to text/plain for a string is not warranted.

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

No branches or pull requests

2 participants