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: Support response headers in File protocol handler #16098

Merged
merged 3 commits into from Dec 19, 2018

Conversation

dbkr
Copy link
Contributor

@dbkr dbkr commented Dec 17, 2018

Description of Change

This adds support for response headers to protocol.registerFileProtocol to match protocol.registerStreamProtocol.

My specific use case for this is to set a CSP for pages served from local content rather than HTTPS: setting the header by intercepting the request with the webRequest module doesn't work because URLRequestAsarJob doesn't call the network_delegate methods (see #16030). In any case, this seems like a more direct way of setting the header.

I've also changed how this works a little to make it more consistent (hopefully) with the other handlers (ie. convert the dict to a base::DictionaryValue and use base::DictionaryValue::GetFoo()).

Note that I've documented this in the text as the callback param in the list has filePath as a string. This could be changed so the callback taking an object is in the main docs: I'm happy to make this change.

Stakeholders: @zcbenz & @paulcbetts appear to have last made major changes here. cc @MarshallOfSound as you kindly helped on the issue I filed.

Test failures don't appear to be related to my changes: one of them is:

AssertionError: exit signal should be null, if you see this please tag @MarshallOfSound: expected 'SIGSEGV' to equal null

(so, cc @MarshallOfSound)

Checklist

  • PR description included and stakeholders cc'd
  • npm test passes: failures appear unrelated to my changes
  • tests are changed or added
  • relevant documentation is changed or added
  • PR title follows semantic commit guidelines

Release Notes

Notes: Add response header support to protocol.registerFileProtocol to match protocol.registerStreamProtocol.

@dbkr dbkr requested review from a team December 17, 2018 10:11
@welcome
Copy link

welcome bot commented Dec 17, 2018

💖 Thanks for opening this pull request! 💖

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@dbkr dbkr changed the title feat: Support response headers in File protocol handler [wip] feat: Support response headers in File protocol handler Dec 17, 2018
@dbkr dbkr changed the title [wip] feat: Support response headers in File protocol handler feat: Support response headers in File protocol handler Dec 17, 2018
Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

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

Premise and tests LGTM. Thanks for the patch!

Once the deprecated API use is changed I'm 👍 on this

base::DictionaryValue* headersValue = nullptr;
base::DictionaryValue* dict =
static_cast<base::DictionaryValue*>(options.get());
dict->GetString("path", &file_path);
Copy link
Member

Choose a reason for hiding this comment

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

This introduces a minor regression of going back to deprecated API:

// DEPRECATED, use Value::FindPath(path) and Value::GetString() instead.
bool GetString(StringPiece path, std::string* out_value) const;

Could you keep the previous FindKeyOfType implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, hadn't noticed that was deprecated. Fixed!

Copy link
Member

@codebytere codebytere left a comment

Choose a reason for hiding this comment

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

👍 following your latest changes!

Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

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

Thanks!

@codebytere codebytere merged commit cc85946 into electron:master Dec 19, 2018
@release-clerk
Copy link

release-clerk bot commented Dec 19, 2018

Release Notes Persisted

Add response header support to protocol.registerFileProtocol to match protocol.registerStreamProtocol.

@welcome
Copy link

welcome bot commented Dec 19, 2018

Congrats on merging your first pull request! 🎉🎉🎉

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

3 participants