Page MenuHomePhabricator

D11493.id27741.diff
No OneTemporary

D11493.id27741.diff

diff --git a/src/future/http/HTTPSFuture.php b/src/future/http/HTTPSFuture.php
--- a/src/future/http/HTTPSFuture.php
+++ b/src/future/http/HTTPSFuture.php
@@ -19,6 +19,9 @@
private $responseBufferPos;
private $files = array();
private $temporaryFiles = array();
+ private $rawBody;
+ private $rawBodyPos = 0;
+ private $fileHandle;
/**
* Create a temp file containing an SSL cert, and use it for this session.
@@ -225,8 +228,32 @@
curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, $allowed_protocols);
}
- $data = $this->formatRequestDataForCURL();
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+ if (strlen($this->rawBody)) {
+ if ($this->getData()) {
+ throw new Exception(
+ pht(
+ 'You can not execute an HTTP future with both a raw request '.
+ 'body and structured request data.'));
+ }
+
+ // We aren't actually going to use this file handle, since we are
+ // just pushing data through the callback, but cURL gets upset if
+ // we don't hand it a real file handle.
+ $tmp = new TempFile();
+ $this->fileHandle = fopen($tmp, 'r');
+
+ // NOTE: We must set CURLOPT_PUT here to make cURL use CURLOPT_INFILE.
+ // We'll possibly overwrite the method later on, unless this is really
+ // a PUT request.
+ curl_setopt($curl, CURLOPT_PUT, true);
+ curl_setopt($curl, CURLOPT_INFILE, $this->fileHandle);
+ curl_setopt($curl, CURLOPT_INFILESIZE, strlen($this->rawBody));
+ curl_setopt($curl, CURLOPT_READFUNCTION,
+ array($this, 'willWriteBody'));
+ } else {
+ $data = $this->formatRequestDataForCURL();
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+ }
$headers = $this->getHeaders();
@@ -611,4 +638,29 @@
return true;
}
+
+ /**
+ * Write a raw HTTP body into the request.
+ *
+ * You must write the entire body before starting the request.
+ *
+ * @param string Raw body.
+ * @return this
+ */
+ public function write($raw_body) {
+ $this->rawBody = $raw_body;
+ return $this;
+ }
+
+
+ /**
+ * Callback to pass data to cURL.
+ */
+ public function willWriteBody($handle, $infile, $len) {
+ $bytes = substr($this->rawBody, $this->rawBodyPos, $len);
+ $this->rawBodyPos += $len;
+ return $bytes;
+ }
+
+
}

File Metadata

Mime Type
text/plain
Expires
Wed, May 22, 11:34 AM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6305827
Default Alt Text
D11493.id27741.diff (2 KB)

Event Timeline