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

Reusable server url #14

Merged
merged 10 commits into from
Sep 13, 2014
Merged

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Sep 2, 2014

Improve the re-usability of the addQueryArg() method

  • Support SSL protocol
  • Make the serverUrl code re-usable

@@ -215,7 +262,7 @@ protected function logRequest($query) {
$columns = array(
isset($_SERVER['REMOTE_ADDR']) ? str_pad($_SERVER['REMOTE_ADDR'], 15, ' ') : '-',
isset($query['action']) ? $query['action'] : '-',
isset($query['slug']) ? $query['slug'] : '-',
Copy link
Owner

Choose a reason for hiding this comment

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

The extra space is intentional: it's used to align similar statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I sort of figured that, but then looked at the other five lines and saw you didn't space those out...

Copy link
Owner

Choose a reason for hiding this comment

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

Fair enough. Lets take out the space.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, already put it back in ;-)

@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 3, 2014

Updated the PR

$path = str_replace('\\', '/', dirname($path)) . '/';
}
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

Looking at this bit again, it seems lines 38 to 47 could be simplified (untested code):

$path = str_replace('\\', '/', dirname($path));
//Make sure there's a trailing slash.
if ( substr($path, -1) !== '/' ) {
    $path .= '/';
}

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could do. Still would keep the Unix/Windows if/else to avoid accidentally changing a Unix path. Would put the dirname() in a variable though, to avoid doing that three times. Can you live with that ? I'll update the PR.

@YahnisElsts
Copy link
Owner

Still would keep the Unix/Windows if/else to avoid accidentally changing a Unix path.

Can you think of an example path where that would actually happen? On Unix-like systems the directory separator would already be a forward slash, so the str_replace() would just be a no-op. And the current version appends a trailing slash regardless of the what the directory separator is, so we might as well do it in one place instead of two.

@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 3, 2014

I was just thinking - and forgive me if this sounds ignorant -, but can unix paths contain the '' character as part of the path ? If it could, keeping the switch is best.

Think a Unix path like myserver.com/my\weird\\path/

@YahnisElsts
Copy link
Owner

I was just thinking - and forgive me if this sounds ignorant -, but can unix paths contain the '' character as part of the path?

Apparently, the answer is yes. I looked around and found a number of pages discussing ways to delete files with a backslash in the name. So it must be possible to create a file like that (why anyone would actually do that is beyond me, but there you go).

@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 3, 2014

Ok, then we should keep the if/else like it is. I'll update the PR with the current master and then it should be fine to merge.

… Reusable-server-url

Conflicts:
	includes/Wpup/UpdateServer.php
@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 10, 2014

@YahnisElsts Anything I still need to do about this one before you can merge ?

return true;
}
}
elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
Copy link
Owner

Choose a reason for hiding this comment

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

} elseif {, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, done.

@YahnisElsts
Copy link
Owner

Anything I still need to do about this one before you can merge?

Just some minor things. See my comments above.

*
* @return string Url
*/
public static function determineServerUrl() {
Copy link
Owner

Choose a reason for hiding this comment

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

Personally, I'd call this guessServerUrl. The update server can make a good guess, but it can't be 100% sure it has correctly determined the URL. Stuff like rewrite rules could still mess it up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, adjusted.

@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 11, 2014

Just some minor things. See my comments above.

All done & PR updated.

YahnisElsts added a commit that referenced this pull request Sep 13, 2014
Refactor server URL detection as a separate static method
@YahnisElsts YahnisElsts merged commit c896259 into YahnisElsts:master Sep 13, 2014
@jrfnl jrfnl deleted the Reusable-server-url branch September 14, 2014 19:19
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.

2 participants