Skip to content
This repository has been archived by the owner on Apr 20, 2019. It is now read-only.

Adds a feature where even request with GET query strings having dependent values can be pipelined #96

Merged
merged 3 commits into from
Sep 30, 2018

Conversation

adisingh007
Copy link
Contributor

@adisingh007 adisingh007 commented Sep 5, 2018

Closes #95

Now when the requests are:

{
    "requests": [
        {
             "method": "GET",
             "path": "/get/product?product_id=564"
        },
        {
             "method": "GET",
             "path": "/get/manufacturer",
             "query": {
                 "manufacturter_id": "$0.manufacturer_id"
             }
        }
    ]
}

inspite of being a query parameter(and not a path parameter), $0.manufacturer_id will now be parsed.

Hence, even pipe lined query parameters will now be parsed if dependent on previous requests.

Copy link
Contributor

@cadecairos cadecairos left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @adisingh007, this is a great first step but there's a few things that need to be worked on before we can land this.

test/batch.js Outdated

it('Now parses URL query params in pipelined requests', async () => {

const res = await Internals.makeRequest(server, `{ "requests": [ {"method": "get", "path": "/string/${encodeURI('Aditya Pratap Singh')}"}, { "method": "get", "path": "/profile", "query": {"id": "$0"}}, { "method": "post", "path": "/echo", "payload": { "name": "$1.id" }} ] }`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make the test string a non-identifying piece of data, rather than your full name.

test/batch.js Outdated

expect(res[0]).to.equal('Aditya Pratap Singh');
expect(res[1].id).to.equal('Aditya Pratap Singh');
expect(res[2].name).to.equal('Aditya Pratap Singh');
Copy link
Contributor

Choose a reason for hiding this comment

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

Same request here, and the lines above.

lib/batch.js Outdated
@@ -33,6 +33,10 @@ module.exports.config = function (settings) {

request.payload.requests.every((req, idx) => {

if (req.query) {
req.payload = req.query;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not convert query parameters into request payloads in order to pipeline data into query parameters.

Bassmaster should look at the request it's processing, and if it contains a query object, it should see if previous request responses need to be pipelined into it before constructing a URL and injecting it.

Copy link
Contributor Author

@adisingh007 adisingh007 Sep 16, 2018

Choose a reason for hiding this comment

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

@cadecairos Hello Chris,
I have made another commit. Please have a look at it. Just how it was desired. Bassmaster looks at the request it is processing, and if the request contains a query object, it sees if the previous request responses needs to be pipelined into it before constructing a URL and injecting it. Wrote a test case too to cover the same.

Please review and let me know if anything else also needs to be done.

Thankyou,
Aditya

@adisingh007 adisingh007 force-pushed the hapi#bassmaster#95 branch 3 times, most recently from deca5ce to 18453c5 Compare September 16, 2018 17:59
@adisingh007
Copy link
Contributor Author

adisingh007 commented Sep 17, 2018 via email

@adisingh007 adisingh007 changed the title Hapi#bassmaster#95 Adds a feature where even request with GET query strings having dependent values can be pipelined Sep 18, 2018
Copy link
Contributor

@cadecairos cadecairos left a comment

Choose a reason for hiding this comment

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

This is great! I have one requested change!

lib/batch.js Outdated

internals.requestRegex = /(?:\/)(?:\$(\d+)\.)?([^\/\$]*)/g;

internals.parsePayload = function (obj) {
internals.parseParsable = function (obj) {
Copy link
Contributor

Choose a reason for hiding this comment

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

lets just call this parse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

… both pipelinable query and pipelinable payload objects
Copy link
Contributor

@cadecairos cadecairos left a comment

Choose a reason for hiding this comment

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

Wonderful stuff, thanks @adisingh007

@cadecairos cadecairos merged commit c371d51 into outmoded:master Sep 30, 2018
@adisingh007 adisingh007 deleted the hapi#bassmaster#95 branch September 30, 2018 04:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants