@@ -1688,10 +1688,6 @@ XS(w32_HttpGetFile)
1688
1688
{
1689
1689
dXSARGS ;
1690
1690
WCHAR * url = NULL , * file = NULL , * hostName = NULL , * urlPath = NULL ;
1691
- DWORD dwSize = 0 ;
1692
- DWORD dwDownloaded = 0 ;
1693
- DWORD dwBytesWritten = 0 ;
1694
- LPSTR pszOutBuffer ;
1695
1691
BOOL bResults = FALSE;
1696
1692
HINTERNET hSession = NULL ,
1697
1693
hConnect = NULL ,
@@ -1703,9 +1699,6 @@ XS(w32_HttpGetFile)
1703
1699
DWORD error = 0 ;
1704
1700
URL_COMPONENTS urlComp ;
1705
1701
LPCWSTR acceptTypes [] = { L"*/*" , NULL };
1706
- WINHTTP_AUTOPROXY_OPTIONS AutoProxyOptions ;
1707
- WINHTTP_PROXY_INFO ProxyInfo ;
1708
- DWORD cbProxyInfoSize = sizeof (ProxyInfo );
1709
1702
1710
1703
if (items != 2 )
1711
1704
croak ("usage: Win32::HttpGetFile($url, $file)" );
@@ -1777,6 +1770,10 @@ XS(w32_HttpGetFile)
1777
1770
* configuration, which the request handle will inherit from the session).
1778
1771
*/
1779
1772
if (hRequest ) {
1773
+ WINHTTP_AUTOPROXY_OPTIONS AutoProxyOptions ;
1774
+ WINHTTP_PROXY_INFO ProxyInfo ;
1775
+ DWORD cbProxyInfoSize = sizeof (ProxyInfo );
1776
+
1780
1777
ZeroMemory (& AutoProxyOptions , sizeof (AutoProxyOptions ));
1781
1778
ZeroMemory (& ProxyInfo , sizeof (ProxyInfo ));
1782
1779
AutoProxyOptions .dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT ;
@@ -1825,42 +1822,29 @@ XS(w32_HttpGetFile)
1825
1822
FILE_ATTRIBUTE_NORMAL ,
1826
1823
NULL );
1827
1824
1828
- if (! hOut || hOut == INVALID_HANDLE_VALUE )
1825
+ if (hOut == INVALID_HANDLE_VALUE )
1829
1826
bFileError = TRUE;
1830
1827
}
1831
1828
1832
- /* Keep checking for data until there is nothing left. */
1833
1829
if (!bFileError && bResults ) {
1834
- do {
1835
- /* Check for available data. */
1836
- dwSize = 0 ;
1837
- if (!WinHttpQueryDataAvailable (hRequest , & dwSize )) {
1838
- bAborted = TRUE;
1839
- break ;
1840
- }
1841
-
1842
- /* No more available data. */
1843
- if (!dwSize )
1844
- break ;
1845
-
1846
- /* Allocate space for the buffer. */
1847
- New (0 , pszOutBuffer , dwSize + 1 , char );
1848
- if (!pszOutBuffer ) {
1849
- bAborted = TRUE;
1850
- break ;
1851
- }
1830
+ DWORD dwDownloaded = 0 ;
1831
+ DWORD dwBytesWritten = 0 ;
1832
+ DWORD dwSize = 65536 ;
1833
+ char * pszOutBuffer ;
1852
1834
1853
- /* Read the Data. */
1854
- ZeroMemory (pszOutBuffer , dwSize + 1 );
1835
+ New (0 , pszOutBuffer , dwSize , char );
1855
1836
1837
+ /* Keep checking for data until there is nothing left. */
1838
+ while (1 ) {
1856
1839
if (!WinHttpReadData (hRequest ,
1857
1840
(LPVOID )pszOutBuffer ,
1858
1841
dwSize ,
1859
1842
& dwDownloaded )) {
1860
1843
bAborted = TRUE;
1861
- Safefree (pszOutBuffer );
1862
1844
break ;
1863
1845
}
1846
+ if (!dwDownloaded )
1847
+ break ;
1864
1848
1865
1849
/* Write what we just read to the output file */
1866
1850
if (!WriteFile (hOut ,
@@ -1870,19 +1854,12 @@ XS(w32_HttpGetFile)
1870
1854
NULL )) {
1871
1855
bAborted = TRUE;
1872
1856
bFileError = TRUE;
1873
- Safefree (pszOutBuffer );
1874
1857
break ;
1875
1858
}
1876
1859
1877
- Safefree (pszOutBuffer );
1878
-
1879
- /* This condition would only be reached if WinHttpQueryDataAvailable
1880
- * said there are more data to read but WinHttpReadData didn't get any.
1881
- */
1882
- if (!dwDownloaded )
1883
- break ;
1884
1860
}
1885
- while (dwSize > 0 );
1861
+
1862
+ Safefree (pszOutBuffer );
1886
1863
}
1887
1864
else {
1888
1865
bAborted = TRUE;
0 commit comments