adamchainz/apig-wsgi

Ability to have custom white list for non binary content types

Closed this issue · 2 comments

v1k45 commented

Problem

The Response class has a whitelist of "non binary content types" which includes:

  • text/*
  • application/json

non_binary_content_types = ("text/", "application/json")

All other response types are assumed to be binary if binary_support is True.

This becomes a problem if you want to return text content for other content types. For example, JSON:API APIs have application/vnd.api+json content type.

Possible solution

The library should provide ability to either extend the Response class or pass the non_binary_content_types directly to make_lambda_handler call.

wsgi_handler = make_lambda_handler(application, binary_support=True, response_class=MyResponse)

wsgi_handler = make_lambda_handler(application, binary_support=True, non_binary_content_types=my_content_type_list)

I can create PR for either of these approaches.

What do you think?

I'd go with the latter, maybe call it non_binary_content_type_prefixes ?

But I'd also add application/vnd.api+json to the defaults so others don't have to think about it!

v1k45 commented

Sounds good, I'll create PR later this week.