RakString RakString::FormatForDELETE(const char* uri, const char* extraHeaders) { RakString out; RakString host; RakString remotePath; RakNet::RakString header; RakNet::RakString uriRs; uriRs = uri; uriRs.SplitURI(header, host, remotePath); if (host.IsEmpty() || remotePath.IsEmpty()) return out; if (extraHeaders && extraHeaders[0]) { out.Set("DELETE %s HTTP/1.1\r\n" "%s\r\n" "Content-Length: 0\r\n" "Host: %s\r\n" "Connection: close\r\n" "\r\n", remotePath.C_String(), extraHeaders, host.C_String()); } else { out.Set("DELETE %s HTTP/1.1\r\n" "Content-Length: 0\r\n" "Host: %s\r\n" "Connection: close\r\n" "\r\n", remotePath.C_String(), host.C_String()); } return out; }
void Rackspace2::AddOperation(RakNet::RakString URL, OpType opType, json_t *data, bool setAuthToken) { if (tcp==0) { tcp = RakNet::OP_NEW<TCPInterface>(); if (tcp->Start(0, 0, 8)==false) { if (eventCallback) eventCallback->OnTCPFailure(); } httpConnection2 = RakNet::OP_NEW<HTTPConnection2>(); tcp->AttachPlugin(httpConnection2); } RakString authURLHeader, authURLDomain, authURLPath; URL.SplitURI(authURLHeader,authURLDomain,authURLPath); char *jsonStr = ""; if (data) jsonStr = json_dumps(data, 0); RakString requestStr; RakString extraBody; if (setAuthToken) { RakAssert(X_Auth_Token[0]); // Test expired token //strcpy(X_Auth_Token, "fd6ad67c-fbd3-4b35-94e2-059b6090998e"); extraBody.Set("Accept: application/json\r\nX-Auth-Token: %s", X_Auth_Token); __addOpLast_URL = URL; __addOpLast_isPost = opType; __addOpLast_dataAsStr = jsonStr; } else { extraBody = "Accept: application/json"; } if (opType==OT_POST) requestStr = RakString::FormatForPOST(URL, "application/json", jsonStr, extraBody); else if (opType==OT_GET) requestStr = RakString::FormatForGET(URL, extraBody); else if (opType==OT_DELETE) requestStr = RakString::FormatForDELETE(URL, extraBody); else requestStr = RakString::FormatForPUT(URL, "application/json", jsonStr, extraBody); bool b = httpConnection2->TransmitRequest(requestStr,authURLDomain, 443, true); if (!b) { if (eventCallback) eventCallback->OnTransmissionFailed(httpConnection2, requestStr, authURLDomain); } if (data) { free(jsonStr); json_decref(data); } }