Page MenuHomePhabricator

WebRequest should allow overriding headers
Closed, DeclinedPublic


This is needed for use cases like T183722, when a WebRequest instance is being created programmatically, and we would like to assign an arbitrary IP and UA to it. Currently, IP can be set using setIP(). User-agent strings are stored in a header called User-Agent and CheckUser retrieves this using $wgRequest->getHeader( 'User-Agent' ); such as in CheckUserhooks.php but it is not possible to override the value of a request header. Therefore, this task will add a setHeader() function to override a header whenever applicable.

Event Timeline

Huji triaged this task as High priority.Feb 2 2018, 1:09 AM
Huji created this task.

Change 407576 had a related patch set uploaded (by Huji; owner: Huji):
[mediawiki/core@master] WebRequest should allow setting the user-agent string of an instance

@Huji: What do we actually need the UA for? LoginNotify doesn't use it.

@kaldari LoginNotify doesn't use it *now* but will be using it once we connect it to CheckUser, which is the plan.

To be able to test the code that we/I will be writing for the integration of LN and CU, we need a way to generate WebRequests with arbitrarily assigned UAs and IPs. Hence the current task and associated patch.

@Huji: Feels like putting the cart before the horse. If nothing's actually using WebRequest::useragent yet, it'll just get removed. Why not add it once it's actually needed? If you really want to keep it, I think you'll need to add some kind of explanation in the code comments.

@Huji I think the point is that nothing can use that User-Agent. You are setting a variable that cannot be read…

@Platonides thanks for the clarification. I will be working on it in the coming days, and will amend the patch accordingly. I marked my patch as -1 for now.

Huji renamed this task from WebRequest should allow setting the user-agent string of an instance to WebRequest should allow overriding headers.Feb 3 2018, 2:39 AM
Huji updated the task description. (Show Details)

@kaldari I completely changed my strategy. The task description is updated to reflect why.

Change 407576 abandoned by Huji:
Introduce setHeader()

Never mind, overriding $wgRequest solves the problem.

Never mind, I realized I could simply override $wgRequest by setting it to an instance of FauxRequest and then using its existing setHeader() function. Thanks @kaldari for pointing me in the right direction.