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

[Feature] Prettify Json When Saving Response To File #1829

Merged

Conversation

@elemanhillary
Copy link
Contributor

elemanhillary commented Dec 6, 2019

Closes #764

Copy link
Contributor

gschier left a comment

Hey @elemanhillary, thanks for taking a crack at this! I've left quite a few comments here so let me know if you have any questions.

I also think we should present an additional dropdown button to save "prettified" response because saving the original un-prettified response is still something that should be possible.

@gschier gschier self-assigned this Dec 11, 2019
@elemanhillary elemanhillary force-pushed the elemanhillary:feature/prettify_json_when_saving_response branch 3 times, most recently from cf04e5a to 4f564f4 Dec 12, 2019
Copy link
Contributor

gschier left a comment

Just a couple more comments 🙂

@@ -96,11 +98,21 @@ class ResponsePane extends React.PureComponent<Props> {
}

const readStream = models.response.getBodyStream(response);
let responseBody = '';

This comment has been minimized.

Copy link
@gschier

gschier Dec 12, 2019

Contributor

Since this is a string, your logic will force data to be converted from a Buffer a string. For binary data, we need to ensure that it remains a Buffer if it's not a string content-type (eg. PDF document, Image, or mp3).

There's some other code that does this over here that can be referenced:

const dataBuffers = [];
part.on('data', data => {
dataBuffers.push(data);
});

});
readStream.on('end', () => {
const to = fs.createWriteStream(outputPath);
to.write(prettify.json(responseBody));

This comment has been minimized.

Copy link
@gschier

gschier Dec 12, 2019

Contributor

Nice! I think the only thing left to do here is add a check to see if the content type is actually JSON.

There is a contentType variable defined above that can be used to see if it contains the substring json. If it is not JSON, we should leave it unprocessed.

This comment has been minimized.

Copy link
@elemanhillary

elemanhillary Dec 12, 2019

Author Contributor

i don't know how i forgot that but let me work on it, it's that i get to work on insomnia when am over worked at my work place

This comment has been minimized.

Copy link
@gschier

gschier Dec 12, 2019

Contributor

No rush @elemanhillary, we're just grateful you're contributing 😄

Also, we're happy to help finish this one if you don't have the time 🤗

@elemanhillary elemanhillary force-pushed the elemanhillary:feature/prettify_json_when_saving_response branch from 4f564f4 to 7872f6d Dec 12, 2019
Copy link
Contributor

gschier left a comment

Nice, thanks for making those changes so quickly ❤️

@gschier gschier merged commit c960673 into Kong:develop Dec 12, 2019
0 of 2 checks passed
0 of 2 checks passed
Travis CI - Pull Request Build Failed
Details
continuous-integration/travis-ci/pr The Travis CI build failed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.