commit 28df097fcc95e457a9586ea5e60e51652cea1a19
Author: Jim Meyering <meyering(a)redhat.com>
Date: Wed Apr 27 13:47:27 2011 +0200
upon successful bucket or object creation, issue HTTP code 201, not 200
200 is a mere "OK", while 201 is the slightly more descriptive CREATED.
However, note that the 201 response does not guarantee that there
was no prior object by the same name. I.e., if you create an object
and that happens to replace one that already existed, you'll get 201
just as when you create an object in an empty bucket.
This makes the code more consistent: even before this change,
attribute-creation would elicit a 201 response.
* rest.c (proxy_put_data): Use MHD_HTTP_CREATED, not MHD_HTTP_OK.
(create_bucket): Likewise.
* t/creation-code (iwhd_pid): New file. Test for the above.
* t/Makefile.am (TESTS): Add it.
Reported by Dave Johnson. See
http://bugzilla.redhat.com/699417
rest.c | 5 +++-
t/Makefile.am | 1 +
t/creation-code | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 64 insertions(+), 1 deletions(-)
---
diff --git a/rest.c b/rest.c
index aa9be64..f1055ad 100644
--- a/rest.c
+++ b/rest.c
@@ -509,7 +509,7 @@ proxy_put_data (void *cctx, struct MHD_Connection *conn, const char
*url,
}
DPRINTF("rereplicate (obj PUT)\n");
recheck_replication(ms,NULL);
- rc = MHD_HTTP_OK;
+ rc = MHD_HTTP_CREATED;
}
resp = MHD_create_response_from_data(0,NULL,MHD_NO,MHD_NO);
if (!resp) {
@@ -1227,6 +1227,9 @@ create_bucket (char *name, my_state *ms)
* general replica-repair policy/system in place.
*/
replicate_bcreate(name,ms);
+
+ /* Use this (201): slightly more descriptive than 200. */
+ rc = MHD_HTTP_CREATED;
}
return rc;
diff --git a/t/Makefile.am b/t/Makefile.am
index d7e3fbf..5bd4d69 100644
--- a/t/Makefile.am
+++ b/t/Makefile.am
@@ -17,6 +17,7 @@
TESTS = \
parse-test \
basic \
+ creation-code \
provider \
replication \
auto \
diff --git a/t/creation-code b/t/creation-code
new file mode 100755
index 0000000..e71f283
--- /dev/null
+++ b/t/creation-code
@@ -0,0 +1,59 @@
+#!/bin/sh
+# Ensure that bucket,object,attribute-creation all succeed with code 201.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ..
+
+mkdir FS mongod iwhd || framework_failure_ mkdir failed
+
+m_port=$(get_port $mongo_base_port $lock_dir/m-) \
+ || fail_ "failed to get mongodb port"
+
+mongod --help > /dev/null || fail_ "the mongod program is not installed"
+
+mongod --port $m_port --pidfilepath mongod/pid --dbpath mongod > mongod.log
2>&1 &
+mongo_pid=$!
+cleanup_() { kill -9 $mongo_pid; }
+
+# Wait for up to 5 seconds for mongod to begin listening.
+wait_for .1 50 'mongo localhost:$m_port < /dev/null' \
+ || framework_failure_ mongod failed to start
+
+port=$(get_port 9095 $lock_dir/i-) || fail_ "failed to get iwhd port"
+
+printf '[{"path": "FS", "type": "fs",
"name": "primary"}]\n' \
+ > iwhd.cfg || fail=1
+
+iwhd -v -p $port -c iwhd.cfg -d localhost:$m_port &
+iwhd_pid=$!
+cleanup_() { kill -9 $mongo_pid; kill $iwhd_pid; }
+
+# Wait for up to 5 seconds for iwhd to begin listening on $port.
+wait_for .1 50 "curl -s
http://localhost:$port" \
+ || { echo iwhd failed to listen; Exit 1; }
+
+
+curl_w() { curl --write-out '%{http_code}' "$@"; }
+
+# Show that bucket,object,attribute-creation all evoke 201.
+creation_evokes_201()
+{
+
+ # Create a bucket.
+ local b=http://localhost:$port/b9
+ curl_w -XPUT $b > http-code || fail=1
+ test "$(cat http-code)" = 201 || fail=1
+
+ # Create an object in that bucket.
+ local obj=$b/obj
+ curl_w -XPUT $obj > http-code || fail=1
+ test "$(cat http-code)" = 201 || fail=1
+
+ # Create an attribute.
+ local attr=$obj/color
+ printf blue | curl_w -T - $attr > http-code || fail=1
+ test "$(cat http-code)" = 201 || fail=1
+}
+
+creation_evokes_201
+
+Exit $fail