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/ajax response headers #6057

Merged
merged 2 commits into from Feb 26, 2021

Conversation

benlesh
Copy link
Member

@benlesh benlesh commented Feb 26, 2021

Adds a feature that allows the user to examine response headers more easily (based loosely off of prior art from contemporary libraries):

ajax(url).subscribe(response => {
   console.log(response.responseHeaders); 
});
   /**
    * logs:
    * { "content-type": "application/json", "x-custom-header": "etc" }
    */

@benlesh
Copy link
Member Author

benlesh commented Feb 26, 2021

Ugh... Object.fromEntries is too new 😿

@benlesh
Copy link
Member Author

benlesh commented Feb 26, 2021

No biggy... it's probably more efficient as a reduce :)

Copy link
Collaborator

@cartant cartant left a comment

Choose a reason for hiding this comment

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

LGTM, but maybe use a getter?

Comment on lines +99 to +109
this.responseHeaders = allHeaders
? // Split the header text into lines
allHeaders.split('\n').reduce((headers: Record<string, string>, line) => {
// Split the lines on the first ": " as
// "key: value". Note that the value could
// technically have a ": " in it.
const index = line.indexOf(': ');
headers[line.slice(0, index)] = line.slice(index + 2);
return headers;
}, {})
: {};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we could implement responseHeaders as a getter so that the headers don't have to be parsed for every response?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did that initially, but then I had a add a private property, tests got messy, I got lazy because it was 2am, etc. Happy to take another pass at that in a follow up PR, though.

@benlesh benlesh merged commit 6b90086 into ReactiveX:master Feb 26, 2021
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.

None yet

2 participants