Skip to content
This repository

add custom request header #19

Closed
BluesyLong opened this Issue · 1 comment

2 participants

BluesyLong Johnny Broadway
BluesyLong

I made a little patch to add some headers to the request.
I use it to authenticate with an api key in the header (redmine).

--- ActiveResource.php.orig 2012-10-11 09:40:33.000000000 +0200
+++ ActiveResource.php  2012-10-11 09:40:12.000000000 +0200
@@ -96,6 +96,11 @@
    var $request_body = '';

    /**
+    * The request headers that was sent to the server.
+    */
+   var $request_headers = array();
+
+   /**
     * The complete URL that the request was sent to.
         */
            var $request_uri = '';
@@ -615,7 +620,7 @@
        }

        if ($this->request_format == 'xml') {
-           curl_setopt ($ch, CURLOPT_HTTPHEADER, array ("Expect:", "Content-Type: text/xml", "Length: " .          strlen  $params)));
+           $this->request_headers = array_merge($this->request_headers, array ("Expect:", "Content-Type: text/xml",    Length: " . strlen ($params)));
        }
        switch ($method) {
            case 'POST':
@@ -635,6 +640,10 @@
            default:
                break;
        }
+       if (count($this->request_headers)) {
+           curl_setopt ($ch, CURLOPT_HTTPHEADER, $this->request_headers);
+       }
+
        $res = curl_exec ($ch);

        // Check HTTP status code for denied access
Johnny Broadway
Owner

Awesome, thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.