Page MenuHomePhabricator

Refactor the Http class to not use global state
Closed, ResolvedPublic1 Estimated Story Points

Description

The Http class is currently a collection of static methods accessing global variables for configuration. It should be refactored into a stateless service class (perhaps called HttpClient) that knows a HttpRequestFactory instance. The old class and methods should be deprecated but remain in place for now, delegating to the new service via the global service locator instance, MediaWikiServices::getInstance().

Event Timeline

daniel updated the task description. (Show Details)

What exactly should this new service contain?

$httpEngine is only used by HttpRequestFactory and seems like it should just be a parameter to HttpRequestFactory::create().

get() and post() are shorthands for request().

userAgent() should exist, but it's a one-line wrapper around a config option, so it doesn't count for much.

getProxy() seems to behave equivalently to casting the config variable to a string. Making $wgHTTPProxy default to the empty string instead of false seems like a better solution.

createMultiClient() is unused.

That leaves request(). Do we actually want a whole service class that basically consists of a single method with 16 lines of code? It has no dependencies other than HttpRequestFactory, so why don't we just put the method on HttpRequestFactory? That's a tiny class also as it stands.

Everything you say makes sense. As long as we can deprecate the static methods in Http, I'm happy. If you make a patch that follows your suggestions, we can discuss the details there.

Change 504012 had a related patch set uploaded (by simetrical; owner: simetrical):
[mediawiki/core@master] Deprecate most of the Http class

https://gerrit.wikimedia.org/r/504012

CCicalese_WMF set the point value for this task to 1.Apr 15 2019, 3:06 PM

Change 504012 merged by jenkins-bot:
[mediawiki/core@master] Deprecate the Http class

https://gerrit.wikimedia.org/r/504012