diff --git a/src/HTTPCommands.cc b/src/HTTPCommands.cc index d43a10c..d29ce91 100644 --- a/src/HTTPCommands.cc +++ b/src/HTTPCommands.cc @@ -468,6 +468,15 @@ bool HTTPRequest::SetupHandle(CURL *curl) { } } + if (httpVerb == "MKCOL") { + rv = curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "MKCOL"); + if (rv != CURLE_OK) { + this->errorCode = "E_CURL_LIB"; + this->errorMessage = "curl_easy_setopt( CURLOPT_MKCOL ) failed."; + return false; + } + } + if (httpVerb == "POST") { rv = curl_easy_setopt(curl, CURLOPT_POST, 1); if (rv != CURLE_OK) { @@ -827,3 +836,13 @@ bool HTTPHead::SendRequest() { } // --------------------------------------------------------------------------- + +HTTPMkcol::~HTTPMkcol() {} + +bool HTTPMkcol::SendRequest() { + httpVerb = "MKCOL"; + expectedResponseCode = 201; + std::string noPayloadAllowed; + return SendHTTPRequest(noPayloadAllowed); +} + diff --git a/src/HTTPCommands.hh b/src/HTTPCommands.hh index 47a3d6a..196c4e2 100644 --- a/src/HTTPCommands.hh +++ b/src/HTTPCommands.hh @@ -336,3 +336,19 @@ class HTTPHead : public HTTPRequest { protected: std::string object; }; + +class HTTPMkcol : public HTTPRequest { + public: + HTTPMkcol(const std::string &h, const std::string &o, XrdSysError &log, + const TokenFile *token) + : HTTPRequest(h, log, token), object(o) { + hostUrl = hostUrl + "/" + object; + } + + virtual ~HTTPMkcol(); + + virtual bool SendRequest(); + + protected: + std::string object; +}; diff --git a/src/HTTPFileSystem.cc b/src/HTTPFileSystem.cc index 536cabe..aa37f1f 100644 --- a/src/HTTPFileSystem.cc +++ b/src/HTTPFileSystem.cc @@ -18,6 +18,7 @@ #include "HTTPFileSystem.hh" #include "HTTPDirectory.hh" +#include "HTTPCommands.hh" #include "HTTPFile.hh" #include "logging.hh" @@ -173,3 +174,10 @@ int HTTPFileSystem::Create(const char *tid, const char *path, mode_t mode, return 0; } + +int HTTPFileSystem::Mkdir(const char *path, mode_t mode, int mkpath, + XrdOucEnv *env) { + HTTPMkcol mkcol(m_url_base, path, m_log, getToken()); + mkcol.SendRequest(); + return 0; +} diff --git a/src/HTTPFileSystem.hh b/src/HTTPFileSystem.hh index ac21e90..5a76e87 100644 --- a/src/HTTPFileSystem.hh +++ b/src/HTTPFileSystem.hh @@ -54,9 +54,7 @@ class HTTPFileSystem : public XrdOss { int Init(XrdSysLogger *lp, const char *cfn) { return 0; } int Init(XrdSysLogger *lp, const char *cfn, XrdOucEnv *en) { return 0; } int Mkdir(const char *path, mode_t mode, int mkpath = 0, - XrdOucEnv *env = 0) { - return -ENOSYS; - } + XrdOucEnv *env = 0); int Reloc(const char *tident, const char *path, const char *cgName, const char *anchor = 0) { return -ENOSYS; diff --git a/test/http_tests.cc b/test/http_tests.cc index 4429f53..165d893 100644 --- a/test/http_tests.cc +++ b/test/http_tests.cc @@ -82,6 +82,15 @@ TEST(TestHTTPFile, TestXfer) { ASSERT_EQ(fh->Close(), 0); } +TEST(TestHTTPFile, TestMkdir) { + XrdSysLogger log; + + HTTPFileSystem fs(&log, g_config_file.c_str(), nullptr); + + const auto ret = fs.Mkdir("newdir/", 0755); + ASSERT_EQ(ret, 0); +} + class TestHTTPRequest : public HTTPRequest { public: XrdSysLogger log{}; diff --git a/test/xrdhttp-setup.sh b/test/xrdhttp-setup.sh index 0449c5e..495d8f4 100755 --- a/test/xrdhttp-setup.sh +++ b/test/xrdhttp-setup.sh @@ -161,7 +161,7 @@ EOF cat > $XROOTD_CONFIGDIR/authdb <