Express: req.body empty when accept-encoding is 'gzip, deflate'
I'm attempting to receive a webhook from a 3rd party. Whilst I can see the content-length > 0, console.logging the req.body simply yields {}. The request is being sent to the route '/v2/wtevr/report/wtevr'.
These are the headers received from the webhook POST request:
accept: '*/*',
'accept-encoding': 'gzip, deflate',
'user-agent': 'rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.3p105',
'content-type': 'application/vnd.wtevr.wtevr.leadwebhook+json;version=0.0.2',
'content-length': '254',
host: 'api.mysite.co.uk'
I'm using Express' body-parser to parse the response. According to the Express docs, body-parser supports automatic inflation of 'gzip' and 'deflate' encodings. I've specified the content-type to catch the request and unzip it, but it's not working. This is what my code looks like:
app.use(
function(req, res, next) {
if (req.url === '/v2/wtevr/report/wtevr') {
next();
}
}
)
app.use(bodyParser.json({type: ['application/json', 'application/vnd.wtevr.wtevr.leadwebhook+json;version=0.0.2']}));
app.use(bodyParser.urlencoded({ extended: true }));
Does anyone know how I can parse/view the body?
node.js express gzip body-parser
add a comment |
I'm attempting to receive a webhook from a 3rd party. Whilst I can see the content-length > 0, console.logging the req.body simply yields {}. The request is being sent to the route '/v2/wtevr/report/wtevr'.
These are the headers received from the webhook POST request:
accept: '*/*',
'accept-encoding': 'gzip, deflate',
'user-agent': 'rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.3p105',
'content-type': 'application/vnd.wtevr.wtevr.leadwebhook+json;version=0.0.2',
'content-length': '254',
host: 'api.mysite.co.uk'
I'm using Express' body-parser to parse the response. According to the Express docs, body-parser supports automatic inflation of 'gzip' and 'deflate' encodings. I've specified the content-type to catch the request and unzip it, but it's not working. This is what my code looks like:
app.use(
function(req, res, next) {
if (req.url === '/v2/wtevr/report/wtevr') {
next();
}
}
)
app.use(bodyParser.json({type: ['application/json', 'application/vnd.wtevr.wtevr.leadwebhook+json;version=0.0.2']}));
app.use(bodyParser.urlencoded({ extended: true }));
Does anyone know how I can parse/view the body?
node.js express gzip body-parser
add a comment |
I'm attempting to receive a webhook from a 3rd party. Whilst I can see the content-length > 0, console.logging the req.body simply yields {}. The request is being sent to the route '/v2/wtevr/report/wtevr'.
These are the headers received from the webhook POST request:
accept: '*/*',
'accept-encoding': 'gzip, deflate',
'user-agent': 'rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.3p105',
'content-type': 'application/vnd.wtevr.wtevr.leadwebhook+json;version=0.0.2',
'content-length': '254',
host: 'api.mysite.co.uk'
I'm using Express' body-parser to parse the response. According to the Express docs, body-parser supports automatic inflation of 'gzip' and 'deflate' encodings. I've specified the content-type to catch the request and unzip it, but it's not working. This is what my code looks like:
app.use(
function(req, res, next) {
if (req.url === '/v2/wtevr/report/wtevr') {
next();
}
}
)
app.use(bodyParser.json({type: ['application/json', 'application/vnd.wtevr.wtevr.leadwebhook+json;version=0.0.2']}));
app.use(bodyParser.urlencoded({ extended: true }));
Does anyone know how I can parse/view the body?
node.js express gzip body-parser
I'm attempting to receive a webhook from a 3rd party. Whilst I can see the content-length > 0, console.logging the req.body simply yields {}. The request is being sent to the route '/v2/wtevr/report/wtevr'.
These are the headers received from the webhook POST request:
accept: '*/*',
'accept-encoding': 'gzip, deflate',
'user-agent': 'rest-client/2.0.2 (linux-gnu x86_64) ruby/2.5.3p105',
'content-type': 'application/vnd.wtevr.wtevr.leadwebhook+json;version=0.0.2',
'content-length': '254',
host: 'api.mysite.co.uk'
I'm using Express' body-parser to parse the response. According to the Express docs, body-parser supports automatic inflation of 'gzip' and 'deflate' encodings. I've specified the content-type to catch the request and unzip it, but it's not working. This is what my code looks like:
app.use(
function(req, res, next) {
if (req.url === '/v2/wtevr/report/wtevr') {
next();
}
}
)
app.use(bodyParser.json({type: ['application/json', 'application/vnd.wtevr.wtevr.leadwebhook+json;version=0.0.2']}));
app.use(bodyParser.urlencoded({ extended: true }));
Does anyone know how I can parse/view the body?
node.js express gzip body-parser
node.js express gzip body-parser
asked Dec 30 '18 at 17:20
Robert SamarjiRobert Samarji
315
315
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Managed to solve my own question. The solution was to not specify the custom content-type as an exact string in the 'type' option of the body-parser's .json function, but to either use a wildcard or to specify it exactly but as a function.
Either of the two code snippets below work:
app.use(bodyParser.json({type: (req) => req.get('Content-Type') === 'application/vnd.wtevr.wtevr.leadwebhook+json;version=0.0.2'}));
app.use(bodyParser.json());
or
app.use(bodyParser.json({type: ['application/json', 'application/*+json']}));
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979785%2fexpress-req-body-empty-when-accept-encoding-is-gzip-deflate%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Managed to solve my own question. The solution was to not specify the custom content-type as an exact string in the 'type' option of the body-parser's .json function, but to either use a wildcard or to specify it exactly but as a function.
Either of the two code snippets below work:
app.use(bodyParser.json({type: (req) => req.get('Content-Type') === 'application/vnd.wtevr.wtevr.leadwebhook+json;version=0.0.2'}));
app.use(bodyParser.json());
or
app.use(bodyParser.json({type: ['application/json', 'application/*+json']}));
add a comment |
Managed to solve my own question. The solution was to not specify the custom content-type as an exact string in the 'type' option of the body-parser's .json function, but to either use a wildcard or to specify it exactly but as a function.
Either of the two code snippets below work:
app.use(bodyParser.json({type: (req) => req.get('Content-Type') === 'application/vnd.wtevr.wtevr.leadwebhook+json;version=0.0.2'}));
app.use(bodyParser.json());
or
app.use(bodyParser.json({type: ['application/json', 'application/*+json']}));
add a comment |
Managed to solve my own question. The solution was to not specify the custom content-type as an exact string in the 'type' option of the body-parser's .json function, but to either use a wildcard or to specify it exactly but as a function.
Either of the two code snippets below work:
app.use(bodyParser.json({type: (req) => req.get('Content-Type') === 'application/vnd.wtevr.wtevr.leadwebhook+json;version=0.0.2'}));
app.use(bodyParser.json());
or
app.use(bodyParser.json({type: ['application/json', 'application/*+json']}));
Managed to solve my own question. The solution was to not specify the custom content-type as an exact string in the 'type' option of the body-parser's .json function, but to either use a wildcard or to specify it exactly but as a function.
Either of the two code snippets below work:
app.use(bodyParser.json({type: (req) => req.get('Content-Type') === 'application/vnd.wtevr.wtevr.leadwebhook+json;version=0.0.2'}));
app.use(bodyParser.json());
or
app.use(bodyParser.json({type: ['application/json', 'application/*+json']}));
edited Dec 31 '18 at 0:52
answered Dec 31 '18 at 0:22
Robert SamarjiRobert Samarji
315
315
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979785%2fexpress-req-body-empty-when-accept-encoding-is-gzip-deflate%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown