void HttpConnection::readResponseHeaders() { WCHAR *wbuffer = new WCHAR[1024]; DWORD ddsize = 1024; StringBuffer headerString; responseHeaders.clear(); BOOL reqDone = HttpQueryInfo(req, HTTP_QUERY_RAW_HEADERS_CRLF ,(LPVOID)wbuffer, &ddsize, NULL); if (reqDone == false) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { // Allocate the necessary buffer. delete [] wbuffer; wbuffer = new WCHAR[ddsize]; reqDone = HttpQueryInfo(req, HTTP_QUERY_RAW_HEADERS_CRLF ,(LPVOID)wbuffer, &ddsize, NULL); } } if (reqDone) { headerString.convert(wbuffer); LOG.debug("Response Headers:", headerString.c_str()); ArrayList headers; headerString.split(headers, "\r\n"); StringBuffer *prop; for(ArrayElement* e=headers.front(); e; e=headers.next()) { prop = dynamic_cast<StringBuffer *>(e); if(prop->empty()) continue; size_t colon = prop->find(":"); if (colon != StringBuffer::npos) { StringBuffer key = prop->substr(0, colon); StringBuffer value = prop->substr(colon+1); responseHeaders.put(key.trim(),value.trim()); if (canBeLogged(key)) { LOG.debug("\t%s : %s", key.c_str(), value.c_str()); } else { LOG.debug("\t%s : *****", key.c_str()); } } else { LOG.debug("\t%s", prop->c_str()); } } } else { DWORD err = GetLastError(); const char* msg = createHttpErrorMessage(err); LOG.error("[HttpConnection] Error reading response headers - code %d: %s", err, msg); delete [] msg; } }
void FHttpResponseWinInet::ProcessResponseHeaders() { ::DWORD HeaderSize = 0; TArray<FString> Result; if (!HttpQueryInfo(Request.RequestHandle, HTTP_QUERY_RAW_HEADERS_CRLF, NULL, &HeaderSize, NULL)) { uint32 ErrorCode = GetLastError(); if (ErrorCode != ERROR_INSUFFICIENT_BUFFER) { UE_LOG(LogHttp, Warning, TEXT("HttpQueryInfo to get header length for all headers failed: %s. %p"), *InternetTranslateError(GetLastError()), &Request); } if (HeaderSize == 0) { UE_LOG(LogHttp, Warning, TEXT("HttpQueryInfo for all headers returned zero header size. %p"), this); } TArray<TCHAR> HeaderBuffer; HeaderBuffer.AddUninitialized(HeaderSize/sizeof(TCHAR)); if (!HttpQueryInfo(Request.RequestHandle, HTTP_QUERY_RAW_HEADERS_CRLF, HeaderBuffer.GetTypedData(), &HeaderSize, NULL)) { UE_LOG(LogHttp, Warning, TEXT("HttpQueryInfo for all headers failed: %s. %p"), *InternetTranslateError(GetLastError()), &Request); } // parse all the key/value pairs const TCHAR* HeaderPtr = HeaderBuffer.GetTypedData(); // don't count the terminating NULL character as one to search. const TCHAR* EndPtr = HeaderPtr + HeaderBuffer.Num()-1; while (HeaderPtr < EndPtr) { const TCHAR* DelimiterPtr = FCString::Strstr(HeaderPtr, TEXT("\r\n")); if (DelimiterPtr == NULL) { DelimiterPtr = EndPtr; } FString HeaderLine(DelimiterPtr-HeaderPtr, HeaderPtr); FString HeaderKey,HeaderValue; if (HeaderLine.Split(TEXT(":"), &HeaderKey, &HeaderValue)) { if (!HeaderKey.IsEmpty()) { ResponseHeaders.Add(HeaderKey, HeaderValue.Trim()); } } HeaderPtr = DelimiterPtr + 2; } } else { UE_LOG(LogHttp, Warning, TEXT("HttpQueryInfo for all headers failed when trying to determine the size for the header buffer. %p"), &Request); } }
FString FHttpResponseWinInet::QueryHeaderString(uint32 HttpQueryInfoLevel, const FString& HeaderName) const { // try to use stack allocation where possible. ::DWORD HeaderSize = 0; TCHAR HeaderValue[128]; TArray<TCHAR> HeaderValueLong; TCHAR* HeaderValueReal = HeaderValue; if (!HttpQueryInfo(Request.RequestHandle, HttpQueryInfoLevel, const_cast<TCHAR*>(*HeaderName), &HeaderSize, NULL)) { uint32 ErrorCode = GetLastError(); if (ErrorCode == ERROR_HTTP_HEADER_NOT_FOUND) { return FString(); } else if (ErrorCode == ERROR_INSUFFICIENT_BUFFER) { // make sure we have enough room to supply the HeaderName and Value. If not, dynamically allocate. uint32 HeaderSizeChars = HeaderSize / sizeof(TCHAR) + 1; uint32 HeaderNameChars = HeaderName.Len() == 0 ? 0 : HeaderName.Len() + 1; if (HeaderSizeChars > ARRAYSIZE(HeaderValue) || HeaderNameChars > ARRAYSIZE(HeaderValue)) { // we have to create a dynamic allocation to hold the result. UE_LOG(LogHttp, Verbose, TEXT("Having to resize default buffer for retrieving header %s. Name length: %u. Value length: %u. %p"), *HeaderName, HeaderNameChars, HeaderSizeChars, &Request); uint32 NewBufferSizeChars = FMath::Max(HeaderSizeChars, HeaderNameChars); // Have to copy the HeaderName into the buffer as well for the API to work. if (HeaderName.Len() > 0) { HeaderValueLong = HeaderName.GetCharArray(); } // Set the size of the array to hold the entire value. HeaderValueLong.SetNum(NewBufferSizeChars); HeaderSize = NewBufferSizeChars * sizeof(TCHAR); HeaderValueReal = HeaderValueLong.GetData(); } else { // Use the stack allocated space if we have the room. FMemory::Memcpy(HeaderValue, *HeaderName, HeaderName.Len()*sizeof(TCHAR)); HeaderValue[HeaderName.Len()] = 0; } if (!HttpQueryInfo(Request.RequestHandle, HttpQueryInfoLevel, HeaderValueReal, &HeaderSize, NULL)) { UE_LOG(LogHttp, Warning, TEXT("HttpQueryInfo failed trying to get Header Value for Name %s: %s. %p"), *HeaderName, *InternetTranslateError(GetLastError()), &Request); return FString(); } } } return FString(HeaderValueReal); }
WebInputStream (const String& address_, bool isPost_, const MemoryBlock& postData_, URL::OpenStreamProgressCallback* progressCallback, void* progressCallbackContext, const String& headers_, int timeOutMs_, StringPairArray* responseHeaders) : statusCode (0), connection (0), request (0), address (address_), headers (headers_), postData (postData_), position (0), finished (false), isPost (isPost_), timeOutMs (timeOutMs_) { createConnection (progressCallback, progressCallbackContext); if (! isError()) { if (responseHeaders != nullptr) { DWORD bufferSizeBytes = 4096; for (;;) { HeapBlock<char> buffer ((size_t) bufferSizeBytes); if (HttpQueryInfo (request, HTTP_QUERY_RAW_HEADERS_CRLF, buffer.getData(), &bufferSizeBytes, 0)) { StringArray headersArray; headersArray.addLines (String (reinterpret_cast<const WCHAR*> (buffer.getData()))); for (int i = 0; i < headersArray.size(); ++i) { const String& header = headersArray[i]; const String key (header.upToFirstOccurrenceOf (": ", false, false)); const String value (header.fromFirstOccurrenceOf (": ", false, false)); const String previousValue ((*responseHeaders) [key]); responseHeaders->set (key, previousValue.isEmpty() ? value : (previousValue + "," + value)); } break; } if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) break; } } DWORD status = 0; DWORD statusSize = sizeof (status); if (HttpQueryInfo (request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &statusSize, 0)) statusCode = (int) status; } }
//download file from WWW in a buffer bool WWWFileBuffer(char *host, char *path, char *outBuffer, int outBufferSize) { bool retval = false; LPTSTR AcceptTypes[2] = { TEXT("*/*"), NULL }; DWORD dwSize = outBufferSize - 1, dwFlags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE; HINTERNET opn = NULL, con = NULL, req = NULL; opn = InternetOpen(TEXT("Evilzone.org"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); if (!opn) return retval; con = InternetConnect(opn, host, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); if (!con) return retval; req = HttpOpenRequest(con, TEXT("GET"), path, HTTP_VERSION, NULL, (LPCTSTR*)AcceptTypes, dwFlags, 0); if (!req) return retval; if (HttpSendRequest(req, NULL, 0, NULL, 0)) { DWORD statCodeLen = sizeof(DWORD); DWORD statCode; if (HttpQueryInfo(req, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &statCode, &statCodeLen, NULL)) { if (statCode == 200 && InternetReadFile(req, (LPVOID)outBuffer, outBufferSize - 1, &dwSize)) { retval = TRUE; } } } InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(opn); return retval; }
// Return true if HTTP version of 1.1 or greater bool Download::httpverOK(HINTERNET hIurl) { char str[180]; unsigned long len = 179; if(!HttpQueryInfo(hIurl, HTTP_QUERY_VERSION, &str, &len, NULL)) return false; // First, check major version number char *p = strchr(str, '/'); if(!p) return true; p++; if(*p == '0') return false; // can't use HTTP 0.x // Now, find start of minor HTTP version number p = strchr(str, '.'); p++; // convert to int int minorVerNum = atoi(p); if(minorVerNum > 0) return true; return false; }
void CNetRequestImpl::readResponse(CNetResponseImpl* pNetResp) { DWORD dwLen = 10; wchar_t szHttpRes[10]; DWORD nIndex = 0; if( !HttpQueryInfo( hRequest, HTTP_QUERY_STATUS_CODE, szHttpRes, &dwLen, &nIndex) ) { pszErrFunction = L"HttpQueryInfo"; return; } int nCode = _wtoi(szHttpRes); pNetResp->setResponseCode(nCode); if ( m_pHeaders ) { if ( !readHeaders(*m_pHeaders) ) return; } if ( nCode != 200 ) { LOG(ERROR) + "An error occured connecting to the sync source: " + szHttpRes + " returned."; // If we're unauthorized, delete any cookies that might have been // stored so we don't reuse them later if ( nCode == 401 && m_pSession ) { m_pSession->logout(); } } if (pNetResp->isOK()) pNetResp->setCookies(makeClientCookie()); }
static char *http_receive(HINTERNET h_req, u_long *d_size) { u_long bytes = sizeof(u_long); u_long qsize = 0; u_long readed = 0; char *data = NULL; char buff[4096]; if (HttpQueryInfo(h_req, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &qsize, &bytes, NULL) != 0) { data = malloc(qsize + 1); } do { if (InternetReadFile(h_req, buff, sizeof(buff), &bytes) == 0) { break; } if ( (readed + bytes) > qsize) { data = realloc(data, readed + bytes + 1); if (data == NULL) break; qsize += bytes; } memcpy(data + readed, buff, bytes); readed += bytes; } while (bytes != 0); if ( (data != NULL) && (readed != qsize) ) { free(data); data = NULL; } else { if (d_size != NULL) *d_size = readed; data[readed] = 0; } return data; }
unsigned long BuscarActualizaciones::ThreadBuscarActualizacion(void *phWnd) { // try { HINTERNET Sesion = InternetOpen(TEXT("BubaTronik"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, INTERNET_INVALID_PORT_NUMBER, 0); HINTERNET Peticion = InternetOpenUrl(Sesion, TEXT("http://www.devildrey33.es/BubaTronik/VERSION_BUBATRONIK.txt"), NULL, 0, INTERNET_FLAG_RELOAD, 0); char Txt[32] = ""; DWORD BytesLeidos = 0; DWORD TotalBytesLeidos = 0; DWORD MaxBuffer = sizeof(Txt) -1; DWL::DWLString Ret; // No se ha encontrado la version :/ if (Peticion == NULL) { InternetCloseHandle(Sesion); return 0; } BOOL Leido = InternetReadFile(Peticion, Txt, MaxBuffer, &BytesLeidos); if (BytesLeidos != 0) { Txt[BytesLeidos] = 0; Ret += Txt; // ZeroMemory(Txt, sizeof(Txt) * sizeof(char)); } HWND hWndPlayer = reinterpret_cast<HWND>(phWnd); if (Ret.Tam() == 0) { InternetCloseHandle(Peticion); InternetCloseHandle(Sesion); return 0; } if (Ret[0] == TEXT('<')) { InternetCloseHandle(Peticion); InternetCloseHandle(Sesion); return 0; // no se ha encontrado el documento } DWL::DWLString Version; Version.sprintf(TEXT("%.02f"), static_cast<float>(APP_NUM_VER)); // La versión no es la misma, leemos las novedades if (Ret.SubStr(0, Version.Tam()) != Version) { HINTERNET PeticionNovedades = InternetOpenUrl(Sesion, TEXT("http://www.devildrey33.es/BubaTronik/NOVEDADES_BUBATRONIK.txt"), NULL, 0, INTERNET_FLAG_RELOAD, 0); DWORD TotalDatos = 0; DWORD Descargado = 64; TCHAR TotalDatosStr[64]; BOOL bRet = HttpQueryInfo(PeticionNovedades, HTTP_QUERY_CONTENT_LENGTH, (LPVOID)TotalDatosStr, &Descargado, (LPDWORD)0); if (bRet == TRUE) TotalDatos = _wtol(TotalDatosStr); char *TmpBuffer = new char[TotalDatos + 1]; Leido = InternetReadFile(PeticionNovedades, TmpBuffer, TotalDatos, &BytesLeidos); if (BytesLeidos != 0 && BytesLeidos <= TotalDatos) TmpBuffer[BytesLeidos] = 0; Sistema.App.PlayerEx.VentanaActualizacion.Novedades(TmpBuffer); delete [] TmpBuffer; PostMessage(hWndPlayer, MENSAJE_ACTUALIZACION_ENCONTRADA, 0, 0); } InternetCloseHandle(Peticion); InternetCloseHandle(Sesion); // } // catch (...) { // } return 0; }
static gboolean gst_win_inet_src_get_header_value_as_int (GstWinInetSrc * self, const gchar * header_name, gint * header_value, gboolean log_failure) { gchar buf[16] = { 0, }; DWORD buf_size = sizeof (buf); gint *value = (gint *) buf; strcpy (buf, header_name); if (!HttpQueryInfo (self->url, HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_NUMBER, buf, &buf_size, NULL)) { if (log_failure) { DWORD error_code = GetLastError (); const gchar *error_str = "unknown error"; if (error_code == ERROR_HTTP_HEADER_NOT_FOUND) error_str = "ERROR_HTTP_HEADER_NOT_FOUND"; GST_WARNING_OBJECT (self, "HttpQueryInfo for header '%s' failed: %s " "(0x%08lx)", header_name, error_str, error_code); } return FALSE; } *header_value = *value; return TRUE; }
void CNetRequestImpl::readResponse(CNetResponseImpl* pNetResp) { DWORD dwLen = 10; wchar_t szHttpRes[10]; DWORD nIndex = 0; if( !HttpQueryInfo( hRequest, HTTP_QUERY_STATUS_CODE, szHttpRes, &dwLen, &nIndex) ) { pszErrFunction = L"HttpSendRequest"; return; } int nCode = _wtoi(szHttpRes); pNetResp->setResponseCode(nCode); if ( nCode != 200 ) { LOG(ERROR) + "An error occured connecting to the sync source: " + szHttpRes + " returned."; // If we're unauthorized, delete any cookies that might have been // stored so we don't reuse them later if ( nCode == 401 ) { CAtlStringA strUrlA; int nQuest = strReqUrlW.Find('?'); if ( nQuest > 0 ) strUrlA = strReqUrlW.Mid(0,nQuest-1); else strUrlA = strReqUrlW; ::InternetSetCookieA(strUrlA, NULL, ""); } } }
BOOL CFileDownloader::_CheckIfModifiedSince( LPCTSTR lpszURL, LPCTSTR lpszLastModifed, BOOL bUseProxyConfig, BOOL& modified ) { if(!lpszLastModifed) return FALSE; BOOL bRet = FALSE; do { CString strHeaderIfModifiedSince; strHeaderIfModifiedSince.Format(_T("If-Modified-Since:%s\r\n"), lpszLastModifed); if(!_IssueRequest(m_strHostname, m_strHostPath, strHeaderIfModifiedSince, bUseProxyConfig)) break; DWORD dwStatus = 0; DWORD dwSize = sizeof(DWORD); BOOL bStatusOK = HttpQueryInfo(m_hRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwSize, NULL); if( !bStatusOK) break; modified = dwStatus == HTTP_STATUS_NOT_MODIFIED; return TRUE; }while(FALSE); return bRet; }
std::string HttpSnaffle::FetchStatusMessage() { char* p = 0; DWORD size = 0; DWORD index = 0; // First get size HttpQueryInfo(myRequest, HTTP_QUERY_STATUS_TEXT, p, &size, &index); // Then get actual data p = new char[size]; std::string s; if (HttpQueryInfo(myRequest, HTTP_QUERY_STATUS_TEXT, p, &size, &index)) { s = p; delete[] p; } return s; }
BOOL CFileDownloader::_GetHttpInfo( HINTERNET hRequest, DWORD dwInfoLevel, CString &str ) { DWORD dwBufLen = MAX_PATH; DWORD dwIndex = 0; BOOL bRet = HttpQueryInfo(hRequest, dwInfoLevel, str.GetBuffer(MAX_PATH), &dwBufLen, &dwIndex); str.ReleaseBuffer(); return bRet; }
DWORD getTotalBytes() const { DWORD totalBytes; DWORD sizeof_total_bytes = sizeof(totalBytes); HttpQueryInfo(mDownload, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &totalBytes, &sizeof_total_bytes, NULL); return totalBytes; }
int Request::getStatusCode() { DWORD read = 10; char buff [10]; if (HttpQueryInfo(_hRequest , HTTP_QUERY_STATUS_CODE , buff , &read , 0)) { return atoi(buff); } return 0; }
CBStringA CBHttpRequest::QueryInfo(DWORD i) { CBStringA str; if(m_nReadyState < 2)return str; DWORD dwLen = 0; HttpQueryInfo(m_hFile, i, NULL, &dwLen, 0); LPSTR pstr = str.GetBufferSetLength(dwLen); if (HttpQueryInfo(m_hFile, i, pstr, &dwLen, NULL)) str.ReleaseBuffer(dwLen); else str.ReleaseBuffer(0); return str; }
void CALLBACK my_InternetStatusCallback(HINTERNET hRequest, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength) { LPINTERNET_ASYNC_RESULT AsyncResult = (LPINTERNET_ASYNC_RESULT) lpvStatusInformation; INTERNET_STATUS_CALLBACK RealInetCallback; PHANDLE_CONTEXT Ctx; ENTER_HOOK(); if (Ctx = FindHandle(hRequest)) { switch (dwInternetStatus) { case INTERNET_STATUS_HANDLE_CLOSING: DelHandle(hRequest); break; case INTERNET_STATUS_REQUEST_COMPLETE: if (Ctx->Status == DOWNLOADING) { if (!AsyncResult->dwResult) Ctx->Status = ERROR_WHILE_LOADING; SetEvent(Ctx->AsyncEvent); ReleaseHandle(Ctx); LEAVE_HOOK(); return; } // if (Ctx->Status == DOWNLOADING) else { ULONG HttpStatus, bSize = sizeof(ULONG); if (HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE, &HttpStatus, &bSize, &bSize)) { if (HttpStatus == 1) { __debugbreak(); } } else bSize = GetLastError(); } break; default: break; } // switch (dwInternetStatus) if (RealInetCallback = Ctx->Callback) { ASSERT((LONG_PTR)Ctx->Callback > 0); // User-mode address (RealInetCallback) (hRequest, dwContext, dwInternetStatus, lpvStatusInformation, dwStatusInformationLength); } ReleaseHandle(Ctx); } // if (Ctx = FindHandle(hInternet)) LEAVE_HOOK(); }
Date64 Request::getLastModificationTime() { SYSTEMTIME time; DWORD size = sizeof(time); if (HttpQueryInfo(_hRequest , HTTP_QUERY_LAST_MODIFIED | HTTP_QUERY_FLAG_SYSTEMTIME , &time , &size , 0)) { return Date64(time); } else { return Date64(false); } }
int Request::getInfoInt(int type) { int value; DWORD size = 4; if (HttpQueryInfo(_hRequest , type | HTTP_QUERY_FLAG_NUMBER , &value , &size , 0)) { return value; } else { return 0; } }
int HttpSnaffle::FetchStatusCode() { int length = -1; DWORD size = sizeof(length); DWORD index = 0; if (!HttpQueryInfo(myRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &length, &size, &index)) return -1; return length; }
fsString fsHttpFile::GetCookiesFromResponse() { char sz [10000]; DWORD dw = sizeof (sz) - 1; if (FALSE == HttpQueryInfo (m_hFile, HTTP_QUERY_SET_COOKIE, sz, &dw, NULL)) return ""; return sz; }
FString GetHeader(DWORD dwHeader) { char szHeader[1024]; DWORD dwLen = 1024; if (HttpQueryInfo(m_hReq, dwHeader, szHeader, &dwLen, 0)) { return FString(szHeader); } return ""; }
boolean CNetRequestImpl::readHeaders(Hashtable<String,String>& oHeaders) { oHeaders.clear(); CAtlStringW strHeaders; DWORD dwLen = 0; DWORD nIndex = 0; if( !HttpQueryInfo( hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, null, &dwLen, &nIndex) ) { DWORD dwErr = ::GetLastError(); if ( dwErr != ERROR_INSUFFICIENT_BUFFER ) { pszErrFunction = L"HttpQueryInfo"; return false; } } if( !HttpQueryInfo( hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, strHeaders.GetBuffer(dwLen), &dwLen, &nIndex) ) { pszErrFunction = L"HttpQueryInfo"; return false; } strHeaders.ReleaseBuffer(); int nStart = 0; for(int nEnd = strHeaders.Find(L"\r\n", nStart); nEnd > 0; nStart = nEnd+2, nEnd = strHeaders.Find(L"\r\n", nStart) ) { CAtlStringW strHeader = strHeaders.Mid(nStart, nEnd-nStart); int nSep = strHeader.Find(':'); if (nSep < 0 ) continue; CAtlStringW strName = strHeader.Mid(0, nSep); strName.Trim(); strName.MakeLower(); CAtlStringW strValue = strHeader.Mid(nSep+1); strValue.Trim(); oHeaders.put(common::convertToStringA(strName.GetString()),common::convertToStringA(strValue.GetString())); } return true; }
int HttpDownloadInet::_getStatusCode(HINTERNET hRemoteFile) const { DWORD dwStatus; DWORD dwStatusSize = sizeof(dwStatus); if (HttpQueryInfo(hRemoteFile, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwStatusSize, NULL)) { return dwStatus; } return ERROR_FILE_NOTFOUND; }
int HttpDownloadInet::_getFileSize(HINTERNET hRemoteFile) const { wchar_t szSizeBuffer[64]; DWORD dwLengthSizeBuffer = sizeof(szSizeBuffer); if (HttpQueryInfo(hRemoteFile, HTTP_QUERY_CONTENT_LENGTH, szSizeBuffer, &dwLengthSizeBuffer, NULL)) { return _wtol(szSizeBuffer); } return 0; }
/* get the http respnse code return -1 if it fails */ DWORD get_http_status_code(HINTERNET requesthandle){ DWORD response_code = -1; DWORD response_code_size = sizeof(DWORD); BOOL ishttpqueryinfo = FALSE; ishttpqueryinfo = HttpQueryInfo(requesthandle, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &response_code, &response_code_size, NULL); if (!ishttpqueryinfo){ return response_code; } return response_code; }
void FHttpResponseWinInet::ProcessResponseCode() { // get the response code ResponseCode = EHttpResponseCodes::Unknown; ::DWORD CodeSize = sizeof(ResponseCode); if (!HttpQueryInfo(Request.RequestHandle, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &ResponseCode, &CodeSize, NULL)) { UE_LOG(LogHttp, Warning, TEXT("HttpQueryInfo for response code failed: %s. %p"), *InternetTranslateError(GetLastError()), &Request); } }
STDMETHODIMP CBHttpRequest::getResponseHeader(BSTR strName, BSTR *retVal) { if(m_nReadyState < 2) return S_OK; CBStringA str(strName); LPSTR pstr = str.GetBuffer(); DWORD dwLen = str.GetLength(); if(!HttpQueryInfo(m_hFile, HTTP_QUERY_CUSTOM, pstr, &dwLen, 0)) { if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) { pstr = str.GetBufferSetLength(dwLen); HttpQueryInfo(m_hFile, HTTP_QUERY_CUSTOM, pstr, &dwLen, NULL); } else dwLen = 0; } str.ReleaseBuffer(dwLen); *retVal = str.AllocSysString(); return S_OK; }
fsInternetResult fsHttpFile::ProcessRangesResponse() { CHAR sz [10000]; DWORD dw = sizeof (sz); BOOL bAcceptRanges = FALSE; if (HttpQueryInfo (m_hFile, HTTP_QUERY_ACCEPT_RANGES, sz, &dw, NULL)) { if (stricmp (sz, "bytes") == 0) bAcceptRanges = TRUE; } m_enRST = RST_NONE; dw = sizeof (sz); if (!HttpQueryInfo (m_hFile, HTTP_QUERY_CONTENT_RANGE, sz, &dw, NULL)) return bAcceptRanges ? IR_DOUBTFUL_RANGESRESPONSE : IR_RANGESNOTAVAIL; if (strncmp (sz, "bytes", 5)) return bAcceptRanges ? IR_DOUBTFUL_RANGESRESPONSE : IR_RANGESNOTAVAIL; int pos = 0; while (sz [pos++] != ' '); if (isdigit (sz [pos]) == false) return IR_RANGESNOTAVAIL; UINT64 first = (UINT64) _atoi64 (sz + pos); while (sz [pos] >= '0' && sz [pos] <= '9') pos++; pos++; UINT64 last = (UINT64) _atoi64 (sz + pos); if (last < first) return IR_RANGESNOTAVAIL; while (sz [pos] >= '0' && sz [pos] <= '9') pos++; pos++; m_uFileSize = (UINT64) _atoi64 (sz + pos); if (m_uFileSize < last) return IR_RANGESNOTAVAIL; m_enRST = RST_PRESENT; return IR_SUCCESS; }