MXS-1220: Return 204 No Content for PUT and POST request
Returning 204 No Content removes the cost of always sending back the modified resource. If the modified resource is required, a GET request should be made to retrieve it. Updated tests to account for this change.
This commit is contained in:
@ -34,3 +34,21 @@ static inline std::string http_get_date()
|
|||||||
|
|
||||||
return std::string(buf);
|
return std::string(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert a time_t value into a HTTP-date string
|
||||||
|
*
|
||||||
|
* @param t Time to convert
|
||||||
|
*
|
||||||
|
* @return The time converted to a HTTP-date string
|
||||||
|
*/
|
||||||
|
static inline std::string http_to_date(time_t t)
|
||||||
|
{
|
||||||
|
struct tm tm;
|
||||||
|
char buf[200]; // Enough to store all dates
|
||||||
|
|
||||||
|
gmtime_r(&t, &tm);
|
||||||
|
strftime(buf, sizeof(buf), "%a, %d %b %y %T GMT", &tm);
|
||||||
|
|
||||||
|
return std::string(buf);
|
||||||
|
}
|
||||||
|
@ -153,14 +153,9 @@ HttpResponse cb_create_server(const HttpRequest& request)
|
|||||||
{
|
{
|
||||||
json_t* json = request.get_json();
|
json_t* json = request.get_json();
|
||||||
|
|
||||||
if (json)
|
if (json && runtime_create_server_from_json(json))
|
||||||
{
|
{
|
||||||
SERVER* server = runtime_create_server_from_json(json);
|
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
||||||
|
|
||||||
if (server)
|
|
||||||
{
|
|
||||||
return HttpResponse(MHD_HTTP_OK, server_to_json(server, request.host()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return HttpResponse(MHD_HTTP_FORBIDDEN);
|
return HttpResponse(MHD_HTTP_FORBIDDEN);
|
||||||
@ -176,7 +171,7 @@ HttpResponse cb_alter_server(const HttpRequest& request)
|
|||||||
|
|
||||||
if (server && runtime_alter_server_from_json(server, json))
|
if (server && runtime_alter_server_from_json(server, json))
|
||||||
{
|
{
|
||||||
return HttpResponse(MHD_HTTP_OK, server_to_json(server, request.host()));
|
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,14 +182,9 @@ HttpResponse cb_create_monitor(const HttpRequest& request)
|
|||||||
{
|
{
|
||||||
json_t* json = request.get_json();
|
json_t* json = request.get_json();
|
||||||
|
|
||||||
if (json)
|
if (json && runtime_create_monitor_from_json(json))
|
||||||
{
|
{
|
||||||
MXS_MONITOR* monitor = runtime_create_monitor_from_json(json);
|
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
||||||
|
|
||||||
if (monitor)
|
|
||||||
{
|
|
||||||
return HttpResponse(MHD_HTTP_OK, monitor_to_json(monitor, request.host()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return HttpResponse(MHD_HTTP_FORBIDDEN);
|
return HttpResponse(MHD_HTTP_FORBIDDEN);
|
||||||
@ -210,7 +200,7 @@ HttpResponse cb_alter_monitor(const HttpRequest& request)
|
|||||||
|
|
||||||
if (monitor && runtime_alter_monitor_from_json(monitor, json))
|
if (monitor && runtime_alter_monitor_from_json(monitor, json))
|
||||||
{
|
{
|
||||||
return HttpResponse(MHD_HTTP_OK, monitor_to_json(monitor, request.host()));
|
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +217,7 @@ HttpResponse cb_alter_service(const HttpRequest& request)
|
|||||||
|
|
||||||
if (service && runtime_alter_service_from_json(service, json))
|
if (service && runtime_alter_service_from_json(service, json))
|
||||||
{
|
{
|
||||||
return HttpResponse(MHD_HTTP_OK, service_to_json(service, request.host()));
|
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,10 @@ describe("Service", function() {
|
|||||||
return request.put(base_url + "/services/RW-Split-Router", {json: svc})
|
return request.put(base_url + "/services/RW-Split-Router", {json: svc})
|
||||||
})
|
})
|
||||||
.then(function(resp) {
|
.then(function(resp) {
|
||||||
var svc = resp
|
return request.get(base_url + "/services/RW-Split-Router")
|
||||||
|
})
|
||||||
|
.then(function(resp) {
|
||||||
|
var svc = JSON.parse(resp)
|
||||||
svc.data.attributes.parameters.enable_root_user.should.be.true
|
svc.data.attributes.parameters.enable_root_user.should.be.true
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -25,7 +28,10 @@ describe("Service", function() {
|
|||||||
return request.put(base_url + "/services/RW-Split-Router", {json: svc})
|
return request.put(base_url + "/services/RW-Split-Router", {json: svc})
|
||||||
})
|
})
|
||||||
.then(function(resp) {
|
.then(function(resp) {
|
||||||
var svc = resp
|
return request.get(base_url + "/services/RW-Split-Router")
|
||||||
|
})
|
||||||
|
.then(function(resp) {
|
||||||
|
var svc = JSON.parse(resp)
|
||||||
svc.data.relationships.should.be.empty
|
svc.data.relationships.should.be.empty
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -48,7 +54,10 @@ describe("Service", function() {
|
|||||||
return request.put(base_url + "/services/RW-Split-Router", {json: svc})
|
return request.put(base_url + "/services/RW-Split-Router", {json: svc})
|
||||||
})
|
})
|
||||||
.then(function(resp) {
|
.then(function(resp) {
|
||||||
var svc = resp
|
return request.get(base_url + "/services/RW-Split-Router")
|
||||||
|
})
|
||||||
|
.then(function(resp) {
|
||||||
|
var svc = JSON.parse(resp)
|
||||||
svc.data.relationships.servers.data[0].id.should.be.equal("server1")
|
svc.data.relationships.servers.data[0].id.should.be.equal("server1")
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user