SamDecrock / node-http-ntlm

Node.js module to authenticate using HTTP NTLM
MIT License
192 stars 89 forks source link

Can't set "Content-Type" #75

Closed AndersGerner closed 1 year ago

AndersGerner commented 6 years ago

When trying to set request to have Content-Type header, then it writes the header as 'Content-type' so the server doesn't parse it, because it's written in quotes ' '.

Anybody got an idea on how I can set the header to have content-type: application/json ?

Thanks in advance

SamDecrock commented 6 years ago

I don't think that's possible. Are your sure?

AndersGerner commented 6 years ago

Thanks for quick response @SamDecrock :)

For Sharepoint REST API, I need to set the Accept and Content-Type headers to application/json. Otherwise it returns the response in XML.

But it doesn't seem to be working :(

Wouldn't I just update the request object in the options like this?

const options = {
  url: 'MySharepointSite,
  username: 'USERNAME',
  password: '********',
  workstation: '',
  domain: '',
  request: {
    'Accept': 'application/json;odata=verbose',
        'Content-Type': 'application/json',
  },
};
SamDecrock commented 6 years ago

There is no object called request in my library ;-)

I think this should work:

const options = {
  url: 'MySharepointSite',
  username: 'USERNAME',
  password: '********',
  workstation: '',
  domain: '',
  headers: {
    'Accept': 'application/json;odata=verbose',
        'Content-Type': 'application/json',
  },
};
bradwallen commented 4 years ago

I'm actually seeing the same thing as the OP. I sent my Content-Type as application/x-www-form-urlencoded and this is what I get in the log: headers: { 'Content-Type': 'application/x-www-form-urlencoded', Connection: 'keep-alive', Note how Content-Type is enclosed in single quotes...

Here's the line of code: headers: { 'Content-Type': "application/x-www-form-urlencoded", "Connection": "keep-alive",

naavis commented 3 years ago

I'm having a similar problem with setting the User-Agent header in the requests. The server I am connecting to allows me to use NTLM authentication only if User-Agent is set to a specific value.

I can see from httpntlm.js that is is explicitely not using headers passed in via the options: type1options = _.extend({}, _.omit(httpreqOptions, 'headers', 'body'), type1options);

SamDecrock commented 1 year ago

Indeed, I will add the option to set custom headers back in. But first I need to write some extra tests to make sure I don't break anything.

SamDecrock commented 1 year ago

I added the option to pass in custom headers, see https://github.com/SamDecrock/node-http-ntlm#pass-in-custom-headers for an example. This is available from version 1.8.10

creage commented 1 year ago

@SamDecrock This commit https://github.com/SamDecrock/node-http-ntlm/commit/f2c71c9a8cc956685b957bb993c601dfdceff245 breaks authorization when used with headers option. Basically, v1.8.9 works, v1.8.10 fails.