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

[WIP] Tweak Request API behavior for multi-value parameters & headers #1521

Closed
wants to merge 2 commits into from

Conversation

yozlet
Copy link

@yozlet yozlet commented May 23, 2019

Closes #1518, with the changes proposed by @gschier (unless discussion takes us elsewhere):

  • Change getParameter to return a string for single matches and an array for multiple
  • Change setParameter to remove all instances of key and replace with a single new one
  • Leave addParameter(name: string) as is, since it's working as expected. The method name might be a bit confusing, but the purpose of this one is to only set the parameter if one by that name does not yet exist.

@welcome
Copy link

welcome bot commented May 23, 2019

💖 Thanks for opening this pull request! 💖

To help make this a smooth process, please be sure you have first read the
contributing guidelines.

Copy link
Contributor

@gschier gschier left a comment

Choose a reason for hiding this comment

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

Good start here! There should be too much more to get this done 👍 😄

@@ -97,7 +97,13 @@ describe('request.*', () => {
{ name: 'hello', value: 'world' },
{ name: 'Content-Type', value: 'application/json' },
],
parameters: [{ name: 'foo', value: 'bar' }, { name: 'message', value: 'Hello World!' }],
parameters: [
{ name: 'foo', value: 'bar' },
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change the test data to the following?

        { name: 'foo', value: 'bar' },
        { name: 'multi', value: 'a' },
        { name: 'message', value: 'Hello World!' },
        { name: 'multi', value: 'b' },
        { name: 'multi', value: 'c' },
        { name: 'trailing', value: 't' },

At first glance, it looks like your code does not preserve the position when using setParameter when multiple exist.

What do you think the behavior should be in this case?

  • Never preserve position
  • Replace first occurrence and delete the rest
  • Replace last occurrence and delete the rest

Let me know what you think 🤔

Copy link
Author

@yozlet yozlet May 31, 2019

Choose a reason for hiding this comment

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

Honestly, I have no idea, and I'd be interested to hear arguments for any of them. In the meantime, maybe it'd be best to explicitly:

  1. not make a decision here
  2. say so in the API docs (as in something like "Setting a parameter may change its position in the list. This behaviour is currently undefined, so don't depend on it as it may change in future.")


// setHeader()
// setParameter()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch!

@yozlet
Copy link
Author

yozlet commented May 31, 2019

Sorry that this is taking a while! I have a load of work on right now, but I'd like to get back to this when I can. In the meantime, anyone who's interested should feel free to continue without me.

@yozlet
Copy link
Author

yozlet commented May 31, 2019

@gschier Talking of documentation (as I do in one of the threads above): I'm happy to update the API docs to go with this change, but I don't see them anywhere. Are they open to editing in some way, or should I leave that to you?

@stale
Copy link

stale bot commented Jul 30, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Bot: Stale Issue label Jul 30, 2019
@stale stale bot closed this Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Bot: Stale Issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Request API is inconsistent when dealing with multi-value parameters
2 participants