summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/http.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2016-12-28 20:30:46 +0300
committerGeorge Hazan <ghazan@miranda.im>2016-12-28 20:30:46 +0300
commit3e34adae711d9ddf79b4959143a696b6a403a522 (patch)
treeaebc8cc38c164558e6da1d9c30971592045e1617 /protocols/Discord/src/http.cpp
parente7a87b3c82204e048f23750a18b456e567a6f436 (diff)
first version that logs in successfully
Diffstat (limited to 'protocols/Discord/src/http.cpp')
-rw-r--r--protocols/Discord/src/http.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/protocols/Discord/src/http.cpp b/protocols/Discord/src/http.cpp
index 5333d87a65..3e513ee8d0 100644
--- a/protocols/Discord/src/http.cpp
+++ b/protocols/Discord/src/http.cpp
@@ -35,27 +35,32 @@ static LONG g_reqNum = 0;
AsyncHttpRequest::AsyncHttpRequest()
{
cbSize = sizeof(NETLIBHTTPREQUEST);
- AddHeader("Connection", "keep-alive");
- pUserInfo = NULL;
- m_iErrorCode = 0;
- m_pCallback = NULL;
m_iReqNum = ::InterlockedIncrement(&g_reqNum);
}
-AsyncHttpRequest::AsyncHttpRequest(CDiscordProto *ppro, int iRequestType, LPCSTR _url, HttpCallback pFunc)
+AsyncHttpRequest::AsyncHttpRequest(CDiscordProto *ppro, int iRequestType, LPCSTR _url, HttpCallback pFunc, JSONNode *pRoot)
{
cbSize = sizeof(NETLIBHTTPREQUEST);
- AddHeader("Connection", "keep-alive");
-
+
if (*_url == '/') { // relative url leads to a site
- m_szUrl = "https://discardapp.com";
+ m_szUrl = "https://discordapp.com/api";
m_szUrl += _url;
}
else m_szUrl = _url;
- flags = NLHRF_DUMPASTEXT | NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_SSL;
- if (ppro->m_szAccessToken != NULL)
- this << CHAR_PARAM("access_token", ppro->m_szAccessToken);
+ flags = NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_SSL;
+ if (ppro->m_szAccessToken == NULL)
+ flags |= NLHRF_NODUMPSEND;
+ else
+ flags |= NLHRF_DUMPASTEXT;
+
+ if (pRoot != NULL) {
+ ptrW text(json_write(pRoot));
+ pData = mir_utf8encodeW(text);
+ dataLength = (int)mir_strlen(pData);
+
+ AddHeader("Content-Type", "application/json");
+ }
requestType = iRequestType;
m_pCallback = pFunc;