Improve handling of active URLs (esp HTTPS construction) #236
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Improve the integration between
cv
, its URL inputs, and the common$_SERVER
variables. Specifically, if you give the--url
option, then it will set variables likeHTTP_HOST
,HTTPS
, andSERVER_PORT
By setting these server-variables, we should give better hints to any URL-generating functions in CMS or Civi.
The older options
--cms-base-url
and--hostname
are retained as unpublicized aliases. The new--url
option is the combined+expanded replacement.Example Problem
In civicrm/civicrm-core#31271, @seamuslee001 mentions the use-case where one installs a WordPress site with an HTTPS address:
cv core:install --cms-base-url='https://example.com/'
This URL is properly recorded in
CIVICRM_UF_BASEURL
. However, when calling APIs to generate URLs (such as WP'splugin_dir_url()
), those functions may sometimes composehttp://
URLs even though the user indicated thathttps://
is valid. (And ifhttps://
is valid, then it really should be used.)For
plugin_dir_url()
, the reason is that WP is inspecting the active request ($_SERVER
and its properties,HTTP_HOST
,HTTPS
,SERVER_PORT
, etc); these don't include any HTTPS flags, so we get basic HTTP.It seems that we should provide stronger direction on how these server-vars behave in CLI context.
Before
cv
commands accept input from--hostname example.com
and env-varHTTP_HOST=example.com
.$_SERVER
, but they don't indicate whether HTTPS is supported.cv core:install
, there is also an option--cms-base-url
which accepts a fully formed URL.$_SERVER
.--hostname
orHTTP_HOST
, then$_SERVER
is devoid of information about HTTP/SSL. Consequently, you are liable to emithttp://
URLs andlocalhost
URLs.After
The old options
--hostname
and--cms-base-url
are deprecated. They function as aliases for--url
.All
cv
commands accept input from--url
(-l
) and env-varsHTTP_HOST
,HTTPS
,SERVER_PORT
.This feeds into
$_SERVER
, and it also indicates HTTPS support.As before, you can give a bare hostname -- but you can also give a fully formed URL.
If the given URL is
https://
, then you can expect most URL-composition to enable HTTPS.This works for
core:install
(CMS-first boot) and all regular commands (Civi-first or CMS-first boot).The new option is shorter and easier to type. It also gives a nod to folks who use wp-cli or drush:
cv --url=XXX
wp --url=XXX
cv --uri=XXX
drush --uri=XXX
cv -l XXX
drush -l XXX
If you do not specify
--url
(or similar env-vars), then the behavior varies:$_SERVER
usingCIVICRM_UF_BASEURL
. (You will get HTTPS if the BASEURL has HTTPS.)$_SERVER
usinghttp://localhost
. (This doesn't seem ideal -- it will still tend toward HTTP. But it is the status-quo, and it's trickier to find a fix.)