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

Fix: remove CURLRequest headers sharing from $_SERVER #5249

Merged
merged 21 commits into from
Nov 1, 2021

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Oct 28, 2021

Description
Alternative to #5218 (Inclueds #5218)
Fixes #4826

  • populateHeaders() which gets request headers from the browser and sets the same headers to the curl request and shares the headers between curl requests, is a bug. So remove populateHeaders() logic completely
  • add Config\CURLRequest::$shareOptions. The default is true
    • if false,
      • all options are reset after sending a request
      • $defaultOptions which are passed in the constructor are applied to all requests
  • share $option['headers'] except $unsharedHeaders between curl requests
  • remove CURLRequestTest::testOptionsHeadersUsingPopulate()

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added the breaking change Pull requests that may break existing functionalities label Oct 28, 2021
@kenjis kenjis changed the title Fix: remove CURLRequest headers sharing Fix: remove CURLRequest headers sharing from $_SERVER Oct 28, 2021
@kenjis kenjis requested review from MGatner and michalsn October 28, 2021 05:06
@MGatner
Copy link
Member

MGatner commented Oct 28, 2021

Initial review looks good but I will take a deeper look on desktop.

Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

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

I think that removing populateHeaders() call when the headers array is empty will solve most of the problems that users had. We will need an entry in the changelog for this - if it gonna be merged.

The real question is how big a problem for devs these changes will be... My point is that missing some headers that were populated before may cause some requests to not work. Personally, I have always specified my own headers, but it looks like a lot of people have not.

system/HTTP/CURLRequest.php Outdated Show resolved Hide resolved
system/HTTP/CURLRequest.php Outdated Show resolved Hide resolved
To override the values.
If user setHeader() that is defined in $unsharedHeaders, the header will be removed
before sending request, and there is no way to send the header.

The reason I didn't do the reset after sending is because a test failed.
This time I modify the test, too.
@kenjis
Copy link
Member Author

kenjis commented Oct 29, 2021

The real question is how big a problem for devs these changes will be... My point is that missing some headers that were populated before may cause some requests to not work. Personally, I have always specified my own headers, but it looks like a lot of people have not.

I guess it is very small. But I have no data.

@kenjis
Copy link
Member Author

kenjis commented Oct 29, 2021

Added one fix and documentation.

user_guide_src/source/changelogs/v4.1.5.rst Outdated Show resolved Hide resolved
user_guide_src/source/installation/upgrade_415.rst Outdated Show resolved Hide resolved
system/HTTP/CURLRequest.php Outdated Show resolved Hide resolved
$defaultOptions is options passed in the constructor.
They are applied for all requests.
All request headers are cleared after sending request,
and $defaultOptions are set again.
@kenjis
Copy link
Member Author

kenjis commented Oct 29, 2021

I removed $unsharedHeaders and added $defaultOptions.

$defaultOptions is the options passed in the constructor.
They are applied to all requests.

In other words, there are two kind of options. The default options
and the other options.

After sending a request, all headers are cleared. And $defaultOptions
are parsed again.

I wanted to reset all $config, too. But I'm not sure I can do it, so only
$this->config['multipart'] and $this->config['form_params'] are unset.

kenjis and others added 3 commits October 29, 2021 16:22
The explanation was not accurate.

Co-authored-by: Michal Sniatala <[email protected]>
The explanation was not accurate.

Co-authored-by: Michal Sniatala <[email protected]>
If $CURLRequestShareOptions is false, reset all config after sending a request.
If true, keep the all config (the same as before).
@kenjis
Copy link
Member Author

kenjis commented Oct 29, 2021

Added Config\App::$CURLRequestShareOptions. The default is true.
Only when set to false, all config are reset after sending a request,
and set the defaultOptions.

app/Config/App.php Outdated Show resolved Hide resolved
@WinterSilence
Copy link
Contributor

WinterSilence commented Oct 29, 2021

  1. let's use other namespace to keep BC
  2. at first need create class skeleton (architecture)
    2.1. extract curl options in "config" class

Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

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

Nice work @kenjis, I think it looks really good.

The only important thing that is missing is the separate config file and some documentation for this new feature (shareOptions).

app/Config/App.php Outdated Show resolved Hide resolved
system/HTTP/CURLRequest.php Outdated Show resolved Hide resolved
system/HTTP/CURLRequest.php Outdated Show resolved Hide resolved
system/HTTP/CURLRequest.php Outdated Show resolved Hide resolved
@michalsn
Copy link
Member

  • let's use other namespace to keep BC
  • at first need create class skeletons (architecture)
    2.1. extract curl options in "config" class

@WinterSilence I'm not sure if I'm understanding you correctly, but if you're proposing to add a new implementation of this class because of BC, that's not going to happen. The possible BC break is accidental and is a derivative from a bug that is now fixed.

Technically speaking we are dealing with a bug here. However, we are aware that fixing it may lead to problems in some cases. Therefore, we raise this issue in the changelog and upgrade notes.

@kenjis
Copy link
Member Author

kenjis commented Oct 30, 2021

@WinterSilence I'm also not get what you want to say.

@WinterSilence
Copy link
Contributor

@kenjis I want minimal changes in "behavior" of current classes i.e. save public part "as is". Next release is not new major version - BC not allowed. But some errors can't be solved without BC, so I suggest a temporary solution - similar classes with fixes - users will choose version to use. Old/deprecated classes will be removed in next major version.

Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

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

From my point of view, this is ready. Thanks!

@kenjis
Copy link
Member Author

kenjis commented Nov 1, 2021

@WinterSilence I thought that old/new two classes.
If we have two classes, we have to maintain two classes.

Adding config for a new behavior is a bit better than maintaining two classes, I thought.
And users can use the new behavior, just set the config.

@kenjis kenjis merged commit dbbdd2d into codeigniter4:develop Nov 1, 2021
@kenjis kenjis deleted the remove-curl-headers-sharing branch November 1, 2021 00:38
@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Pull requests that may break existing functionalities bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Extra Headers on CURLRequest
4 participants