]> granicus.if.org Git - pdns/commitdiff
API: return status 204 on successful delete
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 20 May 2014 13:52:37 +0000 (15:52 +0200)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 20 May 2014 15:14:17 +0000 (17:14 +0200)
204 No Content is meant to indicate that the data (zone) is now gone.

Also add tests to make sure DELETE works.

Fixes #1422.

pdns/webserver.cc
pdns/ws-auth.cc
pdns/ws-recursor.cc
regression-tests.api/test_Zones.py

index e4e30a0f883a63023f35a4ef547c4619aef50a3e..579b3f8bf670014f7eadfbfd2d508e9798a6ea0e 100644 (file)
@@ -119,6 +119,11 @@ static void apiWrapper(boost::function<void(HttpRequest*,HttpResponse*)> handler
     return;
   }
 
+  if (resp->status == 204) {
+    // No Content -> no Content-Type.
+    resp->headers.erase("Content-Type");
+  }
+
   if(!callback.empty()) {
     resp->body = callback + "(" + resp->body + ");";
   }
index c1e05f95a509224e9e9c72583a2a42cc34c2abcd..da87cf000392c06856f507f31676fff3bc11efdd 100644 (file)
@@ -649,6 +649,7 @@ static void apiServerZoneDetail(HttpRequest* req, HttpResponse* resp) {
 
     // empty body on success
     resp->body = "";
+    resp->status = 204; // No Content: declare that the zone is gone now
     return;
   } else if (req->method == "PATCH" && !::arg().mustDo("experimental-api-readonly")) {
     patchZone(req, resp);
index a437ed687ff97100c5bf44e4d84751378f26f730..089c464cb477f3cb27ce275b146858c23bc2f6f6 100644 (file)
@@ -355,6 +355,7 @@ static void apiServerZoneDetail(HttpRequest* req, HttpResponse* resp)
     reloadAuthAndForwards();
     // empty body on success
     resp->body = "";
+    resp->status = 204; // No Content: declare that the zone is gone now
   } else if(req->method == "GET") {
     fillZone(zonename, resp);
   } else {
index ed643759b9e94bc5f442f0c823fa5ad518cf4f5e..eb4f7b94c376fdc7241f40c1eeaeac53d2cd0060 100644 (file)
@@ -520,6 +520,13 @@ class AuthZones(ApiTestCase):
         self.assertEquals(r.status_code, 422)
         self.assertIn('out of zone', r.json()['error'])
 
+    def test_zone_delete(self):
+        payload, zone = self.create_zone()
+        name = payload['name']
+        r = self.session.delete(self.url("/servers/localhost/zones/" + name))
+        self.assertEquals(r.status_code, 204)
+        self.assertNotIn('Content-Type', r.headers)
+
     def test_zone_comment_create(self):
         payload, zone = self.create_zone()
         name = payload['name']
@@ -816,6 +823,13 @@ class RecursorZones(ApiTestCase):
         for k in payload.keys():
             self.assertEquals(data[k], payload[k])
 
+    def test_zone_delete(self):
+        payload, zone = self.create_zone(kind='Native')
+        name = payload['name']
+        r = self.session.delete(self.url("/servers/localhost/zones/" + name))
+        self.assertEquals(r.status_code, 204)
+        self.assertNotIn('Content-Type', r.headers)
+
     def test_search_rr_exact_zone(self):
         name = unique_zone_name() + '.'
         self.create_zone(name=name, kind='Native')