diff options
author | George Hazan <ghazan@miranda.im> | 2016-12-28 20:30:46 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2016-12-28 20:30:46 +0300 |
commit | 3e34adae711d9ddf79b4959143a696b6a403a522 (patch) | |
tree | aebc8cc38c164558e6da1d9c30971592045e1617 /protocols/Discord/src/http.cpp | |
parent | e7a87b3c82204e048f23750a18b456e567a6f436 (diff) |
first version that logs in successfully
Diffstat (limited to 'protocols/Discord/src/http.cpp')
-rw-r--r-- | protocols/Discord/src/http.cpp | 27 |
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; |