Talk about installation and --dry-run
[shpub.git] / src / shpub / Request.php
index 3614d5d69100ff4b1d5a92e25a6da58233068c44..e7c3b775a51c26d76320bd400b671059d31c1c97 100644 (file)
@@ -93,6 +93,17 @@ class Request
             $cp = new CurlPrinter();
             $cp->show($this->req, $this->uploadsInfo, $this->dedicatedBody);
         }
+
+        if ($this->cfg->dryRun && $this->req->getMethod() != 'GET') {
+            //do not run any modifying queries
+            //fake a successful response
+            $res = new \HTTP_Request2_Response('HTTP/1.1 200 OK', false);
+            $res->parseHeaderLine('Content-type: text/plain');
+            $res->parseHeaderLine('Location: http://example.org/fake-response');
+            $res->appendBody('Fake --dry-run response');
+            return $res;
+        }
+
         $res = $this->req->send();
 
         if (intval($res->getStatus() / 100) != 2) {
@@ -108,7 +119,7 @@ class Request
         );
 
         $shown = false;
-        if ($res->getHeader('content-type') == 'application/json') {
+        if (Util::getMimeType($res) == 'application/json') {
             $errData = json_decode($res->getBody());
             if (!isset($errData->error)) {
                 Log::err('Error response does not contain "error" property');
@@ -225,7 +236,7 @@ class Request
     {
         if ($isHtml) {
             $this->addProperty(
-                'content', ['html' => $text]
+                'content', [['html' => $text]]
             );
         } else {
             $this->addProperty('content', $text);