diff --git a/tests/services.test b/tests/services.test
index 898f008..d795766 100644
--- a/tests/services.test
+++ b/tests/services.test
@@ -2,7 +2,7 @@
 
 class ServicesWebTestCase extends DrupalWebTestCase {
 
-  protected $previousExecHadInfile = FALSE;
+  protected $resetCurl = FALSE;
 
   public function setUp() {
     $args = func_get_args();
@@ -705,6 +705,14 @@ class ServicesWebTestCase extends DrupalWebTestCase {
    *   Content returned from the exec.
    */
   protected function curlExec($curl_options, $redirect = FALSE) {
+    if ($this->resetCurl) {
+      $this->curlClose();
+    }
+    // If the request uses CURLOPT_INFILE or CURLOPT_CUSTOMREQUEST, we need to
+    // reinitialize the request before the next request, as there's no way to
+    // unset options.
+    $this->resetCurl = isset($curl_options[CURLOPT_INFILE]) || isset($curl_options[CURLOPT_CUSTOMREQUEST]);
+
     $this->curlInitialize();
 
     // cURL incorrectly handles URLs with a fragment by including the
@@ -728,15 +736,6 @@ class ServicesWebTestCase extends DrupalWebTestCase {
       $curl_options[CURLOPT_HTTPHEADER][] = 'Expect:';
     }
 
-    if ($this->previousExecHadInfile) {
-      // If the previous exec used CURLOPT_INFILE, we have to reinitialize curl
-      // to loose the option, as to not cause curl to complain that the file has
-      // disappeared.
-      curl_close($this->curlHandle);
-      unset($this->curlHandle);
-      $this->curlInitialize();
-    }
-    $this->previousExecHadInfile = isset($curl_options[CURLOPT_INFILE]);
     curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options);
 
     if (!$redirect) {
