MCPcopy Create free account
hub / github.com/EasyIME/PIME / openHttpFile

Function openHttpFile

installer/inetc/Contrib/Inetc/inetc.cpp:644–832  ·  view source on GitHub ↗

* FUNCTION NAME: openHttpFile() * PURPOSE: * file open, size request, re-get lseek * SPECIAL CONSIDERATIONS: * *****************************************************/

Source from the content-addressed store, hash-verified

642*
643*****************************************************/
644HINTERNET openHttpFile(HINTERNET hConn, INTERNET_SCHEME nScheme, TCHAR *path)
645{
646 TCHAR buf[256] = TEXT("");
647 HINTERNET hFile;
648 DWORD rslt, err;
649 bool first_attempt = true;;
650
651// test connection for PUT, the only way to do this before sending data
652// OPTIONS fails on HttpOpenRequest step for HTTPS
653// but works for HEAD I guess
654 if(fput)// && nScheme != INTERNET_SCHEME_HTTPS)
655 {
656// old proxy's may not support OPTIONS request, so changed to HEAD....
657 if((hFile = HttpOpenRequest(hConn, TEXT("HEAD"), path, NULL, NULL, NULL,
658// if((hFile = HttpOpenRequest(hConn, TEXT("OPTIONS"), path, NULL, NULL, NULL,
659 INTERNET_FLAG_RELOAD | INTERNET_FLAG_KEEP_CONNECTION |
660 (nocookies ? (INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES) : 0), 0)) != NULL)
661 {
662 if(*szAuth)
663 {
664 wsprintf(buf, PROXY_AUTH_HDR, szAuth);
665 HttpAddRequestHeaders(hFile, buf, -1,
666 HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE);
667 }
668resend_proxy1:
669 if(*szBasic)
670 {
671 wsprintf(buf, HOST_AUTH_HDR, szBasic);
672 HttpAddRequestHeaders(hFile, buf, -1,
673 HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE);
674 }
675resend_auth1:
676 if(HttpSendRequest(hFile, NULL, 0, NULL, 0))
677 {
678 queryStatus(hFile);
679// may be don't need to read all from socket, but this looks safer
680 while(InternetReadFile(hFile, buf, sizeof(buf), &rslt) && rslt > 0) {}
681 if(!silent && (status == ERR_PROXY || status == ERR_AUTH))// || status == ERR_FORBIDDEN))
682 {
683 rslt = InternetErrorDlg(hDlg, hFile,
684 ERROR_INTERNET_INCORRECT_PASSWORD,
685 FLAGS_ERROR_UI_FILTER_FOR_ERRORS |
686 FLAGS_ERROR_UI_FLAGS_GENERATE_DATA |
687 FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS,
688 NULL);
689 if (rslt == ERROR_INTERNET_FORCE_RETRY)
690 {
691 status = ST_URLOPEN;
692 if(status == ERR_PROXY) goto resend_proxy1;
693 else goto resend_auth1;
694 }
695 else
696 {
697 status = ST_CANCELLED;
698 }
699
700 }
701 // no such file is OK for PUT. server first checks authentication

Callers 1

inetTransferFunction · 0.85

Calls 3

queryStatusFunction · 0.85
mySendRequestFunction · 0.85
myatouFunction · 0.85

Tested by

no test coverage detected