Skip to content

fix(stac-api): avoid base64 encoding application/geo+json data#172

Merged
gadomski merged 4 commits into
mainfrom
fix/base64-encoded-data-with-rest-api
Jul 29, 2025
Merged

fix(stac-api): avoid base64 encoding application/geo+json data#172
gadomski merged 4 commits into
mainfrom
fix/base64-encoded-data-with-rest-api

Conversation

@alukach
Copy link
Copy Markdown
Member

@alukach alukach commented Jul 25, 2025

When using a REST API with a Lambda Proxy integration (such as when making use of our PrivateLambdaApiGateway, link), data that Mangum converts to base64 is not converted to text by the API Gateway.

By default, Mangum v0.14.1 converts any text data to base64 aside from its builtin defaults1. These defaults do not include application/geo+json which is used by the STAC API. This PR upgrades Mangum (by utilizing stac-fastapi-pgstac's unspecified mangum version2) and configures Mangum to avoid converting any data to base64 that begins with text/ or application/.

Question: Perhaps we should just disable the base64 conversion completely by specifying a text mime type of '' which would match all mime_type in content_type3 lookups?

Footnotes

  1. https://github.com/Kludex/mangum/blob/0.14.1/docs/http.md#text-mime-types

  2. https://github.com/stac-utils/stac-fastapi-pgstac/blob/d43ea548103d0e157d7e22fb70f9ea9fe310509b/setup.py#L49C6-L49C15

  3. https://github.com/Kludex/mangum/blob/0.14.1/mangum/handlers/utils.py#L79

Comment thread lib/stac-api/runtime/src/handler.py Outdated
Comment thread lib/stac-api/runtime/src/handler.py Outdated
text_mime_types=[
# Avoid base64 encoding any text/* or application/* mime-types
"text/",
"application/"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, this feels a little overbroad ... Could we just add the GeoJSON mime type instead?

Copy link
Copy Markdown
Member Author

@alukach alukach Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but there's also the Open API spec with application/vnd.oai.openapi;version=3.0. Your point regarding Parquet is valid though, would that have application/vnd.apache.parquet? And we probably wouldn't want to convert application/octet-stream either...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to ship as-is to unblock, we can always dial it back later.

@gadomski
Copy link
Copy Markdown
Contributor

Perhaps we should just disable the base64 conversion completely by specifying a text mime type of '' which would match all mime_type in content_type3 lookups?

Not sure... We might as stac-geoparquet (or some other binary format) responses down the road, in which case we might want the conversion?

@gadomski gadomski merged commit 51a1df0 into main Jul 29, 2025
5 checks passed
@gadomski gadomski deleted the fix/base64-encoded-data-with-rest-api branch July 29, 2025 12:52
github-actions Bot pushed a commit that referenced this pull request Jul 29, 2025
## [9.2.1](v9.2.0...v9.2.1) (2025-07-29)

### Bug Fixes

* **stac-api:** avoid base64 encoding application/geo+json data ([#172](#172)) ([51a1df0](51a1df0))
@ds-release-bot
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 9.2.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants