Hi everyone,
I need to use HTTP Basic Auth for outgoing HTTP connections. I could use MWHttpRequest
directly to achieve this but wondered if this functionality could also be provided through
the Http helper class.
The Http class provides get, post and request functions that do not allow to set HTTP
headers other than the User Agent. But as this helper class is used by code I need to use,
I would like to discuss two options (did not test the code), and open the discussion for
other options.
Option 1: Pure HTTP Basic Auth support
Add two new well-defined options to the options parameter
- username
- password
In MWHttpRequest's constructor add the HTTP Authentication header:
if ( isset( $options['username'] ) && isset( $options['password']
) )
$this->setHeader( 'Authorization', base64_encode(
$options['username'] . ':' . $options['password'] ) );
Option 2: Support for any HTTP header
Add a single new option to the options parameter
- httpHeaders
In MWHttpRequest's constructor add the HTTP headers:
foreach ( $options['httpHeaders'] as $fieldName => $fieldValue )
$this->setHeader( $fieldName, $fieldValue )
Both solutions would work smoothly with Http.get, Http.post or Http.request.
I have no preference over one solution or the other. There might also be a third or a
forth one that is much smarter...
Best regards
Christian