-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat(javascript): use the text/plain content-type #614
Conversation
in algolia/react-instantsearch#3487 I discovered the text/pain content-type is also accepted by the engine, and also doesn't create a full CORS request
✅ Deploy Preview for api-clients-automation canceled.
|
✗ The generated branch has been deleted.If the PR has been merged, you can check the generated code on the |
@@ -91,7 +91,7 @@ export function create{{capitalizedApiName}}(options: CreateClientOptions{{#hasR | |||
requestsCache: options.requestsCache, | |||
responsesCache: options.responsesCache, | |||
baseHeaders: { | |||
'content-type': 'application/x-www-form-urlencoded', | |||
'content-type': 'text/plain', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should probably be enforced by a unit test (not sure where and how)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous version didn't seem tested either. An extra test per method checking it sends the right content type maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think CTS checks the headers but never really took a look at it. Pierre will have the answer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can test for headers but we don't actually use it yet, because it was the same everywhere, definitely the time to test it ! For example in tests/CTS/methods/requests/search/assignUserId.json
we check the value of headers.x-algolia-user-id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is only done in the JS client (other clients always use application/json), and itself mostly for the browser (node could use application/json too), I couldn't find a good place for those tests
In v4 these are all allowed, and this allows users to work around possible issues we have smoothly, see eg. algolia/react-instantsearch#3487 At the same time I also simplified the passing of options in node/browser, they were double checking a variable that later overrides the original with the spread anyway. Note to self: #614 touches a similar part of the code, whichever merges last will have to deal with a conflict
🧭 What and Why
in algolia/react-instantsearch#3487 I discovered the text/pain content-type is also accepted by the engine, and also doesn't create a full CORS request.
text/plain
is preferable overapplication/x-www-form-urlencoded
as the request we send isn't actually form encoded which means that debug tools like the network panel won't parse them wrong.🎟 JIRA Ticket:
Changes included:
🧪 Test
run requests and see that everything works with text/plain, especially including different clients like recommend.