Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support handling=strict for Prefer header #2943

Closed
steve-chavez opened this issue Sep 13, 2023 · 2 comments · Fixed by #2969
Closed

Support handling=strict for Prefer header #2943

steve-chavez opened this issue Sep 13, 2023 · 2 comments · Fixed by #2969
Labels
difficulty: beginner Pure Haskell task enhancement a feature, ready for implementation

Comments

@steve-chavez
Copy link
Member

Problem

Currently any unrecognized Prefer value will be accepted and ignored:

$ curl 'localhost:3000/projects' -H "Prefer: anything" -D -
HTTP/1.1 200 OK

[{"id":1,"name":"Windows 7","client_id":1}, 
 {"id":2,"name":"Windows 10","client_id":1}, 
 {"id":3,"name":"IOS","client_id":2}, 
 {"id":4,"name":"OSX","client_id":2}, 
 {"id":5,"name":"Orphan","client_id":null}]

This can give issues when you don't know what Prefer values a deployed PostgREST accepts (discussed on #2940 (comment)).

Solution

Support Prefer: handling=strict according https://www.rfc-editor.org/rfc/rfc7240.html#section-4.4. This would allow the client to check what Prefer values are accepted:

$ curl 'localhost:3000/projects' -H "Prefer: handling=strict; anything" -D -
HTTP/1.1 400 Bad Request

Using Prefer: handling=lenient would just accept and ignore the Prefer, as we've always done.

Details

The logic that filters the accepted Prefers is currently on the Response module.

prefHeader = maybeToList . prefAppliedHeader $ Preferences Nothing Nothing Nothing preferCount preferTransaction Nothing

Preferences (if null pkCols && isNothing (qsOnConflict iQueryParams) then Nothing else preferResolution)

It'd be better centralized at the Plan module. There we can fail and respond with an error.

@steve-chavez steve-chavez added enhancement a feature, ready for implementation difficulty: beginner Pure Haskell task labels Sep 13, 2023
@taimoorzaeem
Copy link
Collaborator

@steve-chavez In which module should I write tests for this feature? Or maybe should I create a new test module for this feature?

@steve-chavez
Copy link
Member Author

steve-chavez commented Sep 26, 2023

@taimoorzaeem A new test module seems fine, maybe PreferencesSpec

(we might move all the Prefer tests there later on)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: beginner Pure Haskell task enhancement a feature, ready for implementation
Development

Successfully merging a pull request may close this issue.

2 participants