Avoid setting multiple Content-Type headers.
[lhc/web/wiklou.git] / includes / HttpFunctions.php
index 1018658..a1d2e59 100644 (file)
@@ -43,9 +43,6 @@ class Http {
                }
 
                $req = MWHttpRequest::factory( $url, $options );
-               if( isset( $options['userAgent'] ) ) {
-                       $req->setUserAgent( $options['userAgent'] );
-               }
                $status = $req->execute();
 
                if ( $status->isOK() ) {
@@ -210,6 +207,9 @@ class MWHttpRequest {
                } else {
                        $this->timeout = $wgHTTPTimeout;
                }
+               if( isset( $options['userAgent'] ) ) {
+                       $this->setUserAgent( $options['userAgent'] );
+               }
 
                $members = array( "postData", "proxy", "noProxy", "sslVerifyHost", "caInfo",
                                  "method", "followRedirects", "maxRedirects", "sslVerifyCert", "callback" );
@@ -219,6 +219,10 @@ class MWHttpRequest {
                                $this->$o = $options[$o];
                        }
                }
+
+               if ( $this->noProxy ) {
+                       $this->proxy = ''; // noProxy takes precedence
+               }
        }
 
        /**
@@ -279,15 +283,14 @@ class MWHttpRequest {
        }
 
        /**
-        * Take care of setting up the proxy
-        * (override in subclass)
+        * Take care of setting up the proxy (do nothing if "noProxy" is set)
         *
-        * @return String
+        * @return void
         */
        public function proxySetup() {
                global $wgHTTPProxy;
 
-               if ( $this->proxy && !$this->noProxy ) {
+               if ( $this->proxy || !$this->noProxy ) {
                        return;
                }
 
@@ -402,11 +405,7 @@ class MWHttpRequest {
                        $this->setReferer( wfExpandUrl( $wgTitle->getFullURL(), PROTO_CURRENT ) );
                }
 
-               /**
-                * Set up the proxy, but
-                * clear the proxy when $noProxy is set (takes precedence)
-                */
-               $this->proxySetup();
+               $this->proxySetup(); // set up any proxy as needed
 
                if ( !$this->callback ) {
                        $this->setCallback( array( $this, 'read' ) );
@@ -801,11 +800,13 @@ class PhpHttpRequest extends MWHttpRequest {
                if ( $this->method == 'POST' ) {
                        // Required for HTTP 1.0 POSTs
                        $this->reqHeaders['Content-Length'] = strlen( $this->postData );
-                       $this->reqHeaders['Content-type'] = "application/x-www-form-urlencoded";
+                       if( !isset( $this->reqHeaders['Content-Type'] ) ) {
+                               $this->reqHeaders['Content-Type'] = "application/x-www-form-urlencoded";
+                       }
                }
 
                $options = array();
-               if ( $this->proxy && !$this->noProxy ) {
+               if ( $this->proxy ) {
                        $options['proxy'] = $this->urlToTCP( $this->proxy );
                        $options['request_fulluri'] = true;
                }