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

[feat] Decode postData params when mimeType is application/x-www-form-urlencoded #96

Merged
merged 2 commits into from
Jan 28, 2022

Conversation

EdvinasDaugirdas
Copy link
Contributor

@EdvinasDaugirdas EdvinasDaugirdas commented Jan 28, 2022

POST data with application/x-www-form-urlencoded might be encoded.
We should attempt to decode it as otherwise we'll end up with "double encoding".

Copy link
Collaborator

@legander legander left a comment

Choose a reason for hiding this comment

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

Sweet! It works nicely too 🙌 I left a few small comments, check em out and decide if you want to make a change or not.
Consider adding this change too to fix the BOM issue https://github.com/grafana/har-to-k6/pull/75/files#diff-6c8538269ea8beb3f861758572b0197f510b809890216c333e8a1a034b021b85

return entry
}

if (entry.request.method !== 'POST' || !entry.request.postData) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Other verbs are can have postData too not only POST, maybe we should just be checking entry.request.postData here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, makes sense.

}

if (
entry.request.postData.mimeType !== 'application/x-www-form-urlencoded' ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

it is not uncommon that mimeType here will include a chartset like application/x-www-form-urlencoded;charset=UTF-8 which would make this not match, look into using the helper function in aid.js called getContentTypeValue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, gonna update

entries = getSortedEntries(entries, options)
entries = getDecodedPostDataParamEntries(entries)
return entries
}
Copy link
Collaborator

@legander legander Jan 28, 2022

Choose a reason for hiding this comment

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

I think we should try to avoid reassignment as much as possible and always return new objects. I know there are mutations and reassignment all over the place in the project but let's try to not add more of it. I think it will make the code easier to read, debug and produce less unexpected behaviour.
I wish we had a pipe operator here but i suppose this will also do

return getDecodedPostDataParamEntries(
  getSortedEntries(entries, options)
)

// Alternatively 
const sortedEntries = getSortedEntries(entries, options)
return getDecodedPostDataParamEntries(sortedEntries)

It looks like getSortedEntries does a little more than sorting, perhaps a more fitting name would be setSleepTimings or createSleepStatements idk wdyt? 🤷‍♀️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeaaaah, agree with reassignment 👍

The getSortedEntries is probably more fitting than setSleepTimings or createSleepStatements. It will always sort entries if there's a startedDateTime available, but only add sleep properties if { addSleep: true } option is passed.

Copy link
Collaborator

@legander legander Jan 28, 2022

Choose a reason for hiding this comment

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

Fair enough 👍
It would have maybe made sense to split the two to separate the concerns then.

sortEntries
decodePostdataParams

if (options.addSleep) {
   return withSleep(..)
}

return result

@EdvinasDaugirdas EdvinasDaugirdas merged commit d893ac5 into master Jan 28, 2022
@EdvinasDaugirdas EdvinasDaugirdas deleted the feat/normalize-url-encoded-postdata branch January 28, 2022 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improved percent/URL-encoding
2 participants