Skip to content

Content-Type header check in response is not handling charset #391

@dkundel

Description

@dkundel

Broken:

exports.handler = async (context, event, callback) => {
  const response = new Twilio.Response();
  response.appendHeader('Content-Type', 'application/json; charset=UTF-8');
  response.setStatusCode(400);
  response.setBody(
    {message: 'I am a JSON message'}
  )
  return callback(null, response);
};

Working:

exports.handler = async (context, event, callback) => {
  const response = new Twilio.Response();
  response.appendHeader('Content-Type', 'application/json');
  response.setStatusCode(400);
  response.setBody(
    {message: 'I am a JSON message'}
  )
  return callback(null, response);
};

Instead we should adjust the check for the Content-Type header to validate that it includes application/json as opposed to being explicitly application-json.

this.headers['Content-Type'] === 'application/json'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions