2005-06-30 22:49:27 +02:00
/*
2012-05-15 10:15:32 +02:00
* Wininet - HTTP tests
2005-06-30 22:49:27 +02:00
*
* Copyright 2002 Aric Stewart
* Copyright 2004 Mike McCormack
* Copyright 2005 Hans Leidekker
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
2006-05-18 14:49:52 +02:00
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 , USA
2005-06-30 22:49:27 +02:00
*/
2003-09-06 01:08:26 +02:00
# include <stdarg.h>
2002-06-22 01:59:49 +02:00
# include <stdio.h>
2002-10-29 22:24:35 +01:00
# include <stdlib.h>
# include "windef.h"
2002-06-22 01:59:49 +02:00
# include "winbase.h"
# include "wininet.h"
2012-06-11 10:22:54 +02:00
# include "winineti.h"
2013-10-24 12:15:43 +02:00
# include "winsock2.h"
2002-06-22 01:59:49 +02:00
2002-10-29 22:24:35 +01:00
# include "wine/test.h"
2014-09-04 11:34:59 +02:00
/* Undocumented security flags */
# define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
# define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
# define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
# define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
2011-03-14 16:43:19 +01:00
# define TEST_URL "http: //test.winehq.org/tests/hello.html"
2005-10-31 15:06:35 +01:00
2007-07-15 23:29:48 +02:00
static BOOL first_connection_to_test_url = TRUE ;
/* Adapted from dlls/urlmon/tests/protocol.c */
# define SET_EXPECT2(status, num) \
expect [ status ] = num
# define SET_EXPECT(status) \
SET_EXPECT2 ( status , 1 )
2008-08-26 11:27:26 +02:00
# define SET_OPTIONAL2(status, num) \
optional [ status ] = num
# define SET_OPTIONAL(status) \
SET_OPTIONAL2 ( status , 1 )
2007-07-15 23:29:48 +02:00
/* SET_WINE_ALLOW's should be used with an appropriate
* todo_wine CHECK_NOTIFIED at a later point in the code */
# define SET_WINE_ALLOW2(status, num) \
wine_allow [ status ] = num
# define SET_WINE_ALLOW(status) \
SET_WINE_ALLOW2 ( status , 1 )
# define CHECK_EXPECT(status) \
do { \
2008-08-26 11:27:26 +02:00
if ( ! expect [ status ] & & ! optional [ status ] & & wine_allow [ status ] ) \
2007-07-15 23:29:48 +02:00
{ \
todo_wine ok ( expect [ status ] , " unexpected status %d (%s) \n " , status , \
2011-02-03 20:46:05 +01:00
status < MAX_INTERNET_STATUS & & status_string [ status ] ? \
2007-07-15 23:29:48 +02:00
status_string [ status ] : " unknown " ) ; \
wine_allow [ status ] - - ; \
} \
else \
{ \
2008-08-26 11:27:26 +02:00
ok ( expect [ status ] | | optional [ status ] , " unexpected status %d (%s) \n " , status , \
2011-02-03 20:46:05 +01:00
status < MAX_INTERNET_STATUS & & status_string [ status ] ? \
2007-07-15 23:29:48 +02:00
status_string [ status ] : " unknown " ) ; \
2008-08-26 11:27:26 +02:00
if ( expect [ status ] ) expect [ status ] - - ; \
2014-09-02 12:37:37 +02:00
else if ( optional [ status ] ) optional [ status ] - - ; \
2007-07-15 23:29:48 +02:00
} \
notified [ status ] + + ; \
} while ( 0 )
/* CLEAR_NOTIFIED used in cases when notification behavior
* differs between Windows versions */
# define CLEAR_NOTIFIED(status) \
2008-08-26 11:27:26 +02:00
expect [ status ] = optional [ status ] = wine_allow [ status ] = notified [ status ] = 0 ;
2007-07-15 23:29:48 +02:00
# define CHECK_NOTIFIED2(status, num) \
do { \
2009-03-25 11:55:17 +01:00
ok ( notified [ status ] + optional [ status ] = = ( num ) , \
" expected status %d (%s) %d times, received %d times \n " , \
2011-02-03 20:46:05 +01:00
status , status < MAX_INTERNET_STATUS & & status_string [ status ] ? \
2007-07-15 23:29:48 +02:00
status_string [ status ] : " unknown " , ( num ) , notified [ status ] ) ; \
CLEAR_NOTIFIED ( status ) ; \
} while ( 0 )
# define CHECK_NOTIFIED(status) \
CHECK_NOTIFIED2 ( status , 1 )
# define CHECK_NOT_NOTIFIED(status) \
CHECK_NOTIFIED2 ( status , 0 )
# define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
2008-08-26 11:27:26 +02:00
static int expect [ MAX_INTERNET_STATUS ] , optional [ MAX_INTERNET_STATUS ] ,
wine_allow [ MAX_INTERNET_STATUS ] , notified [ MAX_INTERNET_STATUS ] ;
2011-02-03 20:46:05 +01:00
static const char * status_string [ MAX_INTERNET_STATUS ] ;
2007-07-15 23:29:48 +02:00
2016-05-04 12:40:03 +02:00
static HANDLE hCompleteEvent , conn_close_event , conn_wait_event , server_req_rec_event ;
2011-06-10 14:47:37 +02:00
static DWORD req_error ;
2002-06-22 01:59:49 +02:00
2009-05-29 23:35:36 +02:00
# define TESTF_REDIRECT 0x01
# define TESTF_COMPRESSED 0x02
2012-05-03 10:11:12 +02:00
# define TESTF_CHUNKED 0x04
2009-05-29 23:35:36 +02:00
typedef struct {
const char * url ;
const char * redirected_url ;
const char * host ;
const char * path ;
2011-01-13 13:54:23 +01:00
const char * headers ;
2009-05-29 23:35:36 +02:00
DWORD flags ;
2011-01-13 13:54:23 +01:00
const char * post_data ;
const char * content ;
2009-05-29 23:35:36 +02:00
} test_data_t ;
static const test_data_t test_data [ ] = {
2011-04-02 15:20:53 +02:00
{
" http://test.winehq.org/tests/data.php " ,
" http://test.winehq.org/tests/data.php " ,
" test.winehq.org " ,
" /tests/data.php " ,
" " ,
2012-05-03 10:11:12 +02:00
TESTF_CHUNKED
2011-04-02 15:20:53 +02:00
} ,
2009-05-29 23:35:36 +02:00
{
2011-03-14 16:43:19 +01:00
" http://test.winehq.org/tests/redirect " ,
" http://test.winehq.org/tests/hello.html " ,
2009-05-29 23:35:36 +02:00
" test.winehq.org " ,
2011-03-14 16:43:19 +01:00
" /tests/redirect " ,
2011-01-13 13:54:23 +01:00
" " ,
2009-05-29 23:35:36 +02:00
TESTF_REDIRECT
} ,
{
2014-09-03 14:39:51 +02:00
" http://test.winehq.org/tests/gzip.php " ,
" http://test.winehq.org/tests/gzip.php " ,
" test.winehq.org " ,
" /tests/gzip.php " ,
2011-01-13 13:54:23 +01:00
" Accept-Encoding: gzip, deflate " ,
2012-05-03 10:11:12 +02:00
TESTF_COMPRESSED
2011-01-13 13:54:23 +01:00
} ,
{
2011-05-02 14:23:52 +02:00
" http://test.winehq.org/tests/post.php " ,
" http://test.winehq.org/tests/post.php " ,
" test.winehq.org " ,
" /tests/post.php " ,
2011-01-13 13:54:23 +01:00
" Content-Type: application/x-www-form-urlencoded " ,
2012-05-03 10:11:12 +02:00
0 ,
2011-01-13 13:54:23 +01:00
" mode=Test " ,
" mode => Test \n "
2009-05-29 23:35:36 +02:00
}
} ;
2007-02-20 15:53:49 +01:00
static INTERNET_STATUS_CALLBACK ( WINAPI * pInternetSetStatusCallbackA ) ( HINTERNET , INTERNET_STATUS_CALLBACK ) ;
2013-02-18 15:45:30 +01:00
static INTERNET_STATUS_CALLBACK ( WINAPI * pInternetSetStatusCallbackW ) ( HINTERNET , INTERNET_STATUS_CALLBACK ) ;
2012-06-11 10:22:54 +02:00
static BOOL ( WINAPI * pInternetGetSecurityInfoByURLA ) ( LPSTR , PCCERT_CHAIN_CONTEXT * , DWORD * ) ;
2007-02-20 15:53:49 +01:00
2012-06-15 18:15:20 +02:00
static int strcmp_wa ( LPCWSTR strw , const char * stra )
{
WCHAR buf [ 512 ] ;
MultiByteToWideChar ( CP_ACP , 0 , stra , - 1 , buf , sizeof ( buf ) / sizeof ( WCHAR ) ) ;
return lstrcmpW ( strw , buf ) ;
}
2011-01-21 13:35:40 +01:00
static BOOL proxy_active ( void )
{
HKEY internet_settings ;
DWORD proxy_enable ;
DWORD size ;
if ( RegOpenKeyExA ( HKEY_CURRENT_USER , " Software \\ Microsoft \\ Windows \\ CurrentVersion \\ Internet Settings " ,
0 , KEY_QUERY_VALUE , & internet_settings ) ! = ERROR_SUCCESS )
return FALSE ;
size = sizeof ( DWORD ) ;
if ( RegQueryValueExA ( internet_settings , " ProxyEnable " , NULL , NULL , ( LPBYTE ) & proxy_enable , & size ) ! = ERROR_SUCCESS )
proxy_enable = 0 ;
RegCloseKey ( internet_settings ) ;
return proxy_enable ! = 0 ;
}
2007-02-20 15:53:49 +01:00
2013-06-05 17:35:41 +02:00
# define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)
# define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
static void _test_status_code ( unsigned line , HINTERNET req , DWORD excode , BOOL is_todo )
2012-05-03 12:19:33 +02:00
{
DWORD code , size , index ;
char exbuf [ 10 ] , bufa [ 10 ] ;
2012-06-15 18:15:20 +02:00
WCHAR bufw [ 10 ] ;
2012-05-03 12:19:33 +02:00
BOOL res ;
code = 0xdeadbeef ;
size = sizeof ( code ) ;
2012-06-15 18:15:20 +02:00
res = HttpQueryInfoA ( req , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & code , & size , NULL ) ;
ok_ ( __FILE__ , line ) ( res , " [1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u \n " , GetLastError ( ) ) ;
2016-02-15 23:14:40 +01:00
todo_wine_if ( is_todo )
2013-06-05 17:35:41 +02:00
ok_ ( __FILE__ , line ) ( code = = excode , " code = %d, expected %d \n " , code , excode ) ;
2012-06-15 18:15:20 +02:00
ok_ ( __FILE__ , line ) ( size = = sizeof ( code ) , " size = %u \n " , size ) ;
2012-05-03 12:19:33 +02:00
code = 0xdeadbeef ;
index = 0 ;
size = sizeof ( code ) ;
2012-06-15 18:15:20 +02:00
res = HttpQueryInfoA ( req , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & code , & size , & index ) ;
ok_ ( __FILE__ , line ) ( res , " [2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u \n " , GetLastError ( ) ) ;
2016-02-17 18:03:22 +01:00
ok_ ( __FILE__ , line ) ( ! index , " index = %d, expected 0 \n " , index ) ;
2012-06-15 18:15:20 +02:00
ok_ ( __FILE__ , line ) ( size = = sizeof ( code ) , " size = %u \n " , size ) ;
2012-05-03 12:19:33 +02:00
sprintf ( exbuf , " %u " , excode ) ;
size = sizeof ( bufa ) ;
2012-06-15 18:15:20 +02:00
res = HttpQueryInfoA ( req , HTTP_QUERY_STATUS_CODE , bufa , & size , NULL ) ;
ok_ ( __FILE__ , line ) ( res , " [3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u \n " , GetLastError ( ) ) ;
2016-02-15 23:14:40 +01:00
todo_wine_if ( is_todo )
2013-06-05 17:35:41 +02:00
ok_ ( __FILE__ , line ) ( ! strcmp ( bufa , exbuf ) , " unexpected status code %s, expected %s \n " , bufa , exbuf ) ;
2012-06-15 18:15:20 +02:00
ok_ ( __FILE__ , line ) ( size = = strlen ( exbuf ) , " unexpected size %d for \" %s \" \n " , size , exbuf ) ;
size = 0 ;
res = HttpQueryInfoA ( req , HTTP_QUERY_STATUS_CODE , NULL , & size , NULL ) ;
ok_ ( __FILE__ , line ) ( ! res & & GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" [4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u \n " , GetLastError ( ) ) ;
ok_ ( __FILE__ , line ) ( size = = strlen ( exbuf ) + 1 , " unexpected size %d for \" %s \" \n " , size , exbuf ) ;
size = sizeof ( bufw ) ;
res = HttpQueryInfoW ( req , HTTP_QUERY_STATUS_CODE , bufw , & size , NULL ) ;
ok_ ( __FILE__ , line ) ( res , " [5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u \n " , GetLastError ( ) ) ;
2016-02-15 23:14:40 +01:00
todo_wine_if ( is_todo )
2013-06-05 17:35:41 +02:00
ok_ ( __FILE__ , line ) ( ! strcmp_wa ( bufw , exbuf ) , " unexpected status code %s, expected %s \n " , bufa , exbuf ) ;
2012-06-15 18:15:20 +02:00
ok_ ( __FILE__ , line ) ( size = = strlen ( exbuf ) * sizeof ( WCHAR ) , " unexpected size %d for \" %s \" \n " , size , exbuf ) ;
size = 0 ;
res = HttpQueryInfoW ( req , HTTP_QUERY_STATUS_CODE , bufw , & size , NULL ) ;
ok_ ( __FILE__ , line ) ( ! res & & GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" [6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u \n " , GetLastError ( ) ) ;
ok_ ( __FILE__ , line ) ( size = = ( strlen ( exbuf ) + 1 ) * sizeof ( WCHAR ) , " unexpected size %d for \" %s \" \n " , size , exbuf ) ;
if ( 0 ) {
size = sizeof ( bufw ) ;
res = HttpQueryInfoW ( req , HTTP_QUERY_STATUS_CODE , NULL , & size , NULL ) ;
ok ( ! res & & GetLastError ( ) = = ERROR_INVALID_PARAMETER , " HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u \n " , GetLastError ( ) ) ;
ok ( size = = sizeof ( bufw ) , " unexpected size %d \n " , size ) ;
}
2012-05-03 12:19:33 +02:00
code = 0xdeadbeef ;
index = 1 ;
size = sizeof ( code ) ;
2012-06-15 18:15:20 +02:00
res = HttpQueryInfoA ( req , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & code , & size , & index ) ;
2012-05-03 12:19:33 +02:00
ok_ ( __FILE__ , line ) ( ! res & & GetLastError ( ) = = ERROR_HTTP_HEADER_NOT_FOUND ,
2012-06-15 18:15:20 +02:00
" [7] HttpQueryInfoA failed: %x(%d) \n " , res , GetLastError ( ) ) ;
2012-05-03 12:19:33 +02:00
code = 0xdeadbeef ;
size = sizeof ( code ) ;
2012-06-15 18:15:20 +02:00
res = HttpQueryInfoA ( req , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_REQUEST_HEADERS , & code , & size , NULL ) ;
2012-05-14 10:41:31 +02:00
ok_ ( __FILE__ , line ) ( ! res & & GetLastError ( ) = = ERROR_HTTP_INVALID_QUERY_REQUEST ,
2012-06-15 18:15:20 +02:00
" [8] HttpQueryInfoA failed: %x(%d) \n " , res , GetLastError ( ) ) ;
2012-05-03 12:19:33 +02:00
}
2012-05-24 15:24:55 +02:00
# define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
# define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
static void _test_request_flags ( unsigned line , HINTERNET req , DWORD exflags , BOOL is_todo )
{
DWORD flags , size ;
BOOL res ;
flags = 0xdeadbeef ;
size = sizeof ( flags ) ;
res = InternetQueryOptionW ( req , INTERNET_OPTION_REQUEST_FLAGS , & flags , & size ) ;
ok_ ( __FILE__ , line ) ( res , " InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u \n " , GetLastError ( ) ) ;
/* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
flags & = ~ INTERNET_REQFLAG_CACHE_WRITE_DISABLED ;
2016-02-15 23:14:40 +01:00
todo_wine_if ( is_todo )
2012-05-24 15:24:55 +02:00
ok_ ( __FILE__ , line ) ( flags = = exflags , " flags = %x, expected %x \n " , flags , exflags ) ;
}
2012-05-25 16:36:46 +02:00
# define test_http_version(a) _test_http_version(__LINE__,a)
static void _test_http_version ( unsigned line , HINTERNET req )
{
HTTP_VERSION_INFO v = { 0xdeadbeef , 0xdeadbeef } ;
DWORD size ;
BOOL res ;
size = sizeof ( v ) ;
res = InternetQueryOptionW ( req , INTERNET_OPTION_HTTP_VERSION , & v , & size ) ;
ok_ ( __FILE__ , line ) ( res , " InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u \n " , GetLastError ( ) ) ;
ok_ ( __FILE__ , line ) ( v . dwMajorVersion = = 1 , " dwMajorVersion = %d \n " , v . dwMajorVersion ) ;
ok_ ( __FILE__ , line ) ( v . dwMinorVersion = = 1 , " dwMinorVersion = %d \n " , v . dwMinorVersion ) ;
}
2011-05-13 13:48:50 +02:00
static int close_handle_cnt ;
2005-06-13 21:05:42 +02:00
static VOID WINAPI callback (
2002-06-22 01:59:49 +02:00
HINTERNET hInternet ,
2006-10-28 14:14:52 +02:00
DWORD_PTR dwContext ,
2002-06-22 01:59:49 +02:00
DWORD dwInternetStatus ,
LPVOID lpvStatusInformation ,
DWORD dwStatusInformationLength
)
{
2007-07-15 23:29:48 +02:00
CHECK_EXPECT ( dwInternetStatus ) ;
2002-06-22 01:59:49 +02:00
switch ( dwInternetStatus )
{
case INTERNET_STATUS_RESOLVING_NAME :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \" %s \" %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2007-03-05 13:06:47 +01:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_NAME_RESOLVED :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \" %s \" %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2007-03-05 13:06:47 +01:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CONNECTING_TO_SERVER :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \" %s \" %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2013-02-18 15:45:30 +01:00
ok ( dwStatusInformationLength = = strlen ( lpvStatusInformation ) + 1 , " unexpected size %u \n " ,
dwStatusInformationLength ) ;
2007-03-05 13:06:47 +01:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CONNECTED_TO_SERVER :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \" %s \" %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2013-02-18 15:45:30 +01:00
ok ( dwStatusInformationLength = = strlen ( lpvStatusInformation ) + 1 , " unexpected size %u \n " ,
dwStatusInformationLength ) ;
2007-03-05 13:06:47 +01:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_SENDING_REQUEST :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_REQUEST_SENT :
2005-11-22 12:59:16 +01:00
ok ( dwStatusInformationLength = = sizeof ( DWORD ) ,
2006-10-05 13:19:00 +02:00
" info length should be sizeof(DWORD) instead of %d \n " ,
2005-11-22 12:59:16 +01:00
dwStatusInformationLength ) ;
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( DWORD * ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_RECEIVING_RESPONSE :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_RESPONSE_RECEIVED :
2005-11-22 12:59:16 +01:00
ok ( dwStatusInformationLength = = sizeof ( DWORD ) ,
2006-10-05 13:19:00 +02:00
" info length should be sizeof(DWORD) instead of %d \n " ,
2005-11-22 12:59:16 +01:00
dwStatusInformationLength ) ;
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( DWORD * ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CTL_RESPONSE_RECEIVED :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_PREFETCH :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CLOSING_CONNECTION :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CONNECTION_CLOSED :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_HANDLE_CREATED :
2005-11-22 12:59:16 +01:00
ok ( dwStatusInformationLength = = sizeof ( HINTERNET ) ,
2006-10-05 13:19:00 +02:00
" info length should be sizeof(HINTERNET) instead of %d \n " ,
2005-11-22 12:59:16 +01:00
dwStatusInformationLength ) ;
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( HINTERNET * ) lpvStatusInformation , dwStatusInformationLength ) ;
2008-05-06 23:58:31 +02:00
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
SET_EXPECT ( INTERNET_STATUS_DETECTING_PROXY ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_HANDLE_CLOSING :
2005-11-22 12:59:16 +01:00
ok ( dwStatusInformationLength = = sizeof ( HINTERNET ) ,
2006-10-05 13:19:00 +02:00
" info length should be sizeof(HINTERNET) instead of %d \n " ,
2005-11-22 12:59:16 +01:00
dwStatusInformationLength ) ;
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( HINTERNET * ) lpvStatusInformation , dwStatusInformationLength ) ;
2013-03-08 15:59:36 +01:00
if ( ! InterlockedDecrement ( & close_handle_cnt ) )
2011-05-13 13:48:50 +02:00
SetEvent ( hCompleteEvent ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_REQUEST_COMPLETE :
2005-11-16 12:21:41 +01:00
{
INTERNET_ASYNC_RESULT * iar = ( INTERNET_ASYNC_RESULT * ) lpvStatusInformation ;
2005-11-22 12:59:16 +01:00
ok ( dwStatusInformationLength = = sizeof ( INTERNET_ASYNC_RESULT ) ,
2006-10-05 13:19:00 +02:00
" info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d \n " ,
2005-11-22 12:59:16 +01:00
dwStatusInformationLength ) ;
2011-06-10 14:47:16 +02:00
ok ( iar - > dwResult = = 1 | | iar - > dwResult = = 0 , " iar->dwResult = %ld \n " , iar - > dwResult ) ;
2007-08-30 16:21:33 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
iar - > dwResult , iar - > dwError , dwStatusInformationLength ) ;
2011-06-10 14:47:37 +02:00
req_error = iar - > dwError ;
2013-03-08 15:59:36 +01:00
if ( ! close_handle_cnt )
SetEvent ( hCompleteEvent ) ;
2002-06-22 01:59:49 +02:00
break ;
2005-11-16 12:21:41 +01:00
}
2002-06-22 01:59:49 +02:00
case INTERNET_STATUS_REDIRECT :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \" %s \" %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2007-03-05 13:06:47 +01:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2008-05-06 23:58:31 +02:00
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
SET_EXPECT ( INTERNET_STATUS_DETECTING_PROXY ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_INTERMEDIATE_RESPONSE :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
2005-11-16 12:21:41 +01:00
default :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx %d %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext , dwInternetStatus ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
}
}
2011-05-13 13:48:50 +02:00
static void close_async_handle ( HINTERNET handle , HANDLE complete_event , int handle_cnt )
{
BOOL res ;
close_handle_cnt = handle_cnt ;
SET_EXPECT2 ( INTERNET_STATUS_HANDLE_CLOSING , handle_cnt ) ;
res = InternetCloseHandle ( handle ) ;
ok ( res , " InternetCloseHandle failed: %u \n " , GetLastError ( ) ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_HANDLE_CLOSING , handle_cnt ) ;
}
2009-05-29 23:35:36 +02:00
static void InternetReadFile_test ( int flags , const test_data_t * test )
2002-06-22 01:59:49 +02:00
{
2011-01-13 13:54:23 +01:00
char * post_data = NULL ;
2011-04-02 15:20:53 +02:00
BOOL res , on_async = TRUE ;
2002-06-22 01:59:49 +02:00
CHAR buffer [ 4000 ] ;
2014-07-02 01:23:40 +02:00
WCHAR wbuffer [ 4000 ] ;
2014-06-25 03:34:17 +02:00
DWORD length , length2 , index , exlen = 0 , post_len = 0 ;
2002-12-07 00:21:35 +01:00
const char * types [ 2 ] = { " * " , NULL } ;
2002-12-17 22:03:33 +01:00
HINTERNET hi , hic = 0 , hor = 0 ;
2002-06-22 01:59:49 +02:00
2013-10-24 12:15:43 +02:00
hCompleteEvent = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
2005-11-16 12:21:41 +01:00
2009-05-29 23:35:36 +02:00
trace ( " Starting InternetReadFile test with flags 0x%x on url %s \n " , flags , test - > url ) ;
2002-06-22 01:59:49 +02:00
trace ( " InternetOpenA <-- \n " ) ;
2009-05-29 23:35:36 +02:00
hi = InternetOpenA ( ( test - > flags & TESTF_COMPRESSED ) ? " Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) " : " " ,
INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , flags ) ;
2007-01-06 19:25:07 +01:00
ok ( ( hi ! = 0x0 ) , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
2002-06-22 01:59:49 +02:00
trace ( " InternetOpenA --> \n " ) ;
2002-10-09 20:12:20 +02:00
if ( hi = = 0x0 ) goto abort ;
2007-02-20 15:53:49 +01:00
pInternetSetStatusCallbackA ( hi , & callback ) ;
2002-06-22 01:59:49 +02:00
2007-07-15 23:29:48 +02:00
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
2002-06-22 01:59:49 +02:00
trace ( " InternetConnectA <-- \n " ) ;
2009-05-29 23:35:36 +02:00
hic = InternetConnectA ( hi , test - > host , INTERNET_INVALID_PORT_NUMBER ,
2005-11-16 12:21:41 +01:00
NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
2007-01-06 19:25:07 +01:00
ok ( ( hic ! = 0x0 ) , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
2002-06-22 01:59:49 +02:00
trace ( " InternetConnectA --> \n " ) ;
2002-10-09 20:12:20 +02:00
if ( hic = = 0x0 ) goto abort ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
2002-06-22 01:59:49 +02:00
trace ( " HttpOpenRequestA <-- \n " ) ;
2011-01-13 13:54:23 +01:00
hor = HttpOpenRequestA ( hic , test - > post_data ? " POST " : " GET " , test - > path , NULL , NULL , types ,
2012-05-24 15:24:55 +02:00
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD ,
2005-11-16 12:21:41 +01:00
0xdeadbead ) ;
if ( hor = = 0x0 & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ) {
2002-10-09 20:12:20 +02:00
/*
* If the internet name can ' t be resolved we are probably behind
* a firewall or in some other way not directly connected to the
* Internet . Not enough reason to fail the test . Just ignore and
* abort .
*/
} else {
2007-01-06 19:25:07 +01:00
ok ( ( hor ! = 0x0 ) , " HttpOpenRequest failed with error %u \n " , GetLastError ( ) ) ;
2002-10-09 20:12:20 +02:00
}
2002-06-22 01:59:49 +02:00
trace ( " HttpOpenRequestA --> \n " ) ;
2002-10-09 20:12:20 +02:00
if ( hor = = 0x0 ) goto abort ;
2012-05-24 15:24:55 +02:00
test_request_flags ( hor , INTERNET_REQFLAG_NO_HEADERS ) ;
2008-02-13 13:33:42 +01:00
length = sizeof ( buffer ) ;
res = InternetQueryOptionA ( hor , INTERNET_OPTION_URL , buffer , & length ) ;
ok ( res , " InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u \n " , GetLastError ( ) ) ;
2009-05-29 23:35:36 +02:00
ok ( ! strcmp ( buffer , test - > url ) , " Wrong URL %s, expected %s \n " , buffer , test - > url ) ;
2008-02-13 13:33:42 +01:00
2008-10-07 16:39:50 +02:00
length = sizeof ( buffer ) ;
res = HttpQueryInfoA ( hor , HTTP_QUERY_RAW_HEADERS , buffer , & length , 0x0 ) ;
ok ( res , " HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d \n " , GetLastError ( ) ) ;
ok ( length = = 0 , " HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d \n " , length ) ;
ok ( ! strcmp ( buffer , " " ) , " HTTP_QUERY_RAW_HEADERS: expected string \" \" , but got \" %s \" \n " , buffer ) ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
2008-06-23 20:58:41 +02:00
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
2012-05-03 23:40:21 +02:00
SET_OPTIONAL2 ( INTERNET_STATUS_COOKIE_SENT , 2 ) ;
SET_OPTIONAL2 ( INTERNET_STATUS_COOKIE_RECEIVED , 2 ) ;
2007-07-15 23:29:48 +02:00
if ( first_connection_to_test_url )
{
SET_EXPECT ( INTERNET_STATUS_RESOLVING_NAME ) ;
SET_EXPECT ( INTERNET_STATUS_NAME_RESOLVED ) ;
}
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2009-05-29 23:35:36 +02:00
SET_EXPECT2 ( INTERNET_STATUS_SENDING_REQUEST , ( test - > flags & TESTF_REDIRECT ) ? 2 : 1 ) ;
SET_EXPECT2 ( INTERNET_STATUS_REQUEST_SENT , ( test - > flags & TESTF_REDIRECT ) ? 2 : 1 ) ;
SET_EXPECT2 ( INTERNET_STATUS_RECEIVING_RESPONSE , ( test - > flags & TESTF_REDIRECT ) ? 2 : 1 ) ;
SET_EXPECT2 ( INTERNET_STATUS_RESPONSE_RECEIVED , ( test - > flags & TESTF_REDIRECT ) ? 2 : 1 ) ;
if ( test - > flags & TESTF_REDIRECT ) {
SET_OPTIONAL2 ( INTERNET_STATUS_CLOSING_CONNECTION , 2 ) ;
SET_OPTIONAL2 ( INTERNET_STATUS_CONNECTION_CLOSED , 2 ) ;
}
2007-07-15 23:29:48 +02:00
SET_EXPECT ( INTERNET_STATUS_REDIRECT ) ;
2008-08-26 11:27:26 +02:00
SET_OPTIONAL ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_OPTIONAL ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2007-07-15 23:29:48 +02:00
if ( flags & INTERNET_FLAG_ASYNC )
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2009-05-29 23:35:36 +02:00
if ( test - > flags & TESTF_COMPRESSED ) {
BOOL b = TRUE ;
2013-10-24 12:15:43 +02:00
res = InternetSetOptionA ( hor , INTERNET_OPTION_HTTP_DECODING , & b , sizeof ( b ) ) ;
2009-06-02 01:20:20 +02:00
ok ( res | | broken ( ! res & & GetLastError ( ) = = ERROR_INTERNET_INVALID_OPTION ) ,
" InternetSetOption failed: %u \n " , GetLastError ( ) ) ;
if ( ! res )
goto abort ;
2009-05-29 23:35:36 +02:00
}
2012-05-03 12:20:25 +02:00
test_status_code ( hor , 0 ) ;
2002-06-22 01:59:49 +02:00
trace ( " HttpSendRequestA --> \n " ) ;
2011-01-13 13:54:23 +01:00
if ( test - > post_data ) {
post_len = strlen ( test - > post_data ) ;
post_data = HeapAlloc ( GetProcessHeap ( ) , 0 , post_len ) ;
memcpy ( post_data , test - > post_data , post_len ) ;
}
2005-11-16 12:21:41 +01:00
SetLastError ( 0xdeadbeef ) ;
2011-01-13 13:54:23 +01:00
res = HttpSendRequestA ( hor , test - > headers , - 1 , post_data , post_len ) ;
2005-11-16 12:21:41 +01:00
if ( flags & INTERNET_FLAG_ASYNC )
2008-10-07 16:39:46 +02:00
ok ( ! res & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ,
2005-11-16 12:21:41 +01:00
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
2002-06-22 01:59:49 +02:00
else
2008-10-07 16:39:46 +02:00
ok ( res | | ( GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ) ,
2007-01-06 19:25:07 +01:00
" Synchronous HttpSendRequest returning 0, error %u \n " , GetLastError ( ) ) ;
2002-06-22 01:59:49 +02:00
trace ( " HttpSendRequestA <-- \n " ) ;
2011-06-10 14:47:37 +02:00
if ( flags & INTERNET_FLAG_ASYNC ) {
2005-11-16 12:21:41 +01:00
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
2011-06-10 14:47:37 +02:00
ok ( req_error = = ERROR_SUCCESS , " req_error = %u \n " , req_error ) ;
}
2011-01-13 13:54:23 +01:00
HeapFree ( GetProcessHeap ( ) , 0 , post_data ) ;
2002-06-22 01:59:49 +02:00
2012-05-03 10:11:12 +02:00
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_RECEIVED ) ;
2009-03-25 11:55:17 +01:00
if ( first_connection_to_test_url )
2007-07-15 23:29:48 +02:00
{
2011-01-21 13:35:40 +01:00
if ( ! proxy_active ( ) )
{
CHECK_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
}
else
{
CLEAR_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
}
2007-07-15 23:29:48 +02:00
}
2011-05-10 11:26:43 +02:00
else
2007-07-15 23:29:48 +02:00
{
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
}
2009-05-29 23:35:36 +02:00
CHECK_NOTIFIED2 ( INTERNET_STATUS_SENDING_REQUEST , ( test - > flags & TESTF_REDIRECT ) ? 2 : 1 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_REQUEST_SENT , ( test - > flags & TESTF_REDIRECT ) ? 2 : 1 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_RECEIVING_RESPONSE , ( test - > flags & TESTF_REDIRECT ) ? 2 : 1 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_RESPONSE_RECEIVED , ( test - > flags & TESTF_REDIRECT ) ? 2 : 1 ) ;
if ( test - > flags & TESTF_REDIRECT )
CHECK_NOTIFIED ( INTERNET_STATUS_REDIRECT ) ;
2007-07-15 23:29:48 +02:00
if ( flags & INTERNET_FLAG_ASYNC )
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
/* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2012-05-24 15:24:55 +02:00
test_request_flags ( hor , 0 ) ;
2002-06-22 01:59:49 +02:00
length = 100 ;
2008-10-07 16:39:46 +02:00
res = InternetQueryOptionA ( hor , INTERNET_OPTION_URL , buffer , & length ) ;
ok ( res , " InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d \n " , GetLastError ( ) ) ;
2002-06-22 01:59:49 +02:00
2013-05-26 14:40:12 +02:00
length = sizeof ( buffer ) - 1 ;
2014-06-25 03:34:17 +02:00
memset ( buffer , 0x77 , sizeof ( buffer ) ) ;
2008-10-07 16:39:46 +02:00
res = HttpQueryInfoA ( hor , HTTP_QUERY_RAW_HEADERS , buffer , & length , 0x0 ) ;
ok ( res , " HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d \n " , GetLastError ( ) ) ;
2014-06-25 03:34:17 +02:00
/* show that the function writes data past the length returned */
ok ( buffer [ length - 2 ] , " Expected any header character, got 0x00 \n " ) ;
ok ( ! buffer [ length - 1 ] , " Expected 0x00, got %02X \n " , buffer [ length - 1 ] ) ;
ok ( ! buffer [ length ] , " Expected 0x00, got %02X \n " , buffer [ length ] ) ;
ok ( buffer [ length + 1 ] = = 0x77 , " Expected 0x77, got %02X \n " , buffer [ length + 1 ] ) ;
length2 = length ;
res = HttpQueryInfoA ( hor , HTTP_QUERY_RAW_HEADERS , buffer , & length2 , 0x0 ) ;
ok ( ! res , " Expected 0x00, got %d \n " , res ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " Unexpected last error: %d \n " , GetLastError ( ) ) ;
ok ( length2 = = length + 1 , " Expected %d, got %d \n " , length + 1 , length2 ) ;
/* the in length of the buffer must be +1 but the length returned does not count this */
length2 = length + 1 ;
memset ( buffer , 0x77 , sizeof ( buffer ) ) ;
res = HttpQueryInfoA ( hor , HTTP_QUERY_RAW_HEADERS , buffer , & length2 , 0x0 ) ;
ok ( res , " HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d \n " , GetLastError ( ) ) ;
ok ( buffer [ length2 ] = = 0x00 , " Expected 0x00, got %02X \n " , buffer [ length2 ] ) ;
ok ( buffer [ length2 + 1 ] = = 0x77 , " Expected 0x77, got %02X \n " , buffer [ length2 + 1 ] ) ;
ok ( length2 = = length , " Value should not have changed: %d != %d \n " , length2 , length ) ;
2002-06-22 01:59:49 +02:00
2014-07-02 01:23:40 +02:00
length = sizeof ( wbuffer ) - sizeof ( WCHAR ) ;
memset ( wbuffer , 0x77 , sizeof ( wbuffer ) ) ;
res = HttpQueryInfoW ( hor , HTTP_QUERY_RAW_HEADERS , wbuffer , & length , 0x0 ) ;
ok ( res , " HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d \n " , GetLastError ( ) ) ;
ok ( length % sizeof ( WCHAR ) = = 0 , " Expected that length is a multiple of sizeof(WCHAR), got %d. \n " , length ) ;
length / = sizeof ( WCHAR ) ;
/* show that the function writes data past the length returned */
ok ( wbuffer [ length - 2 ] , " Expected any header character, got 0x0000 \n " ) ;
ok ( ! wbuffer [ length - 1 ] , " Expected 0x0000, got %04X \n " , wbuffer [ length - 1 ] ) ;
ok ( ! wbuffer [ length ] , " Expected 0x0000, got %04X \n " , wbuffer [ length ] ) ;
ok ( wbuffer [ length + 1 ] = = 0x7777 | | broken ( wbuffer [ length + 1 ] ! = 0x7777 ) ,
" Expected 0x7777, got %04X \n " , wbuffer [ length + 1 ] ) ;
length2 = length * sizeof ( WCHAR ) ;
res = HttpQueryInfoW ( hor , HTTP_QUERY_RAW_HEADERS , wbuffer , & length2 , 0x0 ) ;
ok ( ! res , " Expected 0x00, got %d \n " , res ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " Unexpected last error: %d \n " , GetLastError ( ) ) ;
ok ( length2 % sizeof ( WCHAR ) = = 0 , " Expected that length is a multiple of sizeof(WCHAR), got %d. \n " , length2 ) ;
length2 / = sizeof ( WCHAR ) ;
ok ( length2 = = length + 1 , " Expected %d, got %d \n " , length + 1 , length2 ) ;
/* the in length of the buffer must be +1 but the length returned does not count this */
length2 = ( length + 1 ) * sizeof ( WCHAR ) ;
memset ( wbuffer , 0x77 , sizeof ( wbuffer ) ) ;
res = HttpQueryInfoW ( hor , HTTP_QUERY_RAW_HEADERS , wbuffer , & length2 , 0x0 ) ;
ok ( res , " HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d \n " , GetLastError ( ) ) ;
ok ( length2 % sizeof ( WCHAR ) = = 0 , " Expected that length is a multiple of sizeof(WCHAR), got %d. \n " , length2 ) ;
length2 / = sizeof ( WCHAR ) ;
ok ( ! wbuffer [ length2 ] , " Expected 0x0000, got %04X \n " , wbuffer [ length2 ] ) ;
ok ( wbuffer [ length2 + 1 ] = = 0x7777 , " Expected 0x7777, got %04X \n " , wbuffer [ length2 + 1 ] ) ;
ok ( length2 = = length , " Value should not have changed: %d != %d \n " , length2 , length ) ;
2008-02-13 13:33:42 +01:00
length = sizeof ( buffer ) ;
res = InternetQueryOptionA ( hor , INTERNET_OPTION_URL , buffer , & length ) ;
ok ( res , " InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u \n " , GetLastError ( ) ) ;
2009-05-29 23:35:36 +02:00
ok ( ! strcmp ( buffer , test - > redirected_url ) , " Wrong URL %s \n " , buffer ) ;
2002-06-22 01:59:49 +02:00
2014-06-17 02:57:10 +02:00
index = 0 ;
length = 0 ;
SetLastError ( 0xdeadbeef ) ;
ok ( HttpQueryInfoA ( hor , HTTP_QUERY_CONTENT_LENGTH , NULL , & length , & index ) = = FALSE , " Query worked \n " ) ;
if ( test - > flags & TESTF_COMPRESSED )
ok ( GetLastError ( ) = = ERROR_HTTP_HEADER_NOT_FOUND ,
" expected ERROR_HTTP_HEADER_NOT_FOUND, got %u \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
index = 0 ;
2002-06-22 01:59:49 +02:00
length = 16 ;
2014-06-17 02:57:10 +02:00
res = HttpQueryInfoA ( hor , HTTP_QUERY_CONTENT_LENGTH , & buffer , & length , & index ) ;
2009-05-29 23:35:36 +02:00
trace ( " Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u) \n " , res , buffer , GetLastError ( ) ) ;
if ( test - > flags & TESTF_COMPRESSED )
ok ( ! res & & GetLastError ( ) = = ERROR_HTTP_HEADER_NOT_FOUND ,
" expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u) \n " , res , GetLastError ( ) ) ;
2014-06-17 02:57:10 +02:00
ok ( ! res | | index = = 1 , " Index was not incremented although result is %x (index = %u) \n " , res , index ) ;
2002-06-22 01:59:49 +02:00
length = 100 ;
2008-10-07 16:39:46 +02:00
res = HttpQueryInfoA ( hor , HTTP_QUERY_CONTENT_TYPE , buffer , & length , 0x0 ) ;
2002-06-22 01:59:49 +02:00
buffer [ length ] = 0 ;
2009-05-29 23:35:36 +02:00
trace ( " Option HTTP_QUERY_CONTENT_TYPE -> %i %s \n " , res , buffer ) ;
length = 100 ;
res = HttpQueryInfoA ( hor , HTTP_QUERY_CONTENT_ENCODING , buffer , & length , 0x0 ) ;
buffer [ length ] = 0 ;
trace ( " Option HTTP_QUERY_CONTENT_ENCODING -> %i %s \n " , res , buffer ) ;
2002-06-22 01:59:49 +02:00
2005-11-16 12:21:41 +01:00
SetLastError ( 0xdeadbeef ) ;
2008-10-07 16:39:46 +02:00
res = InternetReadFile ( NULL , buffer , 100 , & length ) ;
ok ( ! res , " InternetReadFile should have failed \n " ) ;
2005-11-16 12:21:41 +01:00
ok ( GetLastError ( ) = = ERROR_INVALID_HANDLE ,
2007-01-06 19:25:07 +01:00
" InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u \n " ,
2005-11-16 12:21:41 +01:00
GetLastError ( ) ) ;
2002-06-22 01:59:49 +02:00
length = 100 ;
2004-01-23 23:44:26 +01:00
trace ( " Entering Query loop \n " ) ;
2002-06-22 01:59:49 +02:00
2007-07-15 23:29:46 +02:00
while ( TRUE )
2002-06-22 01:59:49 +02:00
{
2007-07-15 23:29:48 +02:00
if ( flags & INTERNET_FLAG_ASYNC )
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2014-09-02 12:37:37 +02:00
/* IE11 calls those in InternetQueryDataAvailable call. */
SET_OPTIONAL ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_OPTIONAL ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
2013-02-14 18:05:14 +01:00
length = 0 ;
2008-10-07 16:39:46 +02:00
res = InternetQueryDataAvailable ( hor , & length , 0x0 , 0x0 ) ;
2014-09-02 12:37:37 +02:00
CLEAR_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
2007-07-15 23:29:46 +02:00
if ( flags & INTERNET_FLAG_ASYNC )
{
2008-10-07 16:39:46 +02:00
if ( res )
2007-07-15 23:29:48 +02:00
{
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2013-02-14 18:05:14 +01:00
if ( exlen ) {
ok ( length > = exlen , " length %u < exlen %u \n " , length , exlen ) ;
exlen = 0 ;
}
2007-07-15 23:29:48 +02:00
}
else if ( GetLastError ( ) = = ERROR_IO_PENDING )
2007-07-15 23:29:46 +02:00
{
2011-04-02 15:20:53 +02:00
trace ( " PENDING \n " ) ;
/* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
if ( ! ( test - > flags & TESTF_CHUNKED ) )
ok ( ! length , " InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length \n " , length ) ;
2007-07-15 23:29:46 +02:00
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
2013-02-14 18:05:14 +01:00
exlen = length ;
ok ( exlen , " length = 0 \n " ) ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2014-09-02 12:37:37 +02:00
CLEAR_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
2011-06-10 14:47:37 +02:00
ok ( req_error , " req_error = 0 \n " ) ;
2007-07-15 23:29:46 +02:00
continue ;
2011-04-02 15:20:53 +02:00
} else {
ok ( 0 , " InternetQueryDataAvailable failed: %u \n " , GetLastError ( ) ) ;
2007-07-15 23:29:46 +02:00
}
2011-04-02 15:20:53 +02:00
} else {
ok ( res , " InternetQueryDataAvailable failed: %u \n " , GetLastError ( ) ) ;
2007-07-15 23:29:46 +02:00
}
2014-09-02 12:37:37 +02:00
CLEAR_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
2011-04-02 15:20:53 +02:00
trace ( " LENGTH %d \n " , length ) ;
if ( test - > flags & TESTF_CHUNKED )
ok ( length < = 8192 , " length = %d, expected <= 8192 \n " , length ) ;
2002-06-22 01:59:49 +02:00
if ( length )
{
char * buffer ;
2005-03-22 19:26:06 +01:00
buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , length + 1 ) ;
2002-06-22 01:59:49 +02:00
2008-10-07 16:39:46 +02:00
res = InternetReadFile ( hor , buffer , length , & length ) ;
2002-06-22 01:59:49 +02:00
buffer [ length ] = 0 ;
2008-10-07 16:39:46 +02:00
trace ( " ReadFile -> %s %i \n " , res ? " TRUE " : " FALSE " , length ) ;
2002-06-22 01:59:49 +02:00
2011-01-13 13:54:23 +01:00
if ( test - > content )
ok ( ! strcmp ( buffer , test - > content ) , " buffer = '%s', expected '%s' \n " , buffer , test - > content ) ;
2002-06-22 01:59:49 +02:00
HeapFree ( GetProcessHeap ( ) , 0 , buffer ) ;
2011-04-02 15:20:53 +02:00
} else {
ok ( ! on_async , " Returned zero size in response to request complete \n " ) ;
2007-07-15 23:29:46 +02:00
break ;
2011-04-02 15:20:53 +02:00
}
on_async = FALSE ;
2002-06-22 01:59:49 +02:00
}
2009-05-29 23:35:36 +02:00
if ( test - > flags & TESTF_REDIRECT ) {
CHECK_NOTIFIED2 ( INTERNET_STATUS_CLOSING_CONNECTION , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_CONNECTION_CLOSED , 2 ) ;
}
2002-10-09 20:12:20 +02:00
abort :
2008-12-10 10:47:13 +01:00
trace ( " aborting \n " ) ;
2011-05-13 13:48:50 +02:00
close_async_handle ( hi , hCompleteEvent , 2 ) ;
2005-11-16 12:21:41 +01:00
CloseHandle ( hCompleteEvent ) ;
2007-07-15 23:29:48 +02:00
first_connection_to_test_url = FALSE ;
2005-11-16 12:21:41 +01:00
}
2009-05-14 16:49:19 +02:00
static void InternetReadFile_chunked_test ( void )
{
BOOL res ;
CHAR buffer [ 4000 ] ;
2013-11-21 17:52:54 +01:00
DWORD length , got ;
2009-05-14 16:49:19 +02:00
const char * types [ 2 ] = { " * " , NULL } ;
HINTERNET hi , hic = 0 , hor = 0 ;
trace ( " Starting InternetReadFile chunked test \n " ) ;
trace ( " InternetOpenA <-- \n " ) ;
hi = InternetOpenA ( " " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , 0 ) ;
ok ( ( hi ! = 0x0 ) , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
trace ( " InternetOpenA --> \n " ) ;
if ( hi = = 0x0 ) goto abort ;
trace ( " InternetConnectA <-- \n " ) ;
hic = InternetConnectA ( hi , " test.winehq.org " , INTERNET_INVALID_PORT_NUMBER ,
NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
ok ( ( hic ! = 0x0 ) , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
trace ( " InternetConnectA --> \n " ) ;
if ( hic = = 0x0 ) goto abort ;
trace ( " HttpOpenRequestA <-- \n " ) ;
2011-03-14 16:43:19 +01:00
hor = HttpOpenRequestA ( hic , " GET " , " /tests/chunked " , NULL , NULL , types ,
2012-05-24 15:24:55 +02:00
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD ,
2009-05-14 16:49:19 +02:00
0xdeadbead ) ;
if ( hor = = 0x0 & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ) {
/*
* If the internet name can ' t be resolved we are probably behind
* a firewall or in some other way not directly connected to the
* Internet . Not enough reason to fail the test . Just ignore and
* abort .
*/
} else {
ok ( ( hor ! = 0x0 ) , " HttpOpenRequest failed with error %u \n " , GetLastError ( ) ) ;
}
trace ( " HttpOpenRequestA --> \n " ) ;
if ( hor = = 0x0 ) goto abort ;
trace ( " HttpSendRequestA --> \n " ) ;
SetLastError ( 0xdeadbeef ) ;
res = HttpSendRequestA ( hor , " " , - 1 , NULL , 0 ) ;
ok ( res | | ( GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ) ,
" Synchronous HttpSendRequest returning 0, error %u \n " , GetLastError ( ) ) ;
trace ( " HttpSendRequestA <-- \n " ) ;
2012-05-24 15:24:55 +02:00
test_request_flags ( hor , 0 ) ;
2009-05-14 16:49:19 +02:00
length = 100 ;
res = HttpQueryInfoA ( hor , HTTP_QUERY_CONTENT_TYPE , buffer , & length , 0x0 ) ;
buffer [ length ] = 0 ;
trace ( " Option CONTENT_TYPE -> %i %s \n " , res , buffer ) ;
SetLastError ( 0xdeadbeef ) ;
length = 100 ;
res = HttpQueryInfoA ( hor , HTTP_QUERY_TRANSFER_ENCODING , buffer , & length , 0x0 ) ;
buffer [ length ] = 0 ;
trace ( " Option TRANSFER_ENCODING -> %i %s \n " , res , buffer ) ;
2011-01-21 13:35:40 +01:00
ok ( res | | ( proxy_active ( ) & & GetLastError ( ) = = ERROR_HTTP_HEADER_NOT_FOUND ) ,
" Failed to get TRANSFER_ENCODING option, error %u \n " , GetLastError ( ) ) ;
ok ( ! strcmp ( buffer , " chunked " ) | | ( ! res & & proxy_active ( ) & & GetLastError ( ) = = ERROR_HTTP_HEADER_NOT_FOUND ) ,
" Wrong transfer encoding '%s' \n " , buffer ) ;
2009-05-14 16:49:19 +02:00
SetLastError ( 0xdeadbeef ) ;
length = 16 ;
res = HttpQueryInfoA ( hor , HTTP_QUERY_CONTENT_LENGTH , & buffer , & length , 0x0 ) ;
ok ( ! res , " Found CONTENT_LENGTH option '%s' \n " , buffer ) ;
ok ( GetLastError ( ) = = ERROR_HTTP_HEADER_NOT_FOUND , " Wrong error %u \n " , GetLastError ( ) ) ;
length = 100 ;
trace ( " Entering Query loop \n " ) ;
while ( TRUE )
{
res = InternetQueryDataAvailable ( hor , & length , 0x0 , 0x0 ) ;
ok ( ! ( ! res & & length ! = 0 ) , " InternetQueryDataAvailable failed with non-zero length \n " ) ;
ok ( res , " InternetQueryDataAvailable failed, error %d \n " , GetLastError ( ) ) ;
trace ( " got %u available \n " , length ) ;
if ( length )
{
char * buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , length + 1 ) ;
res = InternetReadFile ( hor , buffer , length , & got ) ;
buffer [ got ] = 0 ;
trace ( " ReadFile -> %i %i \n " , res , got ) ;
ok ( length = = got , " only got %u of %u available \n " , got , length ) ;
ok ( buffer [ got - 1 ] = = ' \n ' , " received partial line '%s' \n " , buffer ) ;
HeapFree ( GetProcessHeap ( ) , 0 , buffer ) ;
if ( ! got ) break ;
}
if ( length = = 0 )
2013-11-21 17:52:54 +01:00
{
got = 0xdeadbeef ;
res = InternetReadFile ( hor , buffer , 1 , & got ) ;
ok ( res , " InternetReadFile failed: %u \n " , GetLastError ( ) ) ;
ok ( ! got , " got %u \n " , got ) ;
2009-05-14 16:49:19 +02:00
break ;
2013-11-21 17:52:54 +01:00
}
2009-05-14 16:49:19 +02:00
}
abort :
trace ( " aborting \n " ) ;
if ( hor ! = 0x0 ) {
res = InternetCloseHandle ( hor ) ;
ok ( res , " InternetCloseHandle of handle opened by HttpOpenRequestA failed \n " ) ;
}
if ( hi ! = 0x0 ) {
res = InternetCloseHandle ( hi ) ;
ok ( res , " InternetCloseHandle of handle opened by InternetOpenA failed \n " ) ;
}
}
2005-11-16 12:21:41 +01:00
static void InternetReadFileExA_test ( int flags )
{
DWORD rc ;
DWORD length ;
const char * types [ 2 ] = { " * " , NULL } ;
HINTERNET hi , hic = 0 , hor = 0 ;
2013-10-24 12:15:43 +02:00
INTERNET_BUFFERSA inetbuffers ;
2005-11-16 12:21:41 +01:00
2013-10-24 12:15:43 +02:00
hCompleteEvent = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
2005-11-16 12:21:41 +01:00
trace ( " Starting InternetReadFileExA test with flags 0x%x \n " , flags ) ;
trace ( " InternetOpenA <-- \n " ) ;
hi = InternetOpenA ( " " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , flags ) ;
2007-01-06 19:25:07 +01:00
ok ( ( hi ! = 0x0 ) , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
2005-11-16 12:21:41 +01:00
trace ( " InternetOpenA --> \n " ) ;
if ( hi = = 0x0 ) goto abort ;
2007-02-20 15:53:49 +01:00
pInternetSetStatusCallbackA ( hi , & callback ) ;
2005-11-16 12:21:41 +01:00
2007-07-15 23:29:48 +02:00
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
2005-11-16 12:21:41 +01:00
trace ( " InternetConnectA <-- \n " ) ;
2008-12-10 10:47:13 +01:00
hic = InternetConnectA ( hi , " test.winehq.org " , INTERNET_INVALID_PORT_NUMBER ,
2005-11-16 12:21:41 +01:00
NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
2007-01-06 19:25:07 +01:00
ok ( ( hic ! = 0x0 ) , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
2005-11-16 12:21:41 +01:00
trace ( " InternetConnectA --> \n " ) ;
if ( hic = = 0x0 ) goto abort ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
2005-11-16 12:21:41 +01:00
trace ( " HttpOpenRequestA <-- \n " ) ;
2011-03-14 16:43:19 +01:00
hor = HttpOpenRequestA ( hic , " GET " , " /tests/redirect " , NULL , NULL , types ,
2012-05-24 15:24:55 +02:00
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD ,
2005-11-16 12:21:41 +01:00
0xdeadbead ) ;
if ( hor = = 0x0 & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ) {
/*
* If the internet name can ' t be resolved we are probably behind
* a firewall or in some other way not directly connected to the
* Internet . Not enough reason to fail the test . Just ignore and
* abort .
*/
} else {
2007-01-06 19:25:07 +01:00
ok ( ( hor ! = 0x0 ) , " HttpOpenRequest failed with error %u \n " , GetLastError ( ) ) ;
2005-11-16 12:21:41 +01:00
}
trace ( " HttpOpenRequestA --> \n " ) ;
if ( hor = = 0x0 ) goto abort ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
2008-06-23 20:58:41 +02:00
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
2007-07-15 23:29:48 +02:00
if ( first_connection_to_test_url )
{
SET_EXPECT ( INTERNET_STATUS_RESOLVING_NAME ) ;
SET_EXPECT ( INTERNET_STATUS_NAME_RESOLVED ) ;
}
2012-05-03 10:11:12 +02:00
SET_OPTIONAL2 ( INTERNET_STATUS_COOKIE_SENT , 2 ) ;
2007-07-15 23:29:48 +02:00
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT2 ( INTERNET_STATUS_SENDING_REQUEST , 2 ) ;
SET_EXPECT2 ( INTERNET_STATUS_REQUEST_SENT , 2 ) ;
SET_EXPECT2 ( INTERNET_STATUS_RECEIVING_RESPONSE , 2 ) ;
SET_EXPECT2 ( INTERNET_STATUS_RESPONSE_RECEIVED , 2 ) ;
2009-03-25 22:57:32 +01:00
SET_OPTIONAL2 ( INTERNET_STATUS_CLOSING_CONNECTION , 2 ) ;
SET_OPTIONAL2 ( INTERNET_STATUS_CONNECTION_CLOSED , 2 ) ;
2007-07-15 23:29:48 +02:00
SET_EXPECT ( INTERNET_STATUS_REDIRECT ) ;
2008-08-26 20:40:28 +02:00
SET_OPTIONAL ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_OPTIONAL ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2007-07-15 23:29:48 +02:00
if ( flags & INTERNET_FLAG_ASYNC )
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
else
SET_WINE_ALLOW ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2005-11-16 12:21:41 +01:00
trace ( " HttpSendRequestA --> \n " ) ;
SetLastError ( 0xdeadbeef ) ;
rc = HttpSendRequestA ( hor , " " , - 1 , NULL , 0 ) ;
if ( flags & INTERNET_FLAG_ASYNC )
ok ( ( ( rc = = 0 ) & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
else
ok ( ( rc ! = 0 ) | | GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ,
2007-01-06 19:25:07 +01:00
" Synchronous HttpSendRequest returning 0, error %u \n " , GetLastError ( ) ) ;
2005-11-16 12:21:41 +01:00
trace ( " HttpSendRequestA <-- \n " ) ;
2011-06-10 14:47:37 +02:00
if ( ! rc & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ) {
2005-11-16 12:21:41 +01:00
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
2011-06-10 14:47:37 +02:00
ok ( req_error = = ERROR_SUCCESS , " req_error = %u \n " , req_error ) ;
}
2005-11-16 12:21:41 +01:00
2007-07-15 23:29:48 +02:00
if ( first_connection_to_test_url )
{
CHECK_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
}
2011-05-10 11:26:43 +02:00
else
2007-07-15 23:29:48 +02:00
{
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
}
CHECK_NOTIFIED2 ( INTERNET_STATUS_SENDING_REQUEST , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_REQUEST_SENT , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_RECEIVING_RESPONSE , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_RESPONSE_RECEIVED , 2 ) ;
2009-03-25 22:57:32 +01:00
CHECK_NOTIFIED2 ( INTERNET_STATUS_CLOSING_CONNECTION , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_CONNECTION_CLOSED , 2 ) ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_REDIRECT ) ;
if ( flags & INTERNET_FLAG_ASYNC )
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
else
todo_wine CHECK_NOT_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2012-05-02 13:01:34 +02:00
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
2007-07-15 23:29:48 +02:00
/* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2005-11-16 12:21:41 +01:00
/* tests invalid dwStructSize */
2013-10-24 12:15:43 +02:00
inetbuffers . dwStructSize = sizeof ( inetbuffers ) + 1 ;
2005-11-16 12:21:41 +01:00
inetbuffers . lpcszHeader = NULL ;
inetbuffers . dwHeadersLength = 0 ;
inetbuffers . dwBufferLength = 10 ;
inetbuffers . lpvBuffer = HeapAlloc ( GetProcessHeap ( ) , 0 , 10 ) ;
inetbuffers . dwOffsetHigh = 1234 ;
inetbuffers . dwOffsetLow = 5678 ;
2013-10-24 12:15:43 +02:00
rc = InternetReadFileExA ( hor , & inetbuffers , 0 , 0xdeadcafe ) ;
2005-11-16 12:21:41 +01:00
ok ( ! rc & & ( GetLastError ( ) = = ERROR_INVALID_PARAMETER ) ,
2007-01-06 19:25:07 +01:00
" InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u \n " ,
2005-11-16 12:21:41 +01:00
rc ? " TRUE " : " FALSE " , GetLastError ( ) ) ;
HeapFree ( GetProcessHeap ( ) , 0 , inetbuffers . lpvBuffer ) ;
2012-05-24 15:24:55 +02:00
test_request_flags ( hor , 0 ) ;
2005-11-16 12:21:41 +01:00
/* tests to see whether lpcszHeader is used - it isn't */
2013-10-24 12:15:43 +02:00
inetbuffers . dwStructSize = sizeof ( inetbuffers ) ;
inetbuffers . lpcszHeader = ( LPCSTR ) 0xdeadbeef ;
2005-11-16 12:21:41 +01:00
inetbuffers . dwHeadersLength = 255 ;
inetbuffers . dwBufferLength = 0 ;
inetbuffers . lpvBuffer = NULL ;
inetbuffers . dwOffsetHigh = 1234 ;
inetbuffers . dwOffsetLow = 5678 ;
2008-12-11 15:24:12 +01:00
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
2013-10-24 12:15:43 +02:00
rc = InternetReadFileExA ( hor , & inetbuffers , 0 , 0xdeadcafe ) ;
2007-01-06 19:25:07 +01:00
ok ( rc , " InternetReadFileEx failed with error %u \n " , GetLastError ( ) ) ;
2012-05-03 10:11:12 +02:00
trace ( " read %i bytes \n " , inetbuffers . dwBufferLength ) ;
2007-07-15 23:29:48 +02:00
todo_wine
{
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
}
2005-11-16 12:21:41 +01:00
2013-10-24 12:15:43 +02:00
rc = InternetReadFileExA ( NULL , & inetbuffers , 0 , 0xdeadcafe ) ;
2005-11-16 12:21:41 +01:00
ok ( ! rc & & ( GetLastError ( ) = = ERROR_INVALID_HANDLE ) ,
2007-01-06 19:25:07 +01:00
" InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u \n " ,
2005-11-16 12:21:41 +01:00
rc ? " TRUE " : " FALSE " , GetLastError ( ) ) ;
length = 0 ;
trace ( " Entering Query loop \n " ) ;
while ( TRUE )
{
2013-10-24 12:15:43 +02:00
inetbuffers . dwStructSize = sizeof ( inetbuffers ) ;
2005-11-16 12:21:41 +01:00
inetbuffers . dwBufferLength = 1024 ;
inetbuffers . lpvBuffer = HeapAlloc ( GetProcessHeap ( ) , 0 , inetbuffers . dwBufferLength + 1 ) ;
inetbuffers . dwOffsetHigh = 1234 ;
inetbuffers . dwOffsetLow = 5678 ;
2008-12-11 15:24:12 +01:00
SET_WINE_ALLOW ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
2007-07-15 23:29:48 +02:00
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2005-11-16 12:21:41 +01:00
rc = InternetReadFileExA ( hor , & inetbuffers , IRF_ASYNC | IRF_USE_CONTEXT , 0xcafebabe ) ;
if ( ! rc )
{
if ( GetLastError ( ) = = ERROR_IO_PENDING )
{
trace ( " InternetReadFileEx -> PENDING \n " ) ;
2008-03-27 21:52:24 +01:00
ok ( flags & INTERNET_FLAG_ASYNC ,
" Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC \n " ) ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
2005-11-16 12:21:41 +01:00
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2016-04-28 05:12:49 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
2011-06-10 14:47:37 +02:00
ok ( req_error = = ERROR_SUCCESS , " req_error = %u \n " , req_error ) ;
2005-11-16 12:21:41 +01:00
}
else
{
2007-01-06 19:25:07 +01:00
trace ( " InternetReadFileEx -> FAILED %u \n " , GetLastError ( ) ) ;
2005-11-16 12:21:41 +01:00
break ;
}
}
else
2007-06-05 20:45:26 +02:00
{
2005-11-16 12:21:41 +01:00
trace ( " InternetReadFileEx -> SUCCEEDED \n " ) ;
2007-07-15 23:29:48 +02:00
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
if ( inetbuffers . dwBufferLength )
{
2008-12-11 15:24:12 +01:00
todo_wine {
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
}
2007-07-15 23:29:48 +02:00
}
else
{
/* Win98 still sends these when 0 bytes are read, WinXP does not */
CLEAR_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
}
2007-06-05 20:45:26 +02:00
}
2005-11-16 12:21:41 +01:00
2006-10-05 13:19:00 +02:00
trace ( " read %i bytes \n " , inetbuffers . dwBufferLength ) ;
2005-11-16 12:21:41 +01:00
( ( char * ) inetbuffers . lpvBuffer ) [ inetbuffers . dwBufferLength ] = ' \0 ' ;
ok ( inetbuffers . dwOffsetHigh = = 1234 & & inetbuffers . dwOffsetLow = = 5678 ,
2006-10-05 13:19:00 +02:00
" InternetReadFileEx sets offsets to 0x%x%08x \n " ,
2005-11-16 12:21:41 +01:00
inetbuffers . dwOffsetHigh , inetbuffers . dwOffsetLow ) ;
HeapFree ( GetProcessHeap ( ) , 0 , inetbuffers . lpvBuffer ) ;
if ( ! inetbuffers . dwBufferLength )
break ;
length + = inetbuffers . dwBufferLength ;
}
2008-12-10 10:47:13 +01:00
ok ( length > 0 , " failed to read any of the document \n " ) ;
2006-10-05 13:19:00 +02:00
trace ( " Finished. Read %d bytes \n " , length ) ;
2005-11-16 12:21:41 +01:00
abort :
2011-05-13 13:48:50 +02:00
close_async_handle ( hi , hCompleteEvent , 2 ) ;
2005-11-16 12:21:41 +01:00
CloseHandle ( hCompleteEvent ) ;
2007-07-15 23:29:48 +02:00
first_connection_to_test_url = FALSE ;
2002-06-22 01:59:49 +02:00
}
2005-06-13 21:05:42 +02:00
static void InternetOpenUrlA_test ( void )
2003-02-25 04:57:59 +01:00
{
HINTERNET myhinternet , myhttp ;
char buffer [ 0x400 ] ;
DWORD size , readbytes , totalbytes = 0 ;
2004-12-27 18:26:37 +01:00
BOOL ret ;
2009-04-20 21:56:59 +02:00
2013-10-24 12:15:43 +02:00
ret = DeleteUrlCacheEntryA ( TEST_URL ) ;
2013-03-13 17:05:51 +01:00
ok ( ret | | GetLastError ( ) = = ERROR_FILE_NOT_FOUND ,
" DeleteUrlCacheEntry returned %x, GetLastError() = %d \n " , ret , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
myhinternet = InternetOpenA ( " Winetest " , 0 , NULL , NULL , INTERNET_FLAG_NO_CACHE_WRITE ) ;
2007-01-06 19:25:07 +01:00
ok ( ( myhinternet ! = 0 ) , " InternetOpen failed, error %u \n " , GetLastError ( ) ) ;
2003-02-25 04:57:59 +01:00
size = 0x400 ;
2013-10-24 12:15:43 +02:00
ret = InternetCanonicalizeUrlA ( TEST_URL , buffer , & size , ICU_BROWSER_MODE ) ;
2007-01-06 19:25:07 +01:00
ok ( ret , " InternetCanonicalizeUrl failed, error %u \n " , GetLastError ( ) ) ;
2006-03-14 18:49:19 +01:00
2003-09-25 22:29:40 +02:00
SetLastError ( 0 ) ;
2013-10-24 12:15:43 +02:00
myhttp = InternetOpenUrlA ( myhinternet , TEST_URL , 0 , 0 ,
2003-02-25 04:57:59 +01:00
INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_TRANSFER_BINARY , 0 ) ;
2007-11-11 13:35:06 +01:00
if ( GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
2003-09-25 22:29:40 +02:00
return ; /* WinXP returns this when not connected to the net */
2007-01-06 19:25:07 +01:00
ok ( ( myhttp ! = 0 ) , " InternetOpenUrl failed, error %u \n " , GetLastError ( ) ) ;
2004-12-27 18:26:37 +01:00
ret = InternetReadFile ( myhttp , buffer , 0x400 , & readbytes ) ;
2007-01-06 19:25:07 +01:00
ok ( ret , " InternetReadFile failed, error %u \n " , GetLastError ( ) ) ;
2003-02-25 04:57:59 +01:00
totalbytes + = readbytes ;
while ( readbytes & & InternetReadFile ( myhttp , buffer , 0x400 , & readbytes ) )
totalbytes + = readbytes ;
2006-10-05 13:19:00 +02:00
trace ( " read 0x%08x bytes \n " , totalbytes ) ;
2007-11-11 13:35:06 +01:00
InternetCloseHandle ( myhttp ) ;
InternetCloseHandle ( myhinternet ) ;
2013-03-13 17:05:51 +01:00
2013-10-24 12:15:43 +02:00
ret = DeleteUrlCacheEntryA ( TEST_URL ) ;
2013-03-13 17:05:51 +01:00
ok ( ! ret & & GetLastError ( ) = = ERROR_FILE_NOT_FOUND , " INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work \n " ) ;
2003-02-25 04:57:59 +01:00
}
2004-08-06 20:58:04 +02:00
2005-11-21 16:17:55 +01:00
static void HttpSendRequestEx_test ( void )
{
HINTERNET hSession ;
HINTERNET hConnect ;
HINTERNET hRequest ;
2013-10-24 12:15:43 +02:00
INTERNET_BUFFERSA BufferIn ;
2009-12-21 11:13:44 +01:00
DWORD dwBytesWritten , dwBytesRead , error ;
2005-11-21 16:17:55 +01:00
CHAR szBuffer [ 256 ] ;
int i ;
2005-11-30 12:31:38 +01:00
BOOL ret ;
2005-11-21 16:17:55 +01:00
2006-10-05 20:44:30 +02:00
static char szPostData [ ] = " mode=Test " ;
2005-11-21 16:17:55 +01:00
static const char szContentType [ ] = " Content-Type: application/x-www-form-urlencoded " ;
2006-10-05 20:44:30 +02:00
2013-10-24 12:15:43 +02:00
hSession = InternetOpenA ( " Wine Regression Test " ,
2005-11-21 16:17:55 +01:00
INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , 0 ) ;
ok ( hSession ! = NULL , " Unable to open Internet session \n " ) ;
2014-09-03 14:39:51 +02:00
hConnect = InternetConnectA ( hSession , " test.winehq.org " ,
2005-11-21 16:17:55 +01:00
INTERNET_DEFAULT_HTTP_PORT , NULL , NULL , INTERNET_SERVICE_HTTP , 0 ,
0 ) ;
2014-09-03 14:39:51 +02:00
ok ( hConnect ! = NULL , " Unable to connect to http://test.winehq.org \n " ) ;
hRequest = HttpOpenRequestA ( hConnect , " POST " , " /tests/post.php " ,
2005-11-21 16:17:55 +01:00
NULL , NULL , NULL , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
2006-09-21 12:44:56 +02:00
if ( ! hRequest & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
{
2008-07-10 03:04:05 +02:00
skip ( " Network unreachable, skipping test \n " ) ;
2006-09-21 12:44:56 +02:00
goto done ;
}
2007-01-06 19:25:07 +01:00
ok ( hRequest ! = NULL , " Failed to open request handle err %u \n " , GetLastError ( ) ) ;
2005-11-21 16:17:55 +01:00
2012-05-24 15:24:55 +02:00
test_request_flags ( hRequest , INTERNET_REQFLAG_NO_HEADERS ) ;
2005-11-21 16:17:55 +01:00
2013-10-24 12:15:43 +02:00
BufferIn . dwStructSize = sizeof ( BufferIn ) ;
BufferIn . Next = ( INTERNET_BUFFERSA * ) 0xdeadcab ;
2005-11-21 16:17:55 +01:00
BufferIn . lpcszHeader = szContentType ;
2008-02-19 00:20:50 +01:00
BufferIn . dwHeadersLength = sizeof ( szContentType ) - 1 ;
BufferIn . dwHeadersTotal = sizeof ( szContentType ) - 1 ;
2006-10-05 20:44:30 +02:00
BufferIn . lpvBuffer = szPostData ;
2005-11-30 12:31:38 +01:00
BufferIn . dwBufferLength = 3 ;
2005-11-21 16:17:55 +01:00
BufferIn . dwBufferTotal = sizeof ( szPostData ) - 1 ;
BufferIn . dwOffsetLow = 0 ;
BufferIn . dwOffsetHigh = 0 ;
2009-12-21 11:13:44 +01:00
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestExA ( hRequest , & BufferIn , NULL , 0 , 0 ) ;
2009-12-21 11:13:44 +01:00
error = GetLastError ( ) ;
ok ( ret , " HttpSendRequestEx Failed with error %u \n " , error ) ;
ok ( error = = ERROR_SUCCESS , " expected ERROR_SUCCESS, got %u \n " , error ) ;
2005-11-21 16:17:55 +01:00
2012-05-24 15:24:55 +02:00
test_request_flags ( hRequest , INTERNET_REQFLAG_NO_HEADERS ) ;
2005-11-30 12:31:38 +01:00
for ( i = 3 ; szPostData [ i ] ; i + + )
2005-11-21 16:17:55 +01:00
ok ( InternetWriteFile ( hRequest , & szPostData [ i ] , 1 , & dwBytesWritten ) ,
" InternetWriteFile failed \n " ) ;
2012-05-24 15:24:55 +02:00
test_request_flags ( hRequest , INTERNET_REQFLAG_NO_HEADERS ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpEndRequestA ( hRequest , NULL , 0 , 0 ) , " HttpEndRequest Failed \n " ) ;
2005-11-21 16:17:55 +01:00
2012-05-24 15:24:55 +02:00
test_request_flags ( hRequest , 0 ) ;
2005-11-21 16:17:55 +01:00
ok ( InternetReadFile ( hRequest , szBuffer , 255 , & dwBytesRead ) ,
2005-11-23 20:14:43 +01:00
" Unable to read response \n " ) ;
2005-11-21 16:17:55 +01:00
szBuffer [ dwBytesRead ] = 0 ;
2006-10-05 13:19:00 +02:00
ok ( dwBytesRead = = 13 , " Read %u bytes instead of 13 \n " , dwBytesRead ) ;
2011-01-21 13:35:40 +01:00
ok ( strncmp ( szBuffer , " mode => Test \n " , dwBytesRead ) = = 0 | | broken ( proxy_active ( ) ) , " Got string %s \n " , szBuffer ) ;
2005-11-21 16:17:55 +01:00
ok ( InternetCloseHandle ( hRequest ) , " Close request handle failed \n " ) ;
2006-09-21 12:44:56 +02:00
done :
2005-11-21 16:17:55 +01:00
ok ( InternetCloseHandle ( hConnect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( hSession ) , " Close session handle failed \n " ) ;
}
2005-11-22 15:53:30 +01:00
2007-02-12 15:19:17 +01:00
static void InternetOpenRequest_test ( void )
{
HINTERNET session , connect , request ;
static const char * types [ ] = { " * " , " " , NULL } ;
static const WCHAR slash [ ] = { ' / ' , 0 } , any [ ] = { ' * ' , 0 } , empty [ ] = { 0 } ;
static const WCHAR * typesW [ ] = { any , empty , NULL } ;
BOOL ret ;
session = InternetOpenA ( " Wine Regression Test " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , 0 ) ;
ok ( session ! = NULL , " Unable to open Internet session \n " ) ;
2008-01-31 15:47:25 +01:00
connect = InternetConnectA ( session , NULL , INTERNET_DEFAULT_HTTP_PORT , NULL , NULL ,
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( connect = = NULL , " InternetConnectA should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d \n " , GetLastError ( ) ) ;
connect = InternetConnectA ( session , " " , INTERNET_DEFAULT_HTTP_PORT , NULL , NULL ,
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( connect = = NULL , " InternetConnectA should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d \n " , GetLastError ( ) ) ;
2008-12-10 10:47:13 +01:00
connect = InternetConnectA ( session , " test.winehq.org " , INTERNET_DEFAULT_HTTP_PORT , NULL , NULL ,
2007-02-12 15:19:17 +01:00
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2008-12-10 10:47:13 +01:00
ok ( connect ! = NULL , " Unable to connect to http://test.winehq.org with error %d \n " , GetLastError ( ) ) ;
2007-02-12 15:19:17 +01:00
request = HttpOpenRequestA ( connect , NULL , " / " , NULL , NULL , types , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
if ( ! request & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
{
2008-07-10 03:04:05 +02:00
skip ( " Network unreachable, skipping test \n " ) ;
2007-02-12 15:19:17 +01:00
goto done ;
}
ok ( request ! = NULL , " Failed to open request handle err %u \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestW ( request , NULL , 0 , NULL , 0 ) ;
2007-02-12 15:19:17 +01:00
ok ( ret , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
ok ( InternetCloseHandle ( request ) , " Close request handle failed \n " ) ;
request = HttpOpenRequestW ( connect , NULL , slash , NULL , NULL , typesW , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
ok ( request ! = NULL , " Failed to open request handle err %u \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2007-02-12 15:19:17 +01:00
ok ( ret , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
ok ( InternetCloseHandle ( request ) , " Close request handle failed \n " ) ;
done :
ok ( InternetCloseHandle ( connect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( session ) , " Close session handle failed \n " ) ;
}
2013-03-08 15:59:36 +01:00
static void test_cache_read ( void )
{
HINTERNET session , connection , req ;
FILETIME now , tomorrow , yesterday ;
BYTE content [ 1000 ] , buf [ 2000 ] ;
char file_path [ MAX_PATH ] ;
ULARGE_INTEGER li ;
HANDLE file ;
DWORD size ;
unsigned i ;
BOOL res ;
static const char cache_only_url [ ] = " http://test.winehq.org/tests/cache-only " ;
BYTE cache_headers [ ] = " HTTP/1.1 200 OK \r \n \r \n " ;
trace ( " Testing cache read... \n " ) ;
2013-10-24 12:15:43 +02:00
hCompleteEvent = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
2013-03-08 15:59:36 +01:00
for ( i = 0 ; i < sizeof ( content ) ; i + + )
content [ i ] = ' 0 ' + ( i % 10 ) ;
GetSystemTimeAsFileTime ( & now ) ;
li . u . HighPart = now . dwHighDateTime ;
li . u . LowPart = now . dwLowDateTime ;
li . QuadPart + = ( LONGLONG ) 10000000 * 3600 * 24 ;
tomorrow . dwHighDateTime = li . u . HighPart ;
tomorrow . dwLowDateTime = li . u . LowPart ;
li . QuadPart - = ( LONGLONG ) 10000000 * 3600 * 24 * 2 ;
yesterday . dwHighDateTime = li . u . HighPart ;
yesterday . dwLowDateTime = li . u . LowPart ;
res = CreateUrlCacheEntryA ( cache_only_url , sizeof ( content ) , " " , file_path , 0 ) ;
ok ( res , " CreateUrlCacheEntryA failed: %u \n " , GetLastError ( ) ) ;
file = CreateFileA ( file_path , GENERIC_WRITE , 0 , NULL , CREATE_ALWAYS , FILE_ATTRIBUTE_NORMAL , NULL ) ;
ok ( file ! = INVALID_HANDLE_VALUE , " CreateFile failed \n " ) ;
WriteFile ( file , content , sizeof ( content ) , & size , NULL ) ;
CloseHandle ( file ) ;
res = CommitUrlCacheEntryA ( cache_only_url , file_path , tomorrow , yesterday , NORMAL_CACHE_ENTRY ,
cache_headers , sizeof ( cache_headers ) - 1 , " " , 0 ) ;
ok ( res , " CommitUrlCacheEntryA failed: %u \n " , GetLastError ( ) ) ;
session = InternetOpenA ( " " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
ok ( session ! = NULL , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
pInternetSetStatusCallbackA ( session , callback ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
connection = InternetConnectA ( session , " test.winehq.org " , INTERNET_DEFAULT_HTTP_PORT ,
NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
ok ( connection ! = NULL , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
req = HttpOpenRequestA ( connection , " GET " , " /tests/cache-only " , NULL , NULL , NULL , 0 , 0xdeadbead ) ;
ok ( req ! = NULL , " HttpOpenRequest failed: %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_REQUEST_SENT ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
res = HttpSendRequestA ( req , NULL , - 1 , NULL , 0 ) ;
todo_wine
ok ( res , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
if ( res ) {
size = 0 ;
res = InternetQueryDataAvailable ( req , & size , 0 , 0 ) ;
ok ( res , " InternetQueryDataAvailable failed: %u \n " , GetLastError ( ) ) ;
ok ( size = = sizeof ( content ) , " size = %u \n " , size ) ;
size = sizeof ( buf ) ;
res = InternetReadFile ( req , buf , sizeof ( buf ) , & size ) ;
ok ( res , " InternetReadFile failed: %u \n " , GetLastError ( ) ) ;
ok ( size = = sizeof ( content ) , " size = %u \n " , size ) ;
ok ( ! memcmp ( content , buf , sizeof ( content ) ) , " unexpected content \n " ) ;
}
close_async_handle ( session , hCompleteEvent , 2 ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
res = DeleteUrlCacheEntryA ( cache_only_url ) ;
ok ( res , " DeleteUrlCacheEntryA failed: %u \n " , GetLastError ( ) ) ;
CloseHandle ( hCompleteEvent ) ;
}
2008-02-13 13:33:42 +01:00
static void test_http_cache ( void )
{
HINTERNET session , connect , request ;
char file_name [ MAX_PATH ] , url [ INTERNET_MAX_URL_LENGTH ] ;
DWORD size , file_size ;
BYTE buf [ 100 ] ;
HANDLE file ;
BOOL ret ;
2015-05-28 14:20:05 +02:00
FILETIME filetime_zero = { 0 } ;
2008-02-13 13:33:42 +01:00
2015-05-28 14:20:05 +02:00
static const char cached_content [ ] = " data read from cache " ;
2008-02-13 13:33:42 +01:00
static const char * types [ ] = { " * " , " " , NULL } ;
session = InternetOpenA ( " Wine Regression Test " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , 0 ) ;
ok ( session ! = NULL , " Unable to open Internet session \n " ) ;
2008-12-10 10:47:13 +01:00
connect = InternetConnectA ( session , " test.winehq.org " , INTERNET_DEFAULT_HTTP_PORT , NULL , NULL ,
2008-02-13 13:33:42 +01:00
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2008-12-10 10:47:13 +01:00
ok ( connect ! = NULL , " Unable to connect to http://test.winehq.org with error %d \n " , GetLastError ( ) ) ;
2008-02-13 13:33:42 +01:00
2011-03-14 16:43:19 +01:00
request = HttpOpenRequestA ( connect , NULL , " /tests/hello.html " , NULL , NULL , types , INTERNET_FLAG_NEED_FILE , 0 ) ;
2008-02-13 13:33:42 +01:00
if ( ! request & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
{
2008-07-10 03:04:05 +02:00
skip ( " Network unreachable, skipping test \n " ) ;
2008-02-13 13:33:42 +01:00
ok ( InternetCloseHandle ( connect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( session ) , " Close session handle failed \n " ) ;
return ;
}
ok ( request ! = NULL , " Failed to open request handle err %u \n " , GetLastError ( ) ) ;
size = sizeof ( url ) ;
ret = InternetQueryOptionA ( request , INTERNET_OPTION_URL , url , & size ) ;
2009-06-02 20:31:43 +02:00
ok ( ret , " InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u \n " , GetLastError ( ) ) ;
2011-03-14 16:43:19 +01:00
ok ( ! strcmp ( url , " http://test.winehq.org/tests/hello.html " ) , " Wrong URL %s \n " , url ) ;
2008-02-13 13:33:42 +01:00
size = sizeof ( file_name ) ;
ret = InternetQueryOptionA ( request , INTERNET_OPTION_DATAFILE_NAME , file_name , & size ) ;
ok ( ! ret , " InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded \n " ) ;
ok ( GetLastError ( ) = = ERROR_INTERNET_ITEM_NOT_FOUND , " GetLastError()=%u \n " , GetLastError ( ) ) ;
ok ( ! size , " size = %d \n " , size ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2008-02-13 13:33:42 +01:00
ok ( ret , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
size = sizeof ( file_name ) ;
ret = InternetQueryOptionA ( request , INTERNET_OPTION_DATAFILE_NAME , file_name , & size ) ;
ok ( ret , " InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
file = CreateFileA ( file_name , GENERIC_READ , FILE_SHARE_READ , NULL , OPEN_EXISTING ,
2008-02-13 13:33:42 +01:00
FILE_ATTRIBUTE_NORMAL , NULL ) ;
ok ( file ! = INVALID_HANDLE_VALUE , " Could not create file: %u \n " , GetLastError ( ) ) ;
file_size = GetFileSize ( file , NULL ) ;
2012-11-02 13:49:05 +01:00
ok ( file_size = = 106 , " file size = %u \n " , file_size ) ;
2008-02-13 13:33:42 +01:00
2008-12-11 15:24:12 +01:00
size = sizeof ( buf ) ;
2008-02-13 13:33:42 +01:00
ret = InternetReadFile ( request , buf , sizeof ( buf ) , & size ) ;
ok ( ret , " InternetReadFile failed: %u \n " , GetLastError ( ) ) ;
2008-12-11 15:24:12 +01:00
ok ( size = = 100 , " size = %u \n " , size ) ;
2008-02-13 13:33:42 +01:00
file_size = GetFileSize ( file , NULL ) ;
2012-11-02 13:49:05 +01:00
ok ( file_size = = 106 , " file size = %u \n " , file_size ) ;
2008-02-13 13:33:42 +01:00
CloseHandle ( file ) ;
2013-10-04 16:53:34 +02:00
ret = DeleteFileA ( file_name ) ;
ok ( ! ret & & GetLastError ( ) = = ERROR_SHARING_VIOLATION , " Deleting file returned %x(%u) \n " , ret , GetLastError ( ) ) ;
2008-02-13 13:33:42 +01:00
ok ( InternetCloseHandle ( request ) , " Close request handle failed \n " ) ;
2015-05-28 14:20:05 +02:00
file = CreateFileA ( file_name , GENERIC_WRITE , FILE_SHARE_READ | FILE_SHARE_WRITE , NULL , OPEN_EXISTING ,
FILE_ATTRIBUTE_NORMAL , NULL ) ;
2009-06-23 09:36:07 +02:00
ok ( file ! = INVALID_HANDLE_VALUE , " Could not create file: %u \n " , GetLastError ( ) ) ;
2015-05-28 14:20:05 +02:00
ret = WriteFile ( file , cached_content , sizeof ( cached_content ) , & size , NULL ) ;
ok ( ret & & size , " WriteFile failed: %d, %d \n " , ret , size ) ;
ret = CommitUrlCacheEntryA ( url , file_name , filetime_zero , filetime_zero , NORMAL_CACHE_ENTRY , NULL , 0 , NULL , 0 ) ;
ok ( ret , " CommitUrlCacheEntry failed: %d \n " , GetLastError ( ) ) ;
2008-12-11 15:24:12 +01:00
CloseHandle ( file ) ;
2008-02-13 13:33:42 +01:00
2011-03-01 19:56:00 +01:00
/* Send the same request, requiring it to be retrieved from the cache */
2013-10-24 12:15:43 +02:00
request = HttpOpenRequestA ( connect , " GET " , " /tests/hello.html " , NULL , NULL , NULL , INTERNET_FLAG_FROM_CACHE , 0 ) ;
2011-03-01 19:56:00 +01:00
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2011-03-01 19:56:00 +01:00
ok ( ret , " HttpSendRequest failed \n " ) ;
size = sizeof ( buf ) ;
ret = InternetReadFile ( request , buf , sizeof ( buf ) , & size ) ;
ok ( ret , " InternetReadFile failed: %u \n " , GetLastError ( ) ) ;
ok ( size = = 100 , " size = %u \n " , size ) ;
2015-05-28 14:20:05 +02:00
buf [ 99 ] = 0 ;
todo_wine ok ( ! strcmp ( ( char * ) buf , cached_content ) , " incorrect page data: %s \n " , ( char * ) buf ) ;
ok ( InternetCloseHandle ( request ) , " Close request handle failed \n " ) ;
2011-03-01 19:56:00 +01:00
2015-05-28 14:20:05 +02:00
DeleteUrlCacheEntryA ( url ) ;
request = HttpOpenRequestA ( connect , " GET " , " /tests/hello.html " , NULL , NULL , NULL , INTERNET_FLAG_FROM_CACHE , 0 ) ;
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
todo_wine ok ( ! ret , " HttpSendRequest succeeded \n " ) ;
if ( ! ret )
ok ( GetLastError ( ) = = ERROR_FILE_NOT_FOUND , " GetLastError() = %d \n " , GetLastError ( ) ) ;
2011-03-01 19:56:00 +01:00
ok ( InternetCloseHandle ( request ) , " Close request handle failed \n " ) ;
2008-02-13 13:33:42 +01:00
request = HttpOpenRequestA ( connect , NULL , " / " , NULL , NULL , types , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
ok ( request ! = NULL , " Failed to open request handle err %u \n " , GetLastError ( ) ) ;
2008-12-11 15:24:12 +01:00
size = sizeof ( file_name ) ;
2008-02-13 13:33:42 +01:00
ret = InternetQueryOptionA ( request , INTERNET_OPTION_DATAFILE_NAME , file_name , & size ) ;
ok ( ! ret , " InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded \n " ) ;
ok ( GetLastError ( ) = = ERROR_INTERNET_ITEM_NOT_FOUND , " GetLastError()=%u \n " , GetLastError ( ) ) ;
ok ( ! size , " size = %d \n " , size ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2008-02-13 13:33:42 +01:00
ok ( ret , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
size = sizeof ( file_name ) ;
2009-09-10 15:17:17 +02:00
file_name [ 0 ] = 0 ;
2008-02-13 13:33:42 +01:00
ret = InternetQueryOptionA ( request , INTERNET_OPTION_DATAFILE_NAME , file_name , & size ) ;
2009-09-10 15:17:17 +02:00
if ( ret )
{
2013-10-24 12:15:43 +02:00
file = CreateFileA ( file_name , GENERIC_READ , FILE_SHARE_READ | FILE_SHARE_WRITE , NULL , OPEN_EXISTING ,
2008-02-13 13:33:42 +01:00
FILE_ATTRIBUTE_NORMAL , NULL ) ;
2009-09-10 15:17:17 +02:00
ok ( file ! = INVALID_HANDLE_VALUE , " Could not create file: %u \n " , GetLastError ( ) ) ;
CloseHandle ( file ) ;
}
else
{
/* < IE8 */
ok ( file_name [ 0 ] = = 0 , " Didn't expect a file name \n " ) ;
}
2008-02-13 13:33:42 +01:00
ok ( InternetCloseHandle ( request ) , " Close request handle failed \n " ) ;
ok ( InternetCloseHandle ( connect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( session ) , " Close session handle failed \n " ) ;
2013-03-08 15:59:36 +01:00
test_cache_read ( ) ;
2008-02-13 13:33:42 +01:00
}
2013-10-04 16:53:34 +02:00
static void InternetLockRequestFile_test ( void )
{
HINTERNET session , connect , request ;
char file_name [ MAX_PATH ] ;
HANDLE lock , lock2 ;
DWORD size ;
BOOL ret ;
static const char * types [ ] = { " * " , " " , NULL } ;
session = InternetOpenA ( " Wine Regression Test " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , 0 ) ;
ok ( session ! = NULL , " Unable to open Internet session \n " ) ;
connect = InternetConnectA ( session , " test.winehq.org " , INTERNET_DEFAULT_HTTP_PORT , NULL , NULL ,
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( connect ! = NULL , " Unable to connect to http://test.winehq.org with error %d \n " , GetLastError ( ) ) ;
request = HttpOpenRequestA ( connect , NULL , " /tests/hello.html " , NULL , NULL , types , INTERNET_FLAG_NEED_FILE | INTERNET_FLAG_RELOAD , 0 ) ;
if ( ! request & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
{
skip ( " Network unreachable, skipping test \n " ) ;
ok ( InternetCloseHandle ( connect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( session ) , " Close session handle failed \n " ) ;
return ;
}
ok ( request ! = NULL , " Failed to open request handle err %u \n " , GetLastError ( ) ) ;
size = sizeof ( file_name ) ;
ret = InternetQueryOptionA ( request , INTERNET_OPTION_DATAFILE_NAME , file_name , & size ) ;
ok ( ! ret , " InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded \n " ) ;
ok ( GetLastError ( ) = = ERROR_INTERNET_ITEM_NOT_FOUND , " GetLastError()=%u \n " , GetLastError ( ) ) ;
ok ( ! size , " size = %d \n " , size ) ;
lock = NULL ;
ret = InternetLockRequestFile ( request , & lock ) ;
ok ( ! ret & & GetLastError ( ) = = ERROR_FILE_NOT_FOUND , " InternetLockRequestFile returned: %x(%u) \n " , ret , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2013-10-04 16:53:34 +02:00
ok ( ret , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
size = sizeof ( file_name ) ;
ret = InternetQueryOptionA ( request , INTERNET_OPTION_DATAFILE_NAME , file_name , & size ) ;
ok ( ret , " InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u \n " , GetLastError ( ) ) ;
ret = InternetLockRequestFile ( request , & lock ) ;
ok ( ret , " InternetLockRequestFile returned: %x(%u) \n " , ret , GetLastError ( ) ) ;
ok ( lock ! = NULL , " lock == NULL \n " ) ;
ret = InternetLockRequestFile ( request , & lock2 ) ;
ok ( ret , " InternetLockRequestFile returned: %x(%u) \n " , ret , GetLastError ( ) ) ;
ok ( lock = = lock2 , " lock != lock2 \n " ) ;
ret = InternetUnlockRequestFile ( lock2 ) ;
ok ( ret , " InternetUnlockRequestFile failed: %u \n " , GetLastError ( ) ) ;
ret = DeleteFileA ( file_name ) ;
ok ( ! ret & & GetLastError ( ) = = ERROR_SHARING_VIOLATION , " Deleting file returned %x(%u) \n " , ret , GetLastError ( ) ) ;
ok ( InternetCloseHandle ( request ) , " Close request handle failed \n " ) ;
ret = DeleteFileA ( file_name ) ;
ok ( ! ret & & GetLastError ( ) = = ERROR_SHARING_VIOLATION , " Deleting file returned %x(%u) \n " , ret , GetLastError ( ) ) ;
ret = InternetUnlockRequestFile ( lock ) ;
ok ( ret , " InternetUnlockRequestFile failed: %u \n " , GetLastError ( ) ) ;
ret = DeleteFileA ( file_name ) ;
ok ( ret , " Deleting file returned %x(%u) \n " , ret , GetLastError ( ) ) ;
}
2005-11-22 15:53:30 +01:00
static void HttpHeaders_test ( void )
{
HINTERNET hSession ;
HINTERNET hConnect ;
HINTERNET hRequest ;
2005-12-13 17:07:41 +01:00
CHAR buffer [ 256 ] ;
2008-07-30 15:49:04 +02:00
WCHAR wbuffer [ 256 ] ;
2005-12-13 17:07:41 +01:00
DWORD len = 256 ;
2008-07-30 15:49:04 +02:00
DWORD oldlen ;
2005-12-13 17:07:41 +01:00
DWORD index = 0 ;
2013-09-22 21:35:34 +02:00
BOOL ret ;
2005-11-22 15:53:30 +01:00
2013-10-24 12:15:43 +02:00
hSession = InternetOpenA ( " Wine Regression Test " ,
2005-11-22 15:53:30 +01:00
INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , 0 ) ;
ok ( hSession ! = NULL , " Unable to open Internet session \n " ) ;
2014-09-03 14:39:51 +02:00
hConnect = InternetConnectA ( hSession , " test.winehq.org " ,
2005-11-22 15:53:30 +01:00
INTERNET_DEFAULT_HTTP_PORT , NULL , NULL , INTERNET_SERVICE_HTTP , 0 ,
0 ) ;
2014-09-03 14:39:51 +02:00
ok ( hConnect ! = NULL , " Unable to connect to http://test.winehq.org \n " ) ;
hRequest = HttpOpenRequestA ( hConnect , " POST " , " /tests/post.php " ,
2005-11-22 15:53:30 +01:00
NULL , NULL , NULL , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
2006-09-21 12:44:56 +02:00
if ( ! hRequest & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
{
2008-07-10 03:04:05 +02:00
skip ( " Network unreachable, skipping test \n " ) ;
2006-09-21 12:44:56 +02:00
goto done ;
}
2005-11-22 15:53:30 +01:00
ok ( hRequest ! = NULL , " Failed to open request handle \n " ) ;
2005-12-13 17:07:41 +01:00
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2005-12-13 17:07:41 +01:00
buffer , & len , & index ) = = 0 , " Warning hearder reported as Existing \n " ) ;
2009-04-20 21:56:59 +02:00
2013-10-24 12:15:43 +02:00
ok ( HttpAddRequestHeadersA ( hRequest , " Warning:test1 " , - 1 , HTTP_ADDREQ_FLAG_ADD ) ,
2005-12-13 17:07:41 +01:00
" Failed to add new header \n " ) ;
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2005-12-13 17:07:41 +01:00
buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test1 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
2007-08-16 01:29:58 +02:00
ok ( len = = 5 , " Invalid length (exp. 5, got %d) \n " , len ) ;
2008-01-23 22:26:58 +01:00
ok ( ( len < sizeof ( buffer ) ) & & ( buffer [ len ] = = 0 ) , " Buffer not NULL-terminated \n " ) ; /* len show only 5 characters but the buffer is NULL-terminated*/
2005-12-13 17:07:41 +01:00
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2005-12-13 17:07:41 +01:00
buffer , & len , & index ) = = 0 , " Second Index Should Not Exist \n " ) ;
2007-08-16 01:56:43 +02:00
index = 0 ;
len = 5 ; /* could store the string but not the NULL terminator */
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2007-08-16 01:56:43 +02:00
buffer , & len , & index ) = = FALSE , " Query succeeded on a too small buffer \n " ) ;
2014-06-17 02:57:10 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " Unexpected last error: %d \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
2007-08-16 01:56:43 +02:00
ok ( strcmp ( buffer , " Warning " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ; /* string not touched */
ok ( len = = 6 , " Invalid length (exp. 6, got %d) \n " , len ) ; /* unlike success, the length includes the NULL-terminator */
2007-08-16 01:55:15 +02:00
/* a call with NULL will fail but will return the length */
index = 0 ;
len = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2007-08-16 01:55:15 +02:00
NULL , & len , & index ) = = FALSE , " Query worked \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " Unexpected last error: %d \n " , GetLastError ( ) ) ;
ok ( len > 40 , " Invalid length (exp. more than 40, got %d) \n " , len ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
/* even for a len that is too small */
index = 0 ;
len = 15 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2007-08-16 01:55:15 +02:00
NULL , & len , & index ) = = FALSE , " Query worked \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " Unexpected last error: %d \n " , GetLastError ( ) ) ;
ok ( len > 40 , " Invalid length (exp. more than 40, got %d) \n " , len ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
index = 0 ;
len = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2007-08-16 01:55:15 +02:00
NULL , & len , & index ) = = FALSE , " Query worked \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " Unexpected last error: %d \n " , GetLastError ( ) ) ;
ok ( len > 40 , " Invalid length (exp. more than 40, got %d) \n " , len ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
2008-07-30 15:49:04 +02:00
oldlen = len ; /* bytes; at least long enough to hold buffer & nul */
2007-08-16 01:55:15 +02:00
2007-08-16 01:29:58 +02:00
/* a working query */
index = 0 ;
len = sizeof ( buffer ) ;
2008-07-30 15:49:04 +02:00
memset ( buffer , ' x ' , sizeof ( buffer ) ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2007-08-16 01:29:58 +02:00
buffer , & len , & index ) , " Unable to query header \n " ) ;
2008-07-30 15:49:04 +02:00
ok ( len + sizeof ( CHAR ) < = oldlen , " Result longer than advertised \n " ) ;
ok ( ( len < sizeof ( buffer ) - sizeof ( CHAR ) ) & & ( buffer [ len / sizeof ( CHAR ) ] = = 0 ) , " No NUL at end \n " ) ;
ok ( len = = strlen ( buffer ) * sizeof ( CHAR ) , " Length wrong \n " ) ;
2007-08-16 01:29:58 +02:00
/* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
2014-09-03 14:39:51 +02:00
ok ( strncmp ( buffer , " POST /tests/post.php HTTP/1 " , 25 ) = = 0 , " Invalid beginning of headers string \n " ) ;
2007-08-16 01:29:58 +02:00
ok ( strcmp ( buffer + strlen ( buffer ) - 4 , " \r \n \r \n " ) = = 0 , " Invalid end of headers string \n " ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
2008-07-30 15:49:04 +02:00
/* Like above two tests, but for W version */
2007-08-16 01:29:58 +02:00
2008-07-30 15:49:04 +02:00
index = 0 ;
len = 0 ;
SetLastError ( 0xdeadbeef ) ;
ok ( HttpQueryInfoW ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
NULL , & len , & index ) = = FALSE , " Query worked \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " Unexpected last error: %d \n " , GetLastError ( ) ) ;
ok ( len > 80 , " Invalid length (exp. more than 80, got %d) \n " , len ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
oldlen = len ; /* bytes; at least long enough to hold buffer & nul */
/* a working query */
index = 0 ;
len = sizeof ( wbuffer ) ;
memset ( wbuffer , ' x ' , sizeof ( wbuffer ) ) ;
ok ( HttpQueryInfoW ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
wbuffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( len + sizeof ( WCHAR ) < = oldlen , " Result longer than advertised \n " ) ;
ok ( len = = lstrlenW ( wbuffer ) * sizeof ( WCHAR ) , " Length wrong \n " ) ;
ok ( ( len < sizeof ( wbuffer ) - sizeof ( WCHAR ) ) & & ( wbuffer [ len / sizeof ( WCHAR ) ] = = 0 ) , " No NUL at end \n " ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
/* end of W version tests */
2007-08-16 01:29:58 +02:00
2008-08-28 01:54:17 +02:00
/* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
index = 0 ;
len = sizeof ( buffer ) ;
memset ( buffer , ' x ' , sizeof ( buffer ) ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF ,
2008-08-28 01:54:17 +02:00
buffer , & len , & index ) = = TRUE , " Query failed \n " ) ;
ok ( len = = 2 , " Expected 2, got %d \n " , len ) ;
ok ( strcmp ( buffer , " \r \n " ) = = 0 , " Expected CRLF, got '%s' \n " , buffer ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpAddRequestHeadersA ( hRequest , " Warning:test2 " , - 1 , HTTP_ADDREQ_FLAG_ADD ) ,
2005-12-13 17:07:41 +01:00
" Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD \n " ) ;
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2005-12-13 17:07:41 +01:00
buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test1 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2005-12-13 17:07:41 +01:00
buffer , & len , & index ) , " Failed to get second header \n " ) ;
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test2 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2005-12-13 17:07:41 +01:00
buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpAddRequestHeadersA ( hRequest , " Warning:test3 " , - 1 , HTTP_ADDREQ_FLAG_REPLACE ) , " Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE \n " ) ;
2005-12-13 17:07:41 +01:00
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2005-12-13 17:07:41 +01:00
buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test2 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2005-12-13 17:07:41 +01:00
buffer , & len , & index ) , " Failed to get second header \n " ) ;
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test3 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2005-12-13 17:07:41 +01:00
buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
2009-04-20 21:56:59 +02:00
2013-10-24 12:15:43 +02:00
ok ( HttpAddRequestHeadersA ( hRequest , " Warning:test4 " , - 1 , HTTP_ADDREQ_FLAG_ADD_IF_NEW ) = = 0 , " HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header \n " ) ;
2005-11-22 15:53:30 +01:00
2005-12-13 17:07:41 +01:00
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2005-12-13 17:07:41 +01:00
buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test2 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2005-12-13 17:07:41 +01:00
buffer , & len , & index ) , " Failed to get second header \n " ) ;
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test3 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2005-12-13 17:07:41 +01:00
buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpAddRequestHeadersA ( hRequest , " Warning:test4 " , - 1 , HTTP_ADDREQ_FLAG_COALESCE ) , " HTTP_ADDREQ_FLAG_COALESCE Did not work \n " ) ;
2005-12-13 17:07:41 +01:00
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
2005-12-13 17:07:41 +01:00
buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test2, test4 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Failed to get second header \n " ) ;
2005-12-13 17:07:41 +01:00
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test3 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
2005-12-13 17:07:41 +01:00
2013-10-24 12:15:43 +02:00
ok ( HttpAddRequestHeadersA ( hRequest , " Warning:test5 " , - 1 , HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA ) , " HTTP_ADDREQ_FLAG_COALESCE Did not work \n " ) ;
2005-12-13 17:07:41 +01:00
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Unable to query header \n " ) ;
2005-12-13 17:07:41 +01:00
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test2, test4, test5 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Failed to get second header \n " ) ;
2005-12-13 17:07:41 +01:00
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test3 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
2005-12-13 17:07:41 +01:00
2013-10-24 12:15:43 +02:00
ok ( HttpAddRequestHeadersA ( hRequest , " Warning:test6 " , - 1 , HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON ) , " HTTP_ADDREQ_FLAG_COALESCE Did not work \n " ) ;
2005-12-13 17:07:41 +01:00
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Unable to query header \n " ) ;
2005-12-13 17:07:41 +01:00
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test2, test4, test5; test6 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Failed to get second header \n " ) ;
2005-12-13 17:07:41 +01:00
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test3 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
2005-12-13 17:07:41 +01:00
2013-10-24 12:15:43 +02:00
ok ( HttpAddRequestHeadersA ( hRequest , " Warning:test7 " , - 1 , HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE ) , " HTTP_ADDREQ_FLAG_ADD with HTTP_ADDREQ_FLAG_REPALCE Did not work \n " ) ;
2005-12-13 17:07:41 +01:00
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Unable to query header \n " ) ;
2005-12-13 17:07:41 +01:00
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test3 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Failed to get second header \n " ) ;
2005-12-13 17:07:41 +01:00
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test7 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
2005-12-13 17:07:41 +01:00
2009-04-24 18:25:01 +02:00
/* Ensure that blank headers are ignored and don't cause a failure */
2013-10-24 12:15:43 +02:00
ok ( HttpAddRequestHeadersA ( hRequest , " \r \n BlankTest:value \r \n \r \n " , - 1 , HTTP_ADDREQ_FLAG_ADD_IF_NEW ) , " Failed to add header with blank entries in list \n " ) ;
2009-04-24 18:25:01 +02:00
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " BlankTest " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Unable to query header \n " ) ;
2009-04-24 18:25:01 +02:00
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " value " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
2009-04-20 21:56:59 +02:00
2009-06-15 00:30:07 +02:00
/* Ensure that malformed header separators are ignored and don't cause a failure */
2013-10-24 12:15:43 +02:00
ok ( HttpAddRequestHeadersA ( hRequest , " \r \r MalformedTest:value \n \n MalformedTestTwo: value2 \r MalformedTestThree: value3 \n \n \r \r \n " , - 1 , HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE ) ,
2009-06-15 00:30:07 +02:00
" Failed to add header with malformed entries in list \n " ) ;
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " MalformedTest " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Unable to query header \n " ) ;
2009-06-15 00:30:07 +02:00
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " value " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " MalformedTestTwo " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Unable to query header \n " ) ;
2009-06-15 00:30:07 +02:00
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " value2 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " MalformedTestThree " ) ;
2013-10-24 12:15:43 +02:00
ok ( HttpQueryInfoA ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Unable to query header \n " ) ;
2009-06-15 00:30:07 +02:00
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " value3 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpAddRequestHeadersA ( hRequest , " Authorization: Basic \r \n " , - 1 , HTTP_ADDREQ_FLAG_ADD ) ;
2013-09-22 21:35:34 +02:00
ok ( ret , " unable to add header %u \n " , GetLastError ( ) ) ;
2013-08-29 15:26:18 +02:00
index = 0 ;
buffer [ 0 ] = 0 ;
len = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hRequest , HTTP_QUERY_AUTHORIZATION | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) ;
2013-09-22 21:35:34 +02:00
ok ( ret , " unable to query header %u \n " , GetLastError ( ) ) ;
2013-08-29 15:26:18 +02:00
ok ( index = = 1 , " index was not incremented \n " ) ;
ok ( ! strcmp ( buffer , " Basic " ) , " incorrect string was returned (%s) \n " , buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpAddRequestHeadersA ( hRequest , " Authorization: \r \n " , - 1 , HTTP_ADDREQ_FLAG_REPLACE ) ;
2013-09-22 21:35:34 +02:00
ok ( ret , " unable to remove header %u \n " , GetLastError ( ) ) ;
2013-08-29 15:26:18 +02:00
index = 0 ;
len = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ok ( ! HttpQueryInfoA ( hRequest , HTTP_QUERY_AUTHORIZATION | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) ,
2013-08-29 15:26:18 +02:00
" header still present \n " ) ;
ok ( GetLastError ( ) = = ERROR_HTTP_HEADER_NOT_FOUND , " got %u \n " , GetLastError ( ) ) ;
2005-11-22 15:53:30 +01:00
ok ( InternetCloseHandle ( hRequest ) , " Close request handle failed \n " ) ;
2006-09-21 12:44:56 +02:00
done :
2005-11-22 15:53:30 +01:00
ok ( InternetCloseHandle ( hConnect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( hSession ) , " Close session handle failed \n " ) ;
}
2009-06-23 07:30:38 +02:00
static const char garbagemsg [ ] =
" Garbage: Header \r \n " ;
2008-02-17 20:41:56 +01:00
static const char contmsg [ ] =
" HTTP/1.1 100 Continue \r \n " ;
2009-06-23 07:30:38 +02:00
static const char expandcontmsg [ ] =
" HTTP/1.1 100 Continue \r \n "
" Server: winecontinue \r \n "
" Tag: something witty \r \n "
" \r \n " ;
2006-05-16 16:03:45 +02:00
static const char okmsg [ ] =
2008-02-17 20:41:56 +01:00
" HTTP/1.1 200 OK \r \n "
2006-05-16 16:03:45 +02:00
" Server: winetest \r \n "
" \r \n " ;
2008-12-01 15:35:05 +01:00
static const char okmsg2 [ ] =
" HTTP/1.1 200 OK \r \n "
" Date: Mon, 01 Dec 2008 13:44:34 GMT \r \n "
" Server: winetest \r \n "
" Content-Length: 0 \r \n "
" Set-Cookie: one \r \n "
" Set-Cookie: two \r \n "
" \r \n " ;
2007-08-09 21:43:25 +02:00
static const char notokmsg [ ] =
2008-02-17 20:41:56 +01:00
" HTTP/1.1 400 Bad Request \r \n "
2007-08-09 21:43:25 +02:00
" Server: winetest \r \n "
" \r \n " ;
static const char noauthmsg [ ] =
2008-02-17 20:41:56 +01:00
" HTTP/1.1 401 Unauthorized \r \n "
2007-08-09 21:43:25 +02:00
" Server: winetest \r \n "
2008-10-17 13:46:52 +02:00
" Connection: close \r \n "
" WWW-Authenticate: Basic realm= \" placebo \" \r \n "
2007-08-09 21:43:25 +02:00
" \r \n " ;
2009-03-04 12:44:22 +01:00
static const char noauthmsg2 [ ] =
" HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed \r \n "
" HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed "
" \0 d`0|6 \n "
" Server: winetest \r \n " ;
2006-05-30 15:55:16 +02:00
static const char proxymsg [ ] =
" HTTP/1.1 407 Proxy Authentication Required \r \n "
" Server: winetest \r \n "
" Proxy-Connection: close \r \n "
" Proxy-Authenticate: Basic realm= \" placebo \" \r \n "
" \r \n " ;
2006-05-16 16:03:45 +02:00
static const char page1 [ ] =
" <HTML> \r \n "
" <HEAD><TITLE>wininet test page</TITLE></HEAD> \r \n "
" <BODY>The quick brown fox jumped over the lazy dog<P></BODY> \r \n "
" </HTML> \r \n \r \n " ;
2013-06-05 17:35:41 +02:00
static const char ok_with_length [ ] =
" HTTP/1.1 200 OK \r \n "
" Connection: Keep-Alive \r \n "
2013-11-26 00:12:04 +01:00
" Content-Length: 18 \r \n \r \n "
" HTTP/1.1 211 OK \r \n \r \n " ;
2013-06-05 17:35:41 +02:00
static const char ok_with_length2 [ ] =
" HTTP/1.1 210 OK \r \n "
" Connection: Keep-Alive \r \n "
2013-11-26 00:12:04 +01:00
" Content-Length: 19 \r \n \r \n "
" HTTP/1.1 211 OK \r \n \r \n " ;
2013-06-05 17:35:41 +02:00
2006-05-16 16:03:45 +02:00
struct server_info {
HANDLE hEvent ;
int port ;
} ;
2013-04-30 17:00:36 +02:00
static int test_cache_gzip ;
2013-07-12 15:05:57 +02:00
static const char * send_buffer ;
2016-05-04 12:40:03 +02:00
static int server_socket ;
2013-04-30 17:00:36 +02:00
2006-05-16 16:03:45 +02:00
static DWORD CALLBACK server_thread ( LPVOID param )
{
struct server_info * si = param ;
2014-06-25 14:41:47 +02:00
int r , c = - 1 , i , on , count = 0 ;
2007-11-26 23:07:34 +01:00
SOCKET s ;
2006-05-16 16:03:45 +02:00
struct sockaddr_in sa ;
char buffer [ 0x100 ] ;
WSADATA wsaData ;
2006-05-30 15:55:16 +02:00
int last_request = 0 ;
2008-07-02 09:52:18 +02:00
char host_header [ 22 ] ;
2015-06-25 12:27:30 +02:00
char host_header_override [ 30 ] ;
2013-12-05 10:29:37 +01:00
static BOOL test_b = FALSE ;
2013-04-15 14:58:25 +02:00
static int test_no_cache = 0 ;
2006-05-16 16:03:45 +02:00
WSAStartup ( MAKEWORD ( 1 , 1 ) , & wsaData ) ;
s = socket ( AF_INET , SOCK_STREAM , 0 ) ;
2007-11-26 23:07:34 +01:00
if ( s = = INVALID_SOCKET )
2006-05-30 15:55:16 +02:00
return 1 ;
on = 1 ;
setsockopt ( s , SOL_SOCKET , SO_REUSEADDR , ( char * ) & on , sizeof on ) ;
2006-05-16 16:03:45 +02:00
memset ( & sa , 0 , sizeof sa ) ;
sa . sin_family = AF_INET ;
sa . sin_port = htons ( si - > port ) ;
sa . sin_addr . S_un . S_addr = inet_addr ( " 127.0.0.1 " ) ;
r = bind ( s , ( struct sockaddr * ) & sa , sizeof sa ) ;
if ( r < 0 )
return 1 ;
2006-05-30 15:55:16 +02:00
listen ( s , 0 ) ;
2006-05-16 16:03:45 +02:00
SetEvent ( si - > hEvent ) ;
2008-07-02 09:52:18 +02:00
sprintf ( host_header , " Host: localhost:%d " , si - > port ) ;
2015-06-25 12:27:30 +02:00
sprintf ( host_header_override , " Host: test.local:%d \r \n " , si - > port ) ;
2008-07-02 09:52:18 +02:00
2006-05-30 15:55:16 +02:00
do
2006-05-16 16:03:45 +02:00
{
2014-06-25 14:41:47 +02:00
if ( c = = - 1 )
c = accept ( s , NULL , NULL ) ;
2006-05-30 15:55:16 +02:00
memset ( buffer , 0 , sizeof buffer ) ;
for ( i = 0 ; i < ( sizeof buffer - 1 ) ; i + + )
{
r = recv ( c , & buffer [ i ] , 1 , 0 ) ;
if ( r ! = 1 )
break ;
if ( i < 4 ) continue ;
if ( buffer [ i - 2 ] = = ' \n ' & & buffer [ i ] = = ' \n ' & &
buffer [ i - 3 ] = = ' \r ' & & buffer [ i - 1 ] = = ' \r ' )
break ;
}
if ( strstr ( buffer , " GET /test1 " ) )
{
2008-02-02 16:08:28 +01:00
if ( ! strstr ( buffer , " Content-Length: 0 " ) )
{
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
}
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
2006-05-30 15:55:16 +02:00
}
2015-10-02 15:06:36 +02:00
if ( strstr ( buffer , " CONNECT " ) )
{
if ( ! strstr ( buffer , " Content-Length: 0 " ) )
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
else
send ( c , proxymsg , sizeof proxymsg - 1 , 0 ) ;
}
2006-05-30 15:55:16 +02:00
if ( strstr ( buffer , " /test2 " ) )
{
if ( strstr ( buffer , " Proxy-Authorization: Basic bWlrZToxMTAx " ) )
{
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
}
else
send ( c , proxymsg , sizeof proxymsg - 1 , 0 ) ;
}
2007-08-09 21:43:25 +02:00
if ( strstr ( buffer , " /test3 " ) )
{
if ( strstr ( buffer , " Authorization: Basic dXNlcjpwd2Q= " ) )
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , noauthmsg , sizeof noauthmsg - 1 , 0 ) ;
}
if ( strstr ( buffer , " /test4 " ) )
{
if ( strstr ( buffer , " Connection: Close " ) )
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
2009-01-14 16:20:11 +01:00
if ( strstr ( buffer , " POST /test5 " ) | |
strstr ( buffer , " RPC_IN_DATA /test5 " ) | |
strstr ( buffer , " RPC_OUT_DATA /test5 " ) )
2007-10-28 16:32:46 +01:00
{
if ( strstr ( buffer , " Content-Length: 0 " ) )
{
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
}
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
2008-02-17 20:41:56 +01:00
if ( strstr ( buffer , " GET /test6 " ) )
{
send ( c , contmsg , sizeof contmsg - 1 , 0 ) ;
send ( c , contmsg , sizeof contmsg - 1 , 0 ) ;
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
}
2008-05-09 13:12:42 +02:00
if ( strstr ( buffer , " POST /test7 " ) )
{
if ( strstr ( buffer , " Content-Length: 100 " ) )
{
2015-09-22 15:59:22 +02:00
if ( strstr ( buffer , " POST /test7b " ) )
recvfrom ( c , buffer , sizeof buffer , 0 , NULL , NULL ) ;
2008-05-09 13:12:42 +02:00
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
}
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
2008-05-31 21:47:24 +02:00
if ( strstr ( buffer , " /test8 " ) )
{
if ( ! strstr ( buffer , " Connection: Close " ) & &
2008-07-02 09:52:18 +02:00
strstr ( buffer , " Connection: Keep-Alive " ) & &
! strstr ( buffer , " Cache-Control: no-cache " ) & &
! strstr ( buffer , " Pragma: no-cache " ) & &
strstr ( buffer , host_header ) )
2008-05-31 21:47:24 +02:00
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
if ( strstr ( buffer , " /test9 " ) )
{
if ( ! strstr ( buffer , " Connection: Close " ) & &
2008-07-02 09:52:18 +02:00
! strstr ( buffer , " Connection: Keep-Alive " ) & &
! strstr ( buffer , " Cache-Control: no-cache " ) & &
! strstr ( buffer , " Pragma: no-cache " ) & &
strstr ( buffer , host_header ) )
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
if ( strstr ( buffer , " /testA " ) )
{
if ( ! strstr ( buffer , " Connection: Close " ) & &
! strstr ( buffer , " Connection: Keep-Alive " ) & &
( strstr ( buffer , " Cache-Control: no-cache " ) | |
strstr ( buffer , " Pragma: no-cache " ) ) & &
strstr ( buffer , host_header ) )
2008-05-31 21:47:24 +02:00
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
2008-07-02 09:56:12 +02:00
if ( ! test_b & & strstr ( buffer , " /testB HTTP/1.1 " ) )
{
2013-12-05 10:29:37 +01:00
test_b = TRUE ;
2008-07-02 09:56:12 +02:00
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
recvfrom ( c , buffer , sizeof buffer , 0 , NULL , NULL ) ;
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
}
2008-07-19 19:55:39 +02:00
if ( strstr ( buffer , " /testC " ) )
{
if ( strstr ( buffer , " Cookie: cookie=biscuit " ) )
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
2008-12-01 15:35:05 +01:00
if ( strstr ( buffer , " /testD " ) )
{
send ( c , okmsg2 , sizeof okmsg2 - 1 , 0 ) ;
}
2009-03-04 12:44:22 +01:00
if ( strstr ( buffer , " /testE " ) )
{
send ( c , noauthmsg2 , sizeof noauthmsg2 - 1 , 0 ) ;
}
2008-02-02 16:08:28 +01:00
if ( strstr ( buffer , " GET /quit " ) )
2006-05-30 15:55:16 +02:00
{
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
last_request = 1 ;
}
2009-06-23 07:30:38 +02:00
if ( strstr ( buffer , " GET /testF " ) )
{
send ( c , expandcontmsg , sizeof expandcontmsg - 1 , 0 ) ;
send ( c , garbagemsg , sizeof garbagemsg - 1 , 0 ) ;
send ( c , contmsg , sizeof contmsg - 1 , 0 ) ;
send ( c , garbagemsg , sizeof garbagemsg - 1 , 0 ) ;
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
}
2009-09-29 21:50:12 +02:00
if ( strstr ( buffer , " GET /testG " ) )
{
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
}
2013-06-05 17:35:41 +02:00
if ( strstr ( buffer , " GET /testJ " ) )
{
if ( count = = 0 )
{
count + + ;
send ( c , ok_with_length , sizeof ( ok_with_length ) - 1 , 0 ) ;
}
else
{
send ( c , ok_with_length2 , sizeof ( ok_with_length2 ) - 1 , 0 ) ;
count = 0 ;
}
}
2013-11-26 00:12:04 +01:00
if ( strstr ( buffer , " GET /testH " ) )
{
send ( c , ok_with_length2 , sizeof ( ok_with_length2 ) - 1 , 0 ) ;
recvfrom ( c , buffer , sizeof ( buffer ) , 0 , NULL , NULL ) ;
send ( c , ok_with_length , sizeof ( ok_with_length ) - 1 , 0 ) ;
}
2013-06-05 17:35:41 +02:00
2011-05-13 13:49:00 +02:00
if ( strstr ( buffer , " GET /test_no_content " ) )
{
static const char nocontentmsg [ ] = " HTTP/1.1 204 No Content \r \n Connection: close \r \n \r \n " ;
send ( c , nocontentmsg , sizeof ( nocontentmsg ) - 1 , 0 ) ;
}
2011-05-23 16:10:22 +02:00
if ( strstr ( buffer , " GET /test_conn_close " ) )
{
static const char conn_close_response [ ] = " HTTP/1.1 200 OK \r \n Connection: close \r \n \r \n some content " ;
send ( c , conn_close_response , sizeof ( conn_close_response ) - 1 , 0 ) ;
WaitForSingleObject ( conn_close_event , INFINITE ) ;
trace ( " closing connection \n " ) ;
}
2013-03-13 17:06:01 +01:00
if ( strstr ( buffer , " GET /test_cache_control_no_cache " ) )
{
static const char no_cache_response [ ] = " HTTP/1.1 200 OK \r \n Cache-Control: no-cache \r \n \r \n some content " ;
2013-04-15 14:58:25 +02:00
if ( ! test_no_cache + + )
send ( c , no_cache_response , sizeof ( no_cache_response ) - 1 , 0 ) ;
else
send ( c , okmsg , sizeof ( okmsg ) - 1 , 0 ) ;
2013-03-13 17:06:01 +01:00
}
if ( strstr ( buffer , " GET /test_cache_control_no_store " ) )
{
2013-04-24 11:23:18 +02:00
static const char no_cache_response [ ] = " HTTP/1.1 200 OK \r \n Cache-Control: junk, \t No-StOrE \r \n \r \n some content " ;
2013-03-13 17:06:01 +01:00
send ( c , no_cache_response , sizeof ( no_cache_response ) - 1 , 0 ) ;
}
2013-04-30 17:00:36 +02:00
if ( strstr ( buffer , " GET /test_cache_gzip " ) )
{
static const char gzip_response [ ] = " HTTP/1.1 200 OK \r \n Content-Encoding: gzip \r \n Content-Type: text/html \r \n \r \n "
" \x1f \x8b \x08 \x00 \x00 \x00 \x00 \x00 \x00 \x03 \x4b \xaf \xca \x2c \x50 \x28 "
" \x49 \x2d \x2e \xe1 \x02 \x00 \x62 \x92 \xc7 \x6c \x0a \x00 \x00 \x00 " ;
if ( ! test_cache_gzip + + )
send ( c , gzip_response , sizeof ( gzip_response ) , 0 ) ;
else
send ( c , notokmsg , sizeof ( notokmsg ) - 1 , 0 ) ;
}
2014-06-25 14:41:47 +02:00
if ( strstr ( buffer , " HEAD /test_head " ) ) {
static const char head_response [ ] =
" HTTP/1.1 200 OK \r \n "
" Connection: Keep-Alive \r \n "
" Content-Length: 100 \r \n "
" \r \n " ;
send ( c , head_response , sizeof ( head_response ) , 0 ) ;
continue ;
}
2013-07-12 15:05:57 +02:00
if ( strstr ( buffer , " GET /send_from_buffer " ) )
send ( c , send_buffer , strlen ( send_buffer ) , 0 ) ;
2013-07-30 11:08:49 +02:00
if ( strstr ( buffer , " /test_cache_control_verb " ) )
{
if ( ! memcmp ( buffer , " GET " , sizeof ( " GET " ) - 1 ) & &
! strstr ( buffer , " Cache-Control: no-cache \r \n " ) ) send ( c , okmsg , sizeof ( okmsg ) - 1 , 0 ) ;
else if ( strstr ( buffer , " Cache-Control: no-cache \r \n " ) ) send ( c , okmsg , sizeof ( okmsg ) - 1 , 0 ) ;
2014-03-24 16:25:16 +01:00
else send ( c , notokmsg , sizeof ( notokmsg ) - 1 , 0 ) ;
2013-07-30 11:08:49 +02:00
}
2014-12-19 16:50:17 +01:00
if ( strstr ( buffer , " /test_request_content_length " ) )
{
static char msg [ ] = " HTTP/1.1 200 OK \r \n Connection: Keep-Alive \r \n \r \n " ;
static int seen_content_length ;
if ( ! seen_content_length )
{
if ( strstr ( buffer , " Content-Length: 0 " ) )
{
seen_content_length = 1 ;
send ( c , msg , sizeof msg - 1 , 0 ) ;
}
else send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
WaitForSingleObject ( hCompleteEvent , 5000 ) ;
}
else
{
if ( strstr ( buffer , " Content-Length: 0 " ) ) send ( c , msg , sizeof msg - 1 , 0 ) ;
else send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
WaitForSingleObject ( hCompleteEvent , 5000 ) ;
}
}
2013-04-17 15:32:54 +02:00
if ( strstr ( buffer , " GET /test_premature_disconnect " ) )
trace ( " closing connection \n " ) ;
2014-12-08 02:51:30 +01:00
if ( strstr ( buffer , " /test_accept_encoding_http10 " ) )
{
if ( strstr ( buffer , " Accept-Encoding: gzip " ) )
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
2015-04-30 11:50:26 +02:00
if ( strstr ( buffer , " HEAD /upload.txt " ) )
{
if ( strstr ( buffer , " Authorization: Basic dXNlcjpwd2Q= " ) )
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , noauthmsg , sizeof noauthmsg - 1 , 0 ) ;
}
if ( strstr ( buffer , " PUT /upload2.txt " ) )
{
if ( strstr ( buffer , " Authorization: Basic dXNlcjpwd2Q= " ) )
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
2015-06-25 12:27:30 +02:00
if ( strstr ( buffer , " /test_host_override " ) )
{
if ( strstr ( buffer , host_header_override ) )
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
2016-04-28 05:10:07 +02:00
if ( strstr ( buffer , " /async_read " ) )
{
const char * page1_mid = page1 + ( sizeof page1 - 1 ) / 2 ;
const char * page1_end = page1 + sizeof page1 - 1 ;
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , page1_mid - page1 , 0 ) ;
WaitForSingleObject ( conn_wait_event , INFINITE ) ;
send ( c , page1_mid , page1_end - page1_mid , 0 ) ;
}
2016-05-04 12:40:03 +02:00
if ( strstr ( buffer , " /socket " ) )
{
server_socket = c ;
SetEvent ( server_req_rec_event ) ;
WaitForSingleObject ( conn_wait_event , INFINITE ) ;
}
2006-05-30 15:55:16 +02:00
shutdown ( c , 2 ) ;
closesocket ( c ) ;
2014-06-25 14:41:47 +02:00
c = - 1 ;
2006-05-30 15:55:16 +02:00
} while ( ! last_request ) ;
2006-05-16 16:03:45 +02:00
closesocket ( s ) ;
return 0 ;
}
2008-02-02 16:08:28 +01:00
static void test_basic_request ( int port , const char * verb , const char * url )
2006-05-16 16:03:45 +02:00
{
HINTERNET hi , hc , hr ;
2014-03-24 16:25:02 +01:00
DWORD r , count , error ;
2006-05-16 16:03:45 +02:00
char buffer [ 0x100 ] ;
2013-10-24 12:15:43 +02:00
hi = InternetOpenA ( NULL , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2006-05-16 16:03:45 +02:00
ok ( hi ! = NULL , " open failed \n " ) ;
2013-10-24 12:15:43 +02:00
hc = InternetConnectA ( hi , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2006-05-16 16:03:45 +02:00
ok ( hc ! = NULL , " connect failed \n " ) ;
2013-10-24 12:15:43 +02:00
hr = HttpOpenRequestA ( hc , verb , url , NULL , NULL , NULL , 0 , 0 ) ;
2006-05-16 16:03:45 +02:00
ok ( hr ! = NULL , " HttpOpenRequest failed \n " ) ;
2014-03-24 16:25:02 +01:00
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = HttpSendRequestA ( hr , NULL , 0 , NULL , 0 ) ;
2014-03-24 16:25:02 +01:00
error = GetLastError ( ) ;
ok ( error = = ERROR_SUCCESS | | broken ( error ! = ERROR_SUCCESS ) , " expected ERROR_SUCCESS, got %u \n " , error ) ;
2006-05-16 16:03:45 +02:00
ok ( r , " HttpSendRequest failed \n " ) ;
count = 0 ;
memset ( buffer , 0 , sizeof buffer ) ;
2011-01-24 15:22:31 +01:00
SetLastError ( 0xdeadbeef ) ;
2006-05-16 16:03:45 +02:00
r = InternetReadFile ( hr , buffer , sizeof buffer , & count ) ;
2011-01-24 15:22:31 +01:00
ok ( r , " InternetReadFile failed %u \n " , GetLastError ( ) ) ;
2006-05-16 16:03:45 +02:00
ok ( count = = sizeof page1 - 1 , " count was wrong \n " ) ;
2011-04-02 15:20:53 +02:00
ok ( ! memcmp ( buffer , page1 , sizeof page1 ) , " http data wrong, got: %s \n " , buffer ) ;
2006-05-16 16:03:45 +02:00
InternetCloseHandle ( hr ) ;
InternetCloseHandle ( hc ) ;
InternetCloseHandle ( hi ) ;
2006-05-30 15:55:16 +02:00
}
static void test_proxy_indirect ( int port )
{
HINTERNET hi , hc , hr ;
2012-05-03 12:19:33 +02:00
DWORD r , sz ;
2006-05-30 15:55:16 +02:00
char buffer [ 0x40 ] ;
2015-09-22 15:59:01 +02:00
hi = InternetOpenA ( NULL , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2006-05-30 15:55:16 +02:00
ok ( hi ! = NULL , " open failed \n " ) ;
2013-10-24 12:15:43 +02:00
hc = InternetConnectA ( hi , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2006-05-30 15:55:16 +02:00
ok ( hc ! = NULL , " connect failed \n " ) ;
2013-10-24 12:15:43 +02:00
hr = HttpOpenRequestA ( hc , NULL , " /test2 " , NULL , NULL , NULL , 0 , 0 ) ;
2006-05-30 15:55:16 +02:00
ok ( hr ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
r = HttpSendRequestA ( hr , NULL , 0 , NULL , 0 ) ;
2013-04-25 10:13:40 +02:00
ok ( r , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
2006-05-30 15:55:16 +02:00
sz = sizeof buffer ;
2013-10-24 12:15:43 +02:00
r = HttpQueryInfoA ( hr , HTTP_QUERY_PROXY_AUTHENTICATE , buffer , & sz , NULL ) ;
2009-07-09 19:19:00 +02:00
ok ( r | | GetLastError ( ) = = ERROR_HTTP_HEADER_NOT_FOUND , " HttpQueryInfo failed: %d \n " , GetLastError ( ) ) ;
if ( ! r )
{
skip ( " missing proxy header, not testing remaining proxy headers \n " ) ;
goto out ;
}
2006-05-30 15:55:16 +02:00
ok ( ! strcmp ( buffer , " Basic realm= \" placebo \" " ) , " proxy auth info wrong \n " ) ;
2012-05-03 12:19:33 +02:00
test_status_code ( hr , 407 ) ;
2012-05-24 15:24:55 +02:00
test_request_flags ( hr , 0 ) ;
2006-05-30 15:55:16 +02:00
sz = sizeof buffer ;
2013-10-24 12:15:43 +02:00
r = HttpQueryInfoA ( hr , HTTP_QUERY_STATUS_TEXT , buffer , & sz , NULL ) ;
2006-05-30 15:55:16 +02:00
ok ( r , " HttpQueryInfo failed \n " ) ;
ok ( ! strcmp ( buffer , " Proxy Authentication Required " ) , " proxy text wrong \n " ) ;
sz = sizeof buffer ;
2013-10-24 12:15:43 +02:00
r = HttpQueryInfoA ( hr , HTTP_QUERY_VERSION , buffer , & sz , NULL ) ;
2006-05-30 15:55:16 +02:00
ok ( r , " HttpQueryInfo failed \n " ) ;
ok ( ! strcmp ( buffer , " HTTP/1.1 " ) , " http version wrong \n " ) ;
sz = sizeof buffer ;
2013-10-24 12:15:43 +02:00
r = HttpQueryInfoA ( hr , HTTP_QUERY_SERVER , buffer , & sz , NULL ) ;
2006-05-30 15:55:16 +02:00
ok ( r , " HttpQueryInfo failed \n " ) ;
ok ( ! strcmp ( buffer , " winetest " ) , " http server wrong \n " ) ;
sz = sizeof buffer ;
2013-10-24 12:15:43 +02:00
r = HttpQueryInfoA ( hr , HTTP_QUERY_CONTENT_ENCODING , buffer , & sz , NULL ) ;
2006-05-30 15:55:16 +02:00
ok ( GetLastError ( ) = = ERROR_HTTP_HEADER_NOT_FOUND , " HttpQueryInfo should fail \n " ) ;
ok ( r = = FALSE , " HttpQueryInfo failed \n " ) ;
2009-07-09 19:19:00 +02:00
out :
2006-05-30 15:55:16 +02:00
InternetCloseHandle ( hr ) ;
InternetCloseHandle ( hc ) ;
InternetCloseHandle ( hi ) ;
}
static void test_proxy_direct ( int port )
{
HINTERNET hi , hc , hr ;
2013-05-06 18:52:37 +02:00
DWORD r , sz , error ;
2013-04-22 11:02:50 +02:00
char buffer [ 0x40 ] , * url ;
WCHAR bufferW [ 0x40 ] ;
2013-12-31 03:00:47 +01:00
static const char url_fmt [ ] = " http://test.winehq.org:%u/test2 " ;
2006-08-10 20:24:35 +02:00
static CHAR username [ ] = " mike " ,
2013-04-22 11:02:50 +02:00
password [ ] = " 1101 " ,
2013-12-31 03:00:47 +01:00
useragent [ ] = " winetest " ;
static const WCHAR usernameW [ ] = { ' m ' , ' i ' , ' k ' , ' e ' , 0 } ,
passwordW [ ] = { ' 1 ' , ' 1 ' , ' 0 ' , ' 1 ' , 0 } ,
useragentW [ ] = { ' w ' , ' i ' , ' n ' , ' e ' , ' t ' , ' e ' , ' s ' , ' t ' , 0 } ;
2006-05-30 15:55:16 +02:00
2013-05-06 18:52:37 +02:00
/* specify proxy type without the proxy and bypass */
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
hi = InternetOpenW ( NULL , INTERNET_OPEN_TYPE_PROXY , NULL , NULL , 0 ) ;
2013-05-06 18:52:37 +02:00
error = GetLastError ( ) ;
ok ( error = = ERROR_INVALID_PARAMETER | |
broken ( error = = ERROR_SUCCESS ) /* WinXPProSP2 */ , " got %u \n " , error ) ;
ok ( hi = = NULL | | broken ( ! ! hi ) /* WinXPProSP2 */ , " open should have failed \n " ) ;
2006-05-30 15:55:16 +02:00
sprintf ( buffer , " localhost:%d \n " , port ) ;
2013-10-24 12:15:43 +02:00
hi = InternetOpenA ( NULL , INTERNET_OPEN_TYPE_PROXY , buffer , NULL , 0 ) ;
2006-05-30 15:55:16 +02:00
ok ( hi ! = NULL , " open failed \n " ) ;
/* try connect without authorization */
2013-10-24 12:15:43 +02:00
hc = InternetConnectA ( hi , " test.winehq.org " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2006-05-30 15:55:16 +02:00
ok ( hc ! = NULL , " connect failed \n " ) ;
2013-10-24 12:15:43 +02:00
hr = HttpOpenRequestA ( hc , NULL , " /test2 " , NULL , NULL , NULL , 0 , 0 ) ;
2006-05-30 15:55:16 +02:00
ok ( hr ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-07-30 11:09:19 +02:00
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PROXY_PASSWORD , NULL , & sz ) ;
2013-07-30 11:09:19 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = 1 , " got %u \n " , sz ) ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PROXY_USERNAME , NULL , & sz ) ;
2013-07-30 11:09:19 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = 1 , " got %u \n " , sz ) ;
sz = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PROXY_PASSWORD , buffer , & sz ) ;
2013-07-30 11:09:19 +02:00
ok ( r , " unexpected failure %u \n " , GetLastError ( ) ) ;
ok ( ! sz , " got %u \n " , sz ) ;
sz = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PROXY_USERNAME , buffer , & sz ) ;
2013-07-30 11:09:19 +02:00
ok ( r , " unexpected failure %u \n " , GetLastError ( ) ) ;
ok ( ! sz , " got %u \n " , sz ) ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PASSWORD , NULL , & sz ) ;
2013-07-30 11:09:19 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = 1 , " got %u \n " , sz ) ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_USERNAME , NULL , & sz ) ;
2013-07-30 11:09:19 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = 1 , " got %u \n " , sz ) ;
sz = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PASSWORD , buffer , & sz ) ;
2013-07-30 11:09:19 +02:00
ok ( r , " unexpected failure %u \n " , GetLastError ( ) ) ;
ok ( ! sz , " got %u \n " , sz ) ;
sz = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_USERNAME , buffer , & sz ) ;
2013-07-30 11:09:19 +02:00
ok ( r , " unexpected failure %u \n " , GetLastError ( ) ) ;
ok ( ! sz , " got %u \n " , sz ) ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_URL , NULL , & sz ) ;
2013-07-30 11:09:19 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = 34 , " got %u \n " , sz ) ;
sz = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_URL , buffer , & sz ) ;
2013-07-30 11:09:19 +02:00
ok ( r , " unexpected failure %u \n " , GetLastError ( ) ) ;
ok ( sz = = 33 , " got %u \n " , sz ) ;
2013-10-24 12:15:43 +02:00
r = HttpSendRequestW ( hr , NULL , 0 , NULL , 0 ) ;
2013-05-01 12:13:24 +02:00
ok ( r | | broken ( ! r ) , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
if ( ! r )
{
win_skip ( " skipping proxy tests on broken wininet \n " ) ;
goto done ;
}
2006-05-30 15:55:16 +02:00
2012-05-03 12:19:33 +02:00
test_status_code ( hr , 407 ) ;
2006-05-30 15:55:16 +02:00
/* set the user + password then try again */
2013-10-24 12:15:43 +02:00
r = InternetSetOptionA ( hi , INTERNET_OPTION_PROXY_USERNAME , username , 4 ) ;
2013-04-22 11:02:50 +02:00
ok ( ! r , " unexpected success \n " ) ;
2013-10-24 12:15:43 +02:00
r = InternetSetOptionA ( hc , INTERNET_OPTION_PROXY_USERNAME , username , 4 ) ;
2013-04-22 11:02:50 +02:00
ok ( r , " failed to set user \n " ) ;
2013-10-24 12:15:43 +02:00
r = InternetSetOptionA ( hr , INTERNET_OPTION_PROXY_USERNAME , username , 4 ) ;
2006-05-30 15:55:16 +02:00
ok ( r , " failed to set user \n " ) ;
2013-07-30 11:09:19 +02:00
buffer [ 0 ] = 0 ;
sz = 3 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PROXY_USERNAME , buffer , & sz ) ;
2013-07-30 11:09:19 +02:00
ok ( ! r , " unexpected failure %u \n " , GetLastError ( ) ) ;
ok ( ! buffer [ 0 ] , " got %s \n " , buffer ) ;
ok ( sz = = strlen ( username ) + 1 , " got %u \n " , sz ) ;
2013-04-22 11:02:50 +02:00
buffer [ 0 ] = 0 ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PROXY_USERNAME , buffer , & sz ) ;
2013-04-22 11:02:50 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = strlen ( username ) + 1 , " got %u \n " , sz ) ;
bufferW [ 0 ] = 0 ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
r = InternetQueryOptionW ( hr , INTERNET_OPTION_PROXY_USERNAME , bufferW , & sz ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = ( lstrlenW ( usernameW ) + 1 ) * sizeof ( WCHAR ) , " got %u \n " , sz ) ;
buffer [ 0 ] = 0 ;
sz = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PROXY_USERNAME , buffer , & sz ) ;
2013-04-22 11:02:50 +02:00
ok ( r , " failed to get username \n " ) ;
ok ( ! strcmp ( buffer , username ) , " got %s \n " , buffer ) ;
ok ( sz = = strlen ( username ) , " got %u \n " , sz ) ;
buffer [ 0 ] = 0 ;
sz = sizeof ( bufferW ) ;
r = InternetQueryOptionW ( hr , INTERNET_OPTION_PROXY_USERNAME , bufferW , & sz ) ;
ok ( r , " failed to get username \n " ) ;
ok ( ! lstrcmpW ( bufferW , usernameW ) , " wrong username \n " ) ;
ok ( sz = = lstrlenW ( usernameW ) , " got %u \n " , sz ) ;
2013-10-24 12:15:43 +02:00
r = InternetSetOptionA ( hr , INTERNET_OPTION_PROXY_USERNAME , username , 1 ) ;
2013-04-22 11:02:50 +02:00
ok ( r , " failed to set user \n " ) ;
buffer [ 0 ] = 0 ;
sz = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PROXY_USERNAME , buffer , & sz ) ;
2013-04-22 11:02:50 +02:00
ok ( r , " failed to get username \n " ) ;
ok ( ! strcmp ( buffer , username ) , " got %s \n " , buffer ) ;
ok ( sz = = strlen ( username ) , " got %u \n " , sz ) ;
2013-10-24 12:15:43 +02:00
r = InternetSetOptionA ( hi , INTERNET_OPTION_USER_AGENT , useragent , 1 ) ;
2013-04-22 11:02:50 +02:00
ok ( r , " failed to set useragent \n " ) ;
buffer [ 0 ] = 0 ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hi , INTERNET_OPTION_USER_AGENT , buffer , & sz ) ;
2013-04-22 11:02:50 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = strlen ( useragent ) + 1 , " got %u \n " , sz ) ;
buffer [ 0 ] = 0 ;
sz = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hi , INTERNET_OPTION_USER_AGENT , buffer , & sz ) ;
2013-04-22 11:02:50 +02:00
ok ( r , " failed to get user agent \n " ) ;
ok ( ! strcmp ( buffer , useragent ) , " got %s \n " , buffer ) ;
ok ( sz = = strlen ( useragent ) , " got %u \n " , sz ) ;
bufferW [ 0 ] = 0 ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
r = InternetQueryOptionW ( hi , INTERNET_OPTION_USER_AGENT , bufferW , & sz ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = ( lstrlenW ( useragentW ) + 1 ) * sizeof ( WCHAR ) , " got %u \n " , sz ) ;
bufferW [ 0 ] = 0 ;
sz = sizeof ( bufferW ) ;
r = InternetQueryOptionW ( hi , INTERNET_OPTION_USER_AGENT , bufferW , & sz ) ;
ok ( r , " failed to get user agent \n " ) ;
ok ( ! lstrcmpW ( bufferW , useragentW ) , " wrong user agent \n " ) ;
ok ( sz = = lstrlenW ( useragentW ) , " got %u \n " , sz ) ;
2013-10-24 12:15:43 +02:00
r = InternetSetOptionA ( hr , INTERNET_OPTION_USERNAME , username , 1 ) ;
2013-04-22 11:02:50 +02:00
ok ( r , " failed to set user \n " ) ;
buffer [ 0 ] = 0 ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_USERNAME , buffer , & sz ) ;
2013-04-22 11:02:50 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = strlen ( username ) + 1 , " got %u \n " , sz ) ;
buffer [ 0 ] = 0 ;
sz = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_USERNAME , buffer , & sz ) ;
2013-04-22 11:02:50 +02:00
ok ( r , " failed to get user \n " ) ;
ok ( ! strcmp ( buffer , username ) , " got %s \n " , buffer ) ;
ok ( sz = = strlen ( username ) , " got %u \n " , sz ) ;
bufferW [ 0 ] = 0 ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
r = InternetQueryOptionW ( hr , INTERNET_OPTION_USERNAME , bufferW , & sz ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = ( lstrlenW ( usernameW ) + 1 ) * sizeof ( WCHAR ) , " got %u \n " , sz ) ;
bufferW [ 0 ] = 0 ;
sz = sizeof ( bufferW ) ;
r = InternetQueryOptionW ( hr , INTERNET_OPTION_USERNAME , bufferW , & sz ) ;
ok ( r , " failed to get user \n " ) ;
ok ( ! lstrcmpW ( bufferW , usernameW ) , " wrong user \n " ) ;
ok ( sz = = lstrlenW ( usernameW ) , " got %u \n " , sz ) ;
2013-10-24 12:15:43 +02:00
r = InternetSetOptionA ( hr , INTERNET_OPTION_PASSWORD , password , 1 ) ;
2013-04-22 11:02:50 +02:00
ok ( r , " failed to set password \n " ) ;
buffer [ 0 ] = 0 ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PASSWORD , buffer , & sz ) ;
2013-04-22 11:02:50 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = strlen ( password ) + 1 , " got %u \n " , sz ) ;
buffer [ 0 ] = 0 ;
sz = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PASSWORD , buffer , & sz ) ;
2013-04-22 11:02:50 +02:00
ok ( r , " failed to get password \n " ) ;
ok ( ! strcmp ( buffer , password ) , " got %s \n " , buffer ) ;
ok ( sz = = strlen ( password ) , " got %u \n " , sz ) ;
bufferW [ 0 ] = 0 ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
r = InternetQueryOptionW ( hr , INTERNET_OPTION_PASSWORD , bufferW , & sz ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = ( lstrlenW ( passwordW ) + 1 ) * sizeof ( WCHAR ) , " got %u \n " , sz ) ;
bufferW [ 0 ] = 0 ;
sz = sizeof ( bufferW ) ;
r = InternetQueryOptionW ( hr , INTERNET_OPTION_PASSWORD , bufferW , & sz ) ;
ok ( r , " failed to get password \n " ) ;
ok ( ! lstrcmpW ( bufferW , passwordW ) , " wrong password \n " ) ;
ok ( sz = = lstrlenW ( passwordW ) , " got %u \n " , sz ) ;
url = HeapAlloc ( GetProcessHeap ( ) , 0 , strlen ( url_fmt ) + 11 ) ;
sprintf ( url , url_fmt , port ) ;
buffer [ 0 ] = 0 ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_URL , buffer , & sz ) ;
2013-04-22 11:02:50 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = strlen ( url ) + 1 , " got %u \n " , sz ) ;
buffer [ 0 ] = 0 ;
sz = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_URL , buffer , & sz ) ;
2013-04-22 11:02:50 +02:00
ok ( r , " failed to get url \n " ) ;
ok ( ! strcmp ( buffer , url ) , " got %s \n " , buffer ) ;
ok ( sz = = strlen ( url ) , " got %u \n " , sz ) ;
bufferW [ 0 ] = 0 ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
r = InternetQueryOptionW ( hr , INTERNET_OPTION_URL , bufferW , & sz ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = ( strlen ( url ) + 1 ) * sizeof ( WCHAR ) , " got %u \n " , sz ) ;
bufferW [ 0 ] = 0 ;
sz = sizeof ( bufferW ) ;
r = InternetQueryOptionW ( hr , INTERNET_OPTION_URL , bufferW , & sz ) ;
ok ( r , " failed to get url \n " ) ;
ok ( ! strcmp_wa ( bufferW , url ) , " wrong url \n " ) ;
ok ( sz = = strlen ( url ) , " got %u \n " , sz ) ;
HeapFree ( GetProcessHeap ( ) , 0 , url ) ;
2013-10-24 12:15:43 +02:00
r = InternetSetOptionA ( hr , INTERNET_OPTION_PROXY_PASSWORD , password , 4 ) ;
2006-05-30 15:55:16 +02:00
ok ( r , " failed to set password \n " ) ;
2013-04-22 11:02:50 +02:00
buffer [ 0 ] = 0 ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PROXY_PASSWORD , buffer , & sz ) ;
2013-04-22 11:02:50 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = strlen ( password ) + 1 , " got %u \n " , sz ) ;
buffer [ 0 ] = 0 ;
sz = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
r = InternetQueryOptionA ( hr , INTERNET_OPTION_PROXY_PASSWORD , buffer , & sz ) ;
2013-04-22 11:02:50 +02:00
ok ( r , " failed to get password \n " ) ;
ok ( ! strcmp ( buffer , password ) , " got %s \n " , buffer ) ;
ok ( sz = = strlen ( password ) , " got %u \n " , sz ) ;
bufferW [ 0 ] = 0 ;
sz = 0 ;
SetLastError ( 0xdeadbeef ) ;
r = InternetQueryOptionW ( hr , INTERNET_OPTION_PROXY_PASSWORD , bufferW , & sz ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " got %u \n " , GetLastError ( ) ) ;
ok ( ! r , " unexpected success \n " ) ;
ok ( sz = = ( lstrlenW ( passwordW ) + 1 ) * sizeof ( WCHAR ) , " got %u \n " , sz ) ;
bufferW [ 0 ] = 0 ;
sz = sizeof ( bufferW ) ;
r = InternetQueryOptionW ( hr , INTERNET_OPTION_PROXY_PASSWORD , bufferW , & sz ) ;
ok ( r , " failed to get password \n " ) ;
ok ( ! lstrcmpW ( bufferW , passwordW ) , " wrong password \n " ) ;
ok ( sz = = lstrlenW ( passwordW ) , " got %u \n " , sz ) ;
2006-05-30 15:55:16 +02:00
2013-10-24 12:15:43 +02:00
r = HttpSendRequestW ( hr , NULL , 0 , NULL , 0 ) ;
2013-06-12 11:08:42 +02:00
if ( ! r )
{
win_skip ( " skipping proxy tests on broken wininet \n " ) ;
goto done ;
}
2013-04-25 10:13:40 +02:00
ok ( r , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
2006-05-30 15:55:16 +02:00
sz = sizeof buffer ;
2013-10-24 12:15:43 +02:00
r = HttpQueryInfoA ( hr , HTTP_QUERY_STATUS_CODE , buffer , & sz , NULL ) ;
2006-05-30 15:55:16 +02:00
ok ( r , " HttpQueryInfo failed \n " ) ;
ok ( ! strcmp ( buffer , " 200 " ) , " proxy code wrong \n " ) ;
2015-10-02 15:06:36 +02:00
InternetCloseHandle ( hr ) ;
InternetCloseHandle ( hc ) ;
InternetCloseHandle ( hi ) ;
sprintf ( buffer , " localhost:%d \n " , port ) ;
hi = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_PROXY , buffer , NULL , 0 ) ;
ok ( hi ! = NULL , " InternetOpen failed \n " ) ;
hc = InternetConnectA ( hi , " test.winehq.org " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( hc ! = NULL , " InternetConnect failed \n " ) ;
hr = HttpOpenRequestA ( hc , " POST " , " /test2 " , NULL , NULL , NULL , INTERNET_FLAG_SECURE , 0 ) ;
ok ( hr ! = NULL , " HttpOpenRequest failed \n " ) ;
r = HttpSendRequestA ( hr , NULL , 0 , ( char * ) " data " , sizeof ( " data " ) ) ;
ok ( r , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
test_status_code ( hr , 407 ) ;
2013-05-01 12:13:24 +02:00
done :
2006-05-30 15:55:16 +02:00
InternetCloseHandle ( hr ) ;
InternetCloseHandle ( hc ) ;
InternetCloseHandle ( hi ) ;
}
2007-08-09 21:43:25 +02:00
static void test_header_handling_order ( int port )
{
2013-12-31 03:00:47 +01:00
static const char authorization [ ] = " Authorization: Basic dXNlcjpwd2Q= " ;
static const char connection [ ] = " Connection: Close " ;
2007-08-09 21:43:25 +02:00
static const char * types [ 2 ] = { " * " , NULL } ;
2014-05-26 14:09:10 +02:00
char data [ 32 ] ;
2007-08-09 21:43:25 +02:00
HINTERNET session , connect , request ;
2014-05-26 14:09:10 +02:00
DWORD size , status , data_len ;
2007-08-09 21:43:25 +02:00
BOOL ret ;
2013-10-24 12:15:43 +02:00
session = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2007-08-09 21:43:25 +02:00
ok ( session ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
connect = InternetConnectA ( session , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2007-08-09 21:43:25 +02:00
ok ( connect ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
request = HttpOpenRequestA ( connect , NULL , " /test3 " , NULL , NULL , types , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
2007-08-09 21:43:25 +02:00
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpAddRequestHeadersA ( request , authorization , ~ 0u , HTTP_ADDREQ_FLAG_ADD ) ;
2008-02-01 14:40:15 +01:00
ok ( ret , " HttpAddRequestHeaders failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2007-08-09 21:43:25 +02:00
ok ( ret , " HttpSendRequest failed \n " ) ;
2012-05-03 12:19:33 +02:00
test_status_code ( request , 200 ) ;
2012-05-24 15:24:55 +02:00
test_request_flags ( request , 0 ) ;
2007-08-09 21:43:25 +02:00
InternetCloseHandle ( request ) ;
2013-10-24 12:15:43 +02:00
request = HttpOpenRequestA ( connect , NULL , " /test4 " , NULL , NULL , types , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
2007-08-09 21:43:25 +02:00
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , connection , ~ 0u , NULL , 0 ) ;
2007-08-09 21:43:25 +02:00
ok ( ret , " HttpSendRequest failed \n " ) ;
status = 0 ;
size = sizeof ( status ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( request , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
2007-08-09 21:43:25 +02:00
ok ( ret , " HttpQueryInfo failed \n " ) ;
2008-07-19 19:53:09 +02:00
ok ( status = = 200 | | status = = 400 /* IE6 */ , " got status %u, expected 200 or 400 \n " , status ) ;
2007-08-09 21:43:25 +02:00
2008-05-09 13:12:42 +02:00
InternetCloseHandle ( request ) ;
2014-05-26 14:09:10 +02:00
InternetCloseHandle ( connect ) ;
connect = InternetConnectA ( session , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( connect ! = NULL , " InternetConnect failed \n " ) ;
2008-05-09 13:12:42 +02:00
2013-10-24 12:15:43 +02:00
request = HttpOpenRequestA ( connect , " POST " , " /test7 " , NULL , NULL , types , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
2008-05-09 13:12:42 +02:00
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpAddRequestHeadersA ( request , " Content-Length: 100 \r \n " , ~ 0u , HTTP_ADDREQ_FLAG_ADD_IF_NEW ) ;
2008-05-09 13:12:42 +02:00
ok ( ret , " HttpAddRequestHeaders failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , connection , ~ 0u , NULL , 0 ) ;
2008-05-09 13:12:42 +02:00
ok ( ret , " HttpSendRequest failed \n " ) ;
status = 0 ;
size = sizeof ( status ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( request , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
2008-05-09 13:12:42 +02:00
ok ( ret , " HttpQueryInfo failed \n " ) ;
2014-05-26 14:09:10 +02:00
ok ( status = = 200 , " got status %u, expected 200 \n " , status ) ;
InternetCloseHandle ( request ) ;
InternetCloseHandle ( connect ) ;
connect = InternetConnectA ( session , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( connect ! = NULL , " InternetConnect failed \n " ) ;
2015-09-22 15:59:22 +02:00
request = HttpOpenRequestA ( connect , " POST " , " /test7b " , NULL , NULL , types , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
2014-05-26 14:09:10 +02:00
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpAddRequestHeadersA ( request , " Content-Length: 100 \r \n " , ~ 0u , HTTP_ADDREQ_FLAG_ADD_IF_NEW ) ;
ok ( ret , " HttpAddRequestHeaders failed \n " ) ;
data_len = sizeof ( data ) ;
memset ( data , ' a ' , sizeof ( data ) ) ;
2015-09-22 15:59:22 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , data , data_len ) ;
2015-07-17 12:38:21 +02:00
ok ( ret , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
2014-05-26 14:09:10 +02:00
status = 0 ;
size = sizeof ( status ) ;
ret = HttpQueryInfoA ( request , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed \n " ) ;
ok ( status = = 200 , " got status %u, expected 200 \n " , status ) ;
2008-05-09 13:12:42 +02:00
2007-08-09 21:43:25 +02:00
InternetCloseHandle ( request ) ;
InternetCloseHandle ( connect ) ;
InternetCloseHandle ( session ) ;
}
2008-05-31 21:47:24 +02:00
static void test_connection_header ( int port )
{
HINTERNET ses , con , req ;
BOOL ret ;
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2008-05-31 21:47:24 +02:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2008-05-31 21:47:24 +02:00
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , " /test8 " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
2008-05-31 21:47:24 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2008-05-31 21:47:24 +02:00
ok ( ret , " HttpSendRequest failed \n " ) ;
2012-05-03 12:19:33 +02:00
test_status_code ( req , 200 ) ;
2008-05-31 21:47:24 +02:00
InternetCloseHandle ( req ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , " /test9 " , NULL , NULL , NULL , 0 , 0 ) ;
2008-05-31 21:47:24 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2008-05-31 21:47:24 +02:00
ok ( ret , " HttpSendRequest failed \n " ) ;
2012-05-03 12:19:33 +02:00
test_status_code ( req , 200 ) ;
2008-07-02 09:52:18 +02:00
InternetCloseHandle ( req ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , " /test9 " , NULL , NULL , NULL , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
2008-07-02 09:52:18 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2008-07-02 09:52:18 +02:00
ok ( ret , " HttpSendRequest failed \n " ) ;
2012-05-03 12:19:33 +02:00
test_status_code ( req , 200 ) ;
2008-07-02 09:52:18 +02:00
InternetCloseHandle ( req ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , " POST " , " /testA " , NULL , NULL , NULL , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
2008-07-02 09:52:18 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2008-07-02 09:52:18 +02:00
ok ( ret , " HttpSendRequest failed \n " ) ;
2012-05-03 12:19:33 +02:00
test_status_code ( req , 200 ) ;
2008-05-31 21:47:24 +02:00
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2015-06-25 12:27:30 +02:00
static void test_header_override ( int port )
{
char buffer [ 128 ] , host_header_override [ 30 ] , full_url [ 128 ] ;
HINTERNET ses , con , req ;
DWORD size , count , err ;
BOOL ret ;
sprintf ( host_header_override , " Host: test.local:%d \r \n " , port ) ;
sprintf ( full_url , " http://localhost:%d/test_host_override " , port ) ;
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
req = HttpOpenRequestA ( con , NULL , " /test_host_override " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
size = sizeof ( buffer ) - 1 ;
count = 0 ;
memset ( buffer , 0 , sizeof ( buffer ) ) ;
ret = HttpQueryInfoA ( req , HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , & count ) ;
err = GetLastError ( ) ;
2015-08-25 07:26:43 +02:00
ok ( ! ret , " HttpQueryInfo succeeded \n " ) ;
ok ( err = = ERROR_HTTP_HEADER_NOT_FOUND , " Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d \n " , err ) ;
2015-06-25 12:27:30 +02:00
size = sizeof ( buffer ) - 1 ;
memset ( buffer , 0 , sizeof ( buffer ) ) ;
ret = InternetQueryOptionA ( req , INTERNET_OPTION_URL , buffer , & size ) ;
ok ( ret , " InternetQueryOption failed \n " ) ;
ok ( ! strcmp ( full_url , buffer ) , " Expected %s, got %s \n " , full_url , buffer ) ;
ret = HttpAddRequestHeadersA ( req , host_header_override , ~ 0u , HTTP_ADDREQ_FLAG_COALESCE ) ;
ok ( ret , " HttpAddRequestHeaders failed \n " ) ;
size = sizeof ( buffer ) - 1 ;
count = 0 ;
memset ( buffer , 0 , sizeof ( buffer ) ) ;
ret = HttpQueryInfoA ( req , HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , & count ) ;
ok ( ret , " HttpQueryInfo failed \n " ) ;
size = sizeof ( buffer ) - 1 ;
memset ( buffer , 0 , sizeof ( buffer ) ) ;
ret = InternetQueryOptionA ( req , INTERNET_OPTION_URL , buffer , & size ) ;
ok ( ret , " InternetQueryOption failed \n " ) ;
2015-08-25 07:26:43 +02:00
ok ( ! strcmp ( full_url , buffer ) , " Expected %s, got %s \n " , full_url , buffer ) ;
2015-06-25 12:27:30 +02:00
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed \n " ) ;
2015-08-25 07:26:43 +02:00
test_status_code ( req , 200 ) ;
2015-06-25 12:27:30 +02:00
InternetCloseHandle ( req ) ;
req = HttpOpenRequestA ( con , NULL , " /test_host_override " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpAddRequestHeadersA ( req , host_header_override , ~ 0u , HTTP_ADDREQ_FLAG_COALESCE ) ;
ok ( ret , " HttpAddRequestHeaders failed \n " ) ;
ret = HttpAddRequestHeadersA ( req , host_header_override , ~ 0u , HTTP_ADDREQ_FLAG_COALESCE ) ;
ok ( ret , " HttpAddRequestHeaders failed \n " ) ;
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed \n " ) ;
test_status_code ( req , 400 ) ;
InternetCloseHandle ( req ) ;
req = HttpOpenRequestA ( con , NULL , " /test_host_override " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpAddRequestHeadersA ( req , host_header_override , ~ 0u , HTTP_ADDREQ_FLAG_ADD ) ;
ok ( ret , " HttpAddRequestHeaders failed \n " ) ;
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed \n " ) ;
test_status_code ( req , 200 ) ;
InternetCloseHandle ( req ) ;
req = HttpOpenRequestA ( con , NULL , " /test_host_override " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpAddRequestHeadersA ( req , host_header_override , ~ 0u , HTTP_ADDREQ_FLAG_REPLACE ) ;
err = GetLastError ( ) ;
todo_wine ok ( ! ret , " HttpAddRequestHeaders succeeded \n " ) ;
todo_wine ok ( err = = ERROR_HTTP_HEADER_NOT_FOUND , " Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d \n " , err ) ;
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed \n " ) ;
test_status_code_todo ( req , 400 ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2008-07-02 09:56:12 +02:00
static void test_http1_1 ( int port )
{
HINTERNET ses , con , req ;
BOOL ret ;
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2008-07-02 09:56:12 +02:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2008-07-02 09:56:12 +02:00
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , " /testB " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
2008-07-02 09:56:12 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2008-07-02 09:56:12 +02:00
if ( ret )
{
InternetCloseHandle ( req ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , " /testB " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
2008-07-02 09:56:12 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2008-07-02 09:56:12 +02:00
ok ( ret , " HttpSendRequest failed \n " ) ;
}
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2013-06-05 17:35:41 +02:00
static void test_connection_closing ( int port )
{
HINTERNET session , connection , req ;
DWORD res ;
2013-10-24 12:15:43 +02:00
hCompleteEvent = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
2013-06-05 17:35:41 +02:00
session = InternetOpenA ( " " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
ok ( session ! = NULL , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
pInternetSetStatusCallbackA ( session , callback ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
connection = InternetConnectA ( session , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
ok ( connection ! = NULL , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
req = HttpOpenRequestA ( connection , " GET " , " /testJ " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0xdeadbeaf ) ;
ok ( req ! = NULL , " HttpOpenRequest failed: %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
SET_OPTIONAL ( INTERNET_STATUS_DETECTING_PROXY ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_OPTIONAL ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_OPTIONAL ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
res = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ! res & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( req_error = = ERROR_SUCCESS , " req_error = %u \n " , req_error ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
test_status_code ( req , 200 ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
SET_OPTIONAL ( INTERNET_STATUS_DETECTING_PROXY ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
res = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ! res & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( req_error = = ERROR_SUCCESS , " req_error = %u \n " , req_error ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
2013-11-06 23:31:06 +01:00
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2013-06-05 17:35:41 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2013-11-06 23:31:06 +01:00
test_status_code ( req , 210 ) ;
2013-06-05 17:35:41 +02:00
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
SET_OPTIONAL ( INTERNET_STATUS_DETECTING_PROXY ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_OPTIONAL ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_OPTIONAL ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
res = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ! res & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( req_error = = ERROR_SUCCESS , " req_error = %u \n " , req_error ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2013-11-06 23:31:06 +01:00
CHECK_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
2013-06-05 17:35:41 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2013-11-06 23:31:06 +01:00
test_status_code ( req , 200 ) ;
2013-06-05 17:35:41 +02:00
SET_WINE_ALLOW ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
close_async_handle ( session , hCompleteEvent , 2 ) ;
CloseHandle ( hCompleteEvent ) ;
}
2013-11-26 00:12:04 +01:00
static void test_successive_HttpSendRequest ( int port )
{
HINTERNET session , connection , req ;
DWORD res ;
hCompleteEvent = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
session = InternetOpenA ( " " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
ok ( session ! = NULL , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
pInternetSetStatusCallbackA ( session , callback ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
connection = InternetConnectA ( session , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
ok ( connection ! = NULL , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
req = HttpOpenRequestA ( connection , " GET " , " /testH " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0xdeadbeaf ) ;
ok ( req ! = NULL , " HttpOpenRequest failed: %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
SET_OPTIONAL ( INTERNET_STATUS_DETECTING_PROXY ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
res = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ! res & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( req_error = = ERROR_SUCCESS , " req_error = %u \n " , req_error ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
test_status_code ( req , 210 ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
SET_OPTIONAL ( INTERNET_STATUS_DETECTING_PROXY ) ;
SET_EXPECT ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_OPTIONAL ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_OPTIONAL ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
res = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ! res & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( req_error = = ERROR_SUCCESS , " req_error = %u \n " , req_error ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2013-11-26 00:12:34 +01:00
test_status_code ( req , 200 ) ;
2013-11-26 00:12:04 +01:00
SET_WINE_ALLOW ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
close_async_handle ( session , hCompleteEvent , 2 ) ;
CloseHandle ( hCompleteEvent ) ;
}
2013-06-05 17:35:41 +02:00
2011-05-13 13:49:00 +02:00
static void test_no_content ( int port )
{
HINTERNET session , connection , req ;
DWORD res ;
trace ( " Testing 204 no content response... \n " ) ;
2013-10-24 12:15:43 +02:00
hCompleteEvent = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
2011-05-13 13:49:00 +02:00
2015-09-22 15:59:01 +02:00
session = InternetOpenA ( " " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
2011-05-13 13:49:00 +02:00
ok ( session ! = NULL , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
pInternetSetStatusCallbackA ( session , callback ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
connection = InternetConnectA ( session , " localhost " , port ,
NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
ok ( connection ! = NULL , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
req = HttpOpenRequestA ( connection , " GET " , " /test_no_content " , NULL , NULL , NULL ,
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE , 0xdeadbead ) ;
ok ( req ! = NULL , " HttpOpenRequest failed: %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_EXPECT ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
res = HttpSendRequestA ( req , NULL , - 1 , NULL , 0 ) ;
ok ( ! res & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
2011-06-10 14:47:37 +02:00
ok ( req_error = = ERROR_SUCCESS , " req_error = %u \n " , req_error ) ;
2011-05-13 13:49:00 +02:00
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
close_async_handle ( session , hCompleteEvent , 2 ) ;
CloseHandle ( hCompleteEvent ) ;
2014-03-24 16:25:16 +01:00
/*
* The connection should be closed before closing handle . This is true for most
* wininet versions ( including Wine ) , but some old win2k versions fail to do that .
*/
CHECK_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
2011-05-13 13:49:00 +02:00
}
2011-05-23 16:10:22 +02:00
static void test_conn_close ( int port )
{
HINTERNET session , connection , req ;
DWORD res , avail , size ;
BYTE buf [ 1024 ] ;
trace ( " Testing connection close connection... \n " ) ;
2013-10-24 12:15:43 +02:00
hCompleteEvent = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
conn_close_event = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
2011-05-23 16:10:22 +02:00
2015-09-22 15:59:01 +02:00
session = InternetOpenA ( " " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
2011-05-23 16:10:22 +02:00
ok ( session ! = NULL , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
pInternetSetStatusCallbackA ( session , callback ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
connection = InternetConnectA ( session , " localhost " , port ,
NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
ok ( connection ! = NULL , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
req = HttpOpenRequestA ( connection , " GET " , " /test_conn_close " , NULL , NULL , NULL ,
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE , 0xdeadbead ) ;
ok ( req ! = NULL , " HttpOpenRequest failed: %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
res = HttpSendRequestA ( req , NULL , - 1 , NULL , 0 ) ;
ok ( ! res & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
2011-06-10 14:47:37 +02:00
ok ( req_error = = ERROR_SUCCESS , " req_error = %u \n " , req_error ) ;
2011-05-23 16:10:22 +02:00
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
avail = 0 ;
res = InternetQueryDataAvailable ( req , & avail , 0 , 0 ) ;
ok ( res , " InternetQueryDataAvailable failed: %u \n " , GetLastError ( ) ) ;
ok ( avail ! = 0 , " avail = 0 \n " ) ;
size = 0 ;
res = InternetReadFile ( req , buf , avail , & size ) ;
ok ( res , " InternetReadFile failed: %u \n " , GetLastError ( ) ) ;
2014-09-02 12:37:37 +02:00
/* IE11 calls those in InternetQueryDataAvailable call. */
SET_OPTIONAL ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_OPTIONAL ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
2011-05-23 16:10:22 +02:00
res = InternetQueryDataAvailable ( req , & avail , 0 , 0 ) ;
ok ( ! res & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
ok ( ! avail , " avail = %u, expected 0 \n " , avail ) ;
2014-09-02 12:37:37 +02:00
CLEAR_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
2011-05-23 16:10:22 +02:00
SET_EXPECT ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
SetEvent ( conn_close_event ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
2011-06-10 14:47:37 +02:00
ok ( req_error = = ERROR_SUCCESS , " req_error = %u \n " , req_error ) ;
2014-09-02 12:37:37 +02:00
CLEAR_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
2011-05-23 16:10:22 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
close_async_handle ( session , hCompleteEvent , 2 ) ;
CloseHandle ( hCompleteEvent ) ;
}
2013-03-13 17:06:01 +01:00
static void test_no_cache ( int port )
{
static const char cache_control_no_cache [ ] = " /test_cache_control_no_cache " ;
static const char cache_control_no_store [ ] = " /test_cache_control_no_store " ;
static const char cache_url_fmt [ ] = " http://localhost:%d%s " ;
char cache_url [ 256 ] , buf [ 256 ] ;
HINTERNET ses , con , req ;
DWORD read , size ;
BOOL ret ;
trace ( " Testing no-cache header \n " ) ;
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2013-03-13 17:06:01 +01:00
ok ( ses ! = NULL , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2013-03-13 17:06:01 +01:00
ok ( con ! = NULL , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , cache_control_no_cache , NULL , NULL , NULL , 0 , 0 ) ;
2013-03-13 17:06:01 +01:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
sprintf ( cache_url , cache_url_fmt , port , cache_control_no_cache ) ;
2013-10-24 12:15:43 +02:00
DeleteUrlCacheEntryA ( cache_url ) ;
2013-03-13 17:06:01 +01:00
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2013-03-13 17:06:01 +01:00
ok ( ret , " HttpSendRequest failed with error %u \n " , GetLastError ( ) ) ;
size = 0 ;
while ( InternetReadFile ( req , buf , sizeof ( buf ) , & read ) & & read )
size + = read ;
ok ( size = = 12 , " read %d bytes of data \n " , size ) ;
InternetCloseHandle ( req ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , cache_control_no_cache , NULL , NULL , NULL , 0 , 0 ) ;
2013-04-15 14:58:25 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2013-04-15 14:58:25 +02:00
ok ( ret , " HttpSendRequest failed with error %u \n " , GetLastError ( ) ) ;
size = 0 ;
while ( InternetReadFile ( req , buf , sizeof ( buf ) , & read ) & & read )
size + = read ;
ok ( size = = 0 , " read %d bytes of data \n " , size ) ;
InternetCloseHandle ( req ) ;
2013-10-24 12:15:43 +02:00
DeleteUrlCacheEntryA ( cache_url ) ;
2013-03-13 17:06:01 +01:00
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , cache_control_no_store , NULL , NULL , NULL , 0 , 0 ) ;
2013-03-13 17:06:01 +01:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
sprintf ( cache_url , cache_url_fmt , port , cache_control_no_store ) ;
2013-10-24 12:15:43 +02:00
DeleteUrlCacheEntryA ( cache_url ) ;
2013-03-13 17:06:01 +01:00
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2013-03-13 17:06:01 +01:00
ok ( ret , " HttpSendRequest failed with error %u \n " , GetLastError ( ) ) ;
size = 0 ;
while ( InternetReadFile ( req , buf , sizeof ( buf ) , & read ) & & read )
size + = read ;
ok ( size = = 12 , " read %d bytes of data \n " , size ) ;
InternetCloseHandle ( req ) ;
2013-10-24 12:15:43 +02:00
ret = DeleteUrlCacheEntryA ( cache_url ) ;
2013-03-13 17:06:01 +01:00
ok ( ! ret & & GetLastError ( ) = = ERROR_FILE_NOT_FOUND , " cache entry should not exist \n " ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2013-04-30 17:00:36 +02:00
static void test_cache_read_gzipped ( int port )
{
static const char cache_url_fmt [ ] = " http://localhost:%d%s " ;
static const char get_gzip [ ] = " /test_cache_gzip " ;
static const char content [ ] = " gzip test \n " ;
static const char text_html [ ] = " text/html " ;
static const char raw_header [ ] = " HTTP/1.1 200 OK \r \n Content-Type: text/html \r \n \r \n " ;
HINTERNET ses , con , req ;
DWORD read , size ;
char cache_url [ 256 ] , buf [ 256 ] ;
BOOL ret ;
trace ( " Testing reading compressed content from cache \n " ) ;
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2013-04-30 17:00:36 +02:00
ok ( ses ! = NULL , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2013-04-30 17:00:36 +02:00
ok ( con ! = NULL , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , get_gzip , NULL , NULL , NULL , 0 , 0 ) ;
2013-04-30 17:00:36 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = TRUE ;
2013-10-24 12:15:43 +02:00
ret = InternetSetOptionA ( req , INTERNET_OPTION_HTTP_DECODING , & ret , sizeof ( ret ) ) ;
2013-04-30 17:00:36 +02:00
if ( ! ret & & GetLastError ( ) = = ERROR_INTERNET_INVALID_OPTION ) {
win_skip ( " INTERNET_OPTION_HTTP_DECODING not supported \n " ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
return ;
}
ok ( ret , " InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , " Accept-Encoding: gzip " , - 1 , NULL , 0 ) ;
2013-04-30 17:00:36 +02:00
ok ( ret , " HttpSendRequest failed with error %u \n " , GetLastError ( ) ) ;
size = 0 ;
while ( InternetReadFile ( req , buf + size , sizeof ( buf ) - size , & read ) & & read )
size + = read ;
ok ( size = = 10 , " read %d bytes of data \n " , size ) ;
buf [ size ] = 0 ;
ok ( ! strncmp ( buf , content , size ) , " incorrect page content: %s \n " , buf ) ;
2013-05-30 20:27:10 +02:00
size = sizeof ( buf ) - 1 ;
2013-04-30 17:00:36 +02:00
ret = HttpQueryInfoA ( req , HTTP_QUERY_CONTENT_TYPE , buf , & size , 0 ) ;
ok ( ret , " HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d \n " , GetLastError ( ) ) ;
buf [ size ] = 0 ;
ok ( ! strncmp ( text_html , buf , size ) , " buf = %s \n " , buf ) ;
2013-05-30 20:27:10 +02:00
size = sizeof ( buf ) - 1 ;
2013-04-30 17:00:36 +02:00
ret = HttpQueryInfoA ( req , HTTP_QUERY_RAW_HEADERS_CRLF , buf , & size , 0 ) ;
ok ( ret , " HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d \n " , GetLastError ( ) ) ;
buf [ size ] = 0 ;
ok ( ! strncmp ( raw_header , buf , size ) , " buf = %s \n " , buf ) ;
InternetCloseHandle ( req ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , get_gzip , NULL , NULL , NULL , INTERNET_FLAG_FROM_CACHE , 0 ) ;
2013-04-30 17:00:36 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = TRUE ;
2013-10-24 12:15:43 +02:00
ret = InternetSetOptionA ( req , INTERNET_OPTION_HTTP_DECODING , & ret , sizeof ( ret ) ) ;
2013-04-30 17:00:36 +02:00
ok ( ret , " InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , " Accept-Encoding: gzip " , - 1 , NULL , 0 ) ;
2013-04-30 17:00:36 +02:00
ok ( ret , " HttpSendRequest failed with error %u \n " , GetLastError ( ) ) ;
size = 0 ;
2013-05-30 20:27:10 +02:00
while ( InternetReadFile ( req , buf + size , sizeof ( buf ) - 1 - size , & read ) & & read )
2013-04-30 17:00:36 +02:00
size + = read ;
todo_wine ok ( size = = 10 , " read %d bytes of data \n " , size ) ;
buf [ size ] = 0 ;
ok ( ! strncmp ( buf , content , size ) , " incorrect page content: %s \n " , buf ) ;
size = sizeof ( buf ) ;
ret = HttpQueryInfoA ( req , HTTP_QUERY_CONTENT_ENCODING , buf , & size , 0 ) ;
ok ( ! ret & & GetLastError ( ) = = ERROR_HTTP_HEADER_NOT_FOUND ,
" HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d \n " ,
ret , GetLastError ( ) ) ;
2013-05-30 20:27:10 +02:00
size = sizeof ( buf ) - 1 ;
2013-04-30 17:00:36 +02:00
ret = HttpQueryInfoA ( req , HTTP_QUERY_CONTENT_TYPE , buf , & size , 0 ) ;
todo_wine ok ( ret , " HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed : % d \ n " , GetLastError()) ;
buf [ size ] = 0 ;
todo_wine ok ( ! strncmp ( text_html , buf , size ) , " buf = %s \n " , buf ) ;
InternetCloseHandle ( req ) ;
/* Decompression doesn't work while reading from cache */
test_cache_gzip = 0 ;
sprintf ( cache_url , cache_url_fmt , port , get_gzip ) ;
2013-10-24 12:15:43 +02:00
DeleteUrlCacheEntryA ( cache_url ) ;
2013-04-30 17:00:36 +02:00
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , get_gzip , NULL , NULL , NULL , 0 , 0 ) ;
2013-04-30 17:00:36 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , " Accept-Encoding: gzip " , - 1 , NULL , 0 ) ;
2013-04-30 17:00:36 +02:00
ok ( ret , " HttpSendRequest failed with error %u \n " , GetLastError ( ) ) ;
size = 0 ;
2013-05-30 20:27:10 +02:00
while ( InternetReadFile ( req , buf + size , sizeof ( buf ) - 1 - size , & read ) & & read )
2013-04-30 17:00:36 +02:00
size + = read ;
ok ( size = = 31 , " read %d bytes of data \n " , size ) ;
InternetCloseHandle ( req ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , get_gzip , NULL , NULL , NULL , INTERNET_FLAG_FROM_CACHE , 0 ) ;
2013-04-30 17:00:36 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = TRUE ;
2013-10-24 12:15:43 +02:00
ret = InternetSetOptionA ( req , INTERNET_OPTION_HTTP_DECODING , & ret , sizeof ( ret ) ) ;
2013-04-30 17:00:36 +02:00
ok ( ret , " InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , " Accept-Encoding: gzip " , - 1 , NULL , 0 ) ;
2013-04-30 17:00:36 +02:00
ok ( ret , " HttpSendRequest failed with error %u \n " , GetLastError ( ) ) ;
size = 0 ;
2013-05-30 20:27:10 +02:00
while ( InternetReadFile ( req , buf + size , sizeof ( buf ) - 1 - size , & read ) & & read )
2013-04-30 17:00:36 +02:00
size + = read ;
todo_wine ok ( size = = 31 , " read %d bytes of data \n " , size ) ;
size = sizeof ( buf ) ;
ret = HttpQueryInfoA ( req , HTTP_QUERY_CONTENT_ENCODING , buf , & size , 0 ) ;
todo_wine ok ( ret , " HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed : % d \ n " , GetLastError()) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
2013-10-24 12:15:43 +02:00
DeleteUrlCacheEntryA ( cache_url ) ;
2013-04-30 17:00:36 +02:00
}
2009-01-15 16:41:53 +01:00
static void test_HttpSendRequestW ( int port )
{
static const WCHAR header [ ] = { ' U ' , ' A ' , ' - ' , ' C ' , ' P ' , ' U ' , ' : ' , ' ' , ' x ' , ' 8 ' , ' 6 ' , 0 } ;
HINTERNET ses , con , req ;
DWORD error ;
BOOL ret ;
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
2009-01-15 16:41:53 +01:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2009-01-15 16:41:53 +01:00
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , " /test1 " , NULL , NULL , NULL , 0 , 0 ) ;
2009-01-15 16:41:53 +01:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
SetLastError ( 0xdeadbeef ) ;
ret = HttpSendRequestW ( req , header , ~ 0u , NULL , 0 ) ;
error = GetLastError ( ) ;
ok ( ! ret , " HttpSendRequestW succeeded \n " ) ;
2009-04-20 21:56:59 +02:00
ok ( error = = ERROR_IO_PENDING | |
broken ( error = = ERROR_HTTP_HEADER_NOT_FOUND ) | | /* IE6 */
broken ( error = = ERROR_INVALID_PARAMETER ) , /* IE5 */
2009-01-28 15:39:20 +01:00
" got %u expected ERROR_IO_PENDING \n " , error ) ;
2009-01-15 16:41:53 +01:00
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2008-07-19 19:55:39 +02:00
static void test_cookie_header ( int port )
{
HINTERNET ses , con , req ;
2012-05-03 12:19:33 +02:00
DWORD size , error ;
2008-07-19 19:55:39 +02:00
BOOL ret ;
char buffer [ 64 ] ;
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2008-07-19 19:55:39 +02:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2008-07-19 19:55:39 +02:00
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
InternetSetCookieA ( " http://localhost " , " cookie " , " biscuit " ) ;
2008-07-19 19:55:39 +02:00
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , " /testC " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
2008-07-19 19:55:39 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( req , HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
2008-07-19 19:55:39 +02:00
error = GetLastError ( ) ;
ok ( ! ret , " HttpQueryInfo succeeded \n " ) ;
ok ( error = = ERROR_HTTP_HEADER_NOT_FOUND , " got %u expected ERROR_HTTP_HEADER_NOT_FOUND \n " , error ) ;
2013-10-24 12:15:43 +02:00
ret = HttpAddRequestHeadersA ( req , " Cookie: cookie=not biscuit \r \n " , ~ 0u , HTTP_ADDREQ_FLAG_ADD ) ;
2009-04-24 15:00:05 +02:00
ok ( ret , " HttpAddRequestHeaders failed: %u \n " , GetLastError ( ) ) ;
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( req , HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
2009-04-24 15:00:05 +02:00
ok ( ret , " HttpQueryInfo failed: %u \n " , GetLastError ( ) ) ;
ok ( ! strcmp ( buffer , " cookie=not biscuit " ) , " got '%s' expected \' cookie=not biscuit \' \n " , buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2008-07-19 19:55:39 +02:00
ok ( ret , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
2012-05-03 12:19:33 +02:00
test_status_code ( req , 200 ) ;
2008-07-19 19:55:39 +02:00
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( req , HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
2008-07-19 19:55:39 +02:00
ok ( ret , " HttpQueryInfo failed: %u \n " , GetLastError ( ) ) ;
ok ( ! strcmp ( buffer , " cookie=biscuit " ) , " got '%s' expected \' cookie=biscuit \' \n " , buffer ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2008-10-17 13:46:52 +02:00
static void test_basic_authentication ( int port )
{
HINTERNET session , connect , request ;
BOOL ret ;
2013-10-24 12:15:43 +02:00
session = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2008-10-17 13:46:52 +02:00
ok ( session ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
connect = InternetConnectA ( session , " localhost " , port , " user " , " pwd " , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2008-10-17 13:46:52 +02:00
ok ( connect ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
request = HttpOpenRequestA ( connect , NULL , " /test3 " , NULL , NULL , NULL , 0 , 0 ) ;
2008-10-17 13:46:52 +02:00
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2008-10-17 13:46:52 +02:00
ok ( ret , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
2012-05-03 12:19:33 +02:00
test_status_code ( request , 200 ) ;
2012-05-24 15:24:55 +02:00
test_request_flags ( request , 0 ) ;
2008-10-17 13:46:52 +02:00
InternetCloseHandle ( request ) ;
InternetCloseHandle ( connect ) ;
InternetCloseHandle ( session ) ;
}
2013-04-17 15:32:54 +02:00
static void test_premature_disconnect ( int port )
{
HINTERNET session , connect , request ;
DWORD err ;
BOOL ret ;
2013-10-24 12:15:43 +02:00
session = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2013-04-17 15:32:54 +02:00
ok ( session ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
connect = InternetConnectA ( session , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2013-04-17 15:32:54 +02:00
ok ( connect ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
request = HttpOpenRequestA ( connect , NULL , " /premature_disconnect " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
2013-04-17 15:32:54 +02:00
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2013-04-17 15:32:54 +02:00
err = GetLastError ( ) ;
todo_wine ok ( ! ret , " HttpSendRequest succeeded \n " ) ;
todo_wine ok ( err = = ERROR_HTTP_INVALID_SERVER_RESPONSE , " got %u \n " , err ) ;
InternetCloseHandle ( request ) ;
InternetCloseHandle ( connect ) ;
InternetCloseHandle ( session ) ;
}
2009-03-04 12:44:22 +01:00
static void test_invalid_response_headers ( int port )
{
HINTERNET session , connect , request ;
2012-05-03 12:19:33 +02:00
DWORD size ;
2009-03-04 12:44:22 +01:00
BOOL ret ;
char buffer [ 256 ] ;
2013-10-24 12:15:43 +02:00
session = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2009-03-04 12:44:22 +01:00
ok ( session ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
connect = InternetConnectA ( session , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2009-03-04 12:44:22 +01:00
ok ( connect ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
request = HttpOpenRequestA ( connect , NULL , " /testE " , NULL , NULL , NULL , 0 , 0 ) ;
2009-03-04 12:44:22 +01:00
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2009-03-04 12:44:22 +01:00
ok ( ret , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
2012-05-03 12:19:33 +02:00
test_status_code ( request , 401 ) ;
2012-05-24 15:24:55 +02:00
test_request_flags ( request , 0 ) ;
2009-03-04 12:44:22 +01:00
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( request , HTTP_QUERY_RAW_HEADERS , buffer , & size , NULL ) ;
2009-03-04 12:44:22 +01:00
ok ( ret , " HttpQueryInfo failed \n " ) ;
ok ( ! strcmp ( buffer , " HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed " ) ,
" headers wrong \" %s \" \n " , buffer ) ;
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( request , HTTP_QUERY_SERVER , buffer , & size , NULL ) ;
2009-03-04 12:44:22 +01:00
ok ( ret , " HttpQueryInfo failed \n " ) ;
ok ( ! strcmp ( buffer , " winetest " ) , " server wrong \" %s \" \n " , buffer ) ;
InternetCloseHandle ( request ) ;
InternetCloseHandle ( connect ) ;
InternetCloseHandle ( session ) ;
}
2009-09-29 21:50:12 +02:00
static void test_response_without_headers ( int port )
{
HINTERNET hi , hc , hr ;
2012-05-03 12:20:38 +02:00
DWORD r , count , size ;
2009-09-29 21:50:12 +02:00
char buffer [ 1024 ] ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
hi = InternetOpenA ( NULL , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2009-09-29 21:50:12 +02:00
ok ( hi ! = NULL , " open failed %u \n " , GetLastError ( ) ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
hc = InternetConnectA ( hi , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2009-09-29 21:50:12 +02:00
ok ( hc ! = NULL , " connect failed %u \n " , GetLastError ( ) ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
hr = HttpOpenRequestA ( hc , NULL , " /testG " , NULL , NULL , NULL , 0 , 0 ) ;
2009-09-29 21:50:12 +02:00
ok ( hr ! = NULL , " HttpOpenRequest failed %u \n " , GetLastError ( ) ) ;
2012-05-24 15:24:55 +02:00
test_request_flags ( hr , INTERNET_REQFLAG_NO_HEADERS ) ;
2009-09-29 21:50:12 +02:00
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = HttpSendRequestA ( hr , NULL , 0 , NULL , 0 ) ;
2009-12-03 14:48:54 +01:00
ok ( r , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
2009-09-29 21:50:12 +02:00
2012-05-24 15:24:55 +02:00
test_request_flags_todo ( hr , INTERNET_REQFLAG_NO_HEADERS ) ;
2009-09-29 21:50:12 +02:00
count = 0 ;
memset ( buffer , 0 , sizeof buffer ) ;
SetLastError ( 0xdeadbeef ) ;
r = InternetReadFile ( hr , buffer , sizeof buffer , & count ) ;
ok ( r , " InternetReadFile failed %u \n " , GetLastError ( ) ) ;
todo_wine ok ( count = = sizeof page1 - 1 , " count was wrong \n " ) ;
todo_wine ok ( ! memcmp ( buffer , page1 , sizeof page1 ) , " http data wrong \n " ) ;
2012-05-03 12:20:38 +02:00
test_status_code ( hr , 200 ) ;
2012-05-24 15:24:55 +02:00
test_request_flags_todo ( hr , INTERNET_REQFLAG_NO_HEADERS ) ;
2009-09-29 21:50:12 +02:00
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = HttpQueryInfoA ( hr , HTTP_QUERY_STATUS_TEXT , buffer , & size , NULL ) ;
2010-02-22 12:28:03 +01:00
ok ( r , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( ! strcmp ( buffer , " OK " ) , " expected OK got: \" %s \" \n " , buffer ) ;
2009-09-29 21:50:12 +02:00
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = HttpQueryInfoA ( hr , HTTP_QUERY_VERSION , buffer , & size , NULL ) ;
2009-09-29 21:50:12 +02:00
ok ( r , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
2010-02-22 12:28:03 +01:00
ok ( ! strcmp ( buffer , " HTTP/1.0 " ) , " expected HTTP/1.0 got: \" %s \" \n " , buffer ) ;
2009-09-29 21:50:12 +02:00
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
r = HttpQueryInfoA ( hr , HTTP_QUERY_RAW_HEADERS , buffer , & size , NULL ) ;
2009-09-29 21:50:12 +02:00
ok ( r , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
2010-02-22 12:28:03 +01:00
ok ( ! strcmp ( buffer , " HTTP/1.0 200 OK " ) , " raw headers wrong: \" %s \" \n " , buffer ) ;
2009-09-29 21:50:12 +02:00
InternetCloseHandle ( hr ) ;
InternetCloseHandle ( hc ) ;
InternetCloseHandle ( hi ) ;
}
2014-06-25 14:41:47 +02:00
static void test_head_request ( int port )
{
DWORD len , content_length ;
HINTERNET ses , con , req ;
BYTE buf [ 100 ] ;
BOOL ret ;
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
req = HttpOpenRequestA ( con , " HEAD " , " /test_head " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
len = sizeof ( content_length ) ;
content_length = - 1 ;
ret = HttpQueryInfoA ( req , HTTP_QUERY_FLAG_NUMBER | HTTP_QUERY_CONTENT_LENGTH , & content_length , & len , 0 ) ;
ok ( ret , " HttpQueryInfo dailed: %u \n " , GetLastError ( ) ) ;
ok ( len = = sizeof ( DWORD ) , " len = %u \n " , len ) ;
ok ( content_length = = 100 , " content_length = %u \n " , content_length ) ;
len = - 1 ;
ret = InternetReadFile ( req , buf , sizeof ( buf ) , & len ) ;
ok ( ret , " InternetReadFile failed: %u \n " , GetLastError ( ) ) ;
len = - 1 ;
ret = InternetReadFile ( req , buf , sizeof ( buf ) , & len ) ;
ok ( ret , " InternetReadFile failed: %u \n " , GetLastError ( ) ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2008-12-01 15:35:05 +01:00
static void test_HttpQueryInfo ( int port )
{
HINTERNET hi , hc , hr ;
2013-11-26 00:13:40 +01:00
DWORD size , index , error ;
2008-12-01 15:35:05 +01:00
char buffer [ 1024 ] ;
BOOL ret ;
2013-10-24 12:15:43 +02:00
hi = InternetOpenA ( NULL , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2008-12-01 15:35:05 +01:00
ok ( hi ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
hc = InternetConnectA ( hi , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2008-12-01 15:35:05 +01:00
ok ( hc ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
hr = HttpOpenRequestA ( hc , NULL , " /testD " , NULL , NULL , NULL , 0 , 0 ) ;
2008-12-01 15:35:05 +01:00
ok ( hr ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-07-12 15:05:57 +02:00
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_STATUS_TEXT , buffer , & size , & index ) ;
2013-11-26 00:13:40 +01:00
error = GetLastError ( ) ;
ok ( ! ret | | broken ( ret ) , " HttpQueryInfo succeeded \n " ) ;
if ( ! ret ) ok ( error = = ERROR_HTTP_HEADER_NOT_FOUND , " got %u expected ERROR_HTTP_HEADER_NOT_FOUND \n " , error ) ;
2013-07-12 15:05:57 +02:00
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( hr , NULL , 0 , NULL , 0 ) ;
2008-12-01 15:35:05 +01:00
ok ( ret , " HttpSendRequest failed \n " ) ;
index = 0 ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , & index ) ;
2008-12-01 15:35:05 +01:00
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 1 , " expected 1 got %u \n " , index ) ;
index = 0 ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME , buffer , & size , & index ) ;
2008-12-01 15:35:05 +01:00
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 1 , " expected 1 got %u \n " , index ) ;
index = 0 ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_RAW_HEADERS , buffer , & size , & index ) ;
2008-12-01 15:35:05 +01:00
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " expected 0 got %u \n " , index ) ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_RAW_HEADERS , buffer , & size , & index ) ;
2008-12-01 15:35:05 +01:00
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " expected 0 got %u \n " , index ) ;
2012-08-17 03:39:30 +02:00
index = 0xdeadbeef ; /* invalid start index */
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_RAW_HEADERS , buffer , & size , & index ) ;
2012-08-17 03:39:30 +02:00
todo_wine ok ( ! ret , " HttpQueryInfo should have failed \n " ) ;
todo_wine ok ( GetLastError ( ) = = ERROR_HTTP_HEADER_NOT_FOUND ,
" Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u \n " , GetLastError ( ) ) ;
index = 0 ;
2008-12-01 15:35:05 +01:00
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_RAW_HEADERS_CRLF , buffer , & size , & index ) ;
2008-12-01 15:35:05 +01:00
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " expected 0 got %u \n " , index ) ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_STATUS_TEXT , buffer , & size , & index ) ;
2008-12-01 15:35:05 +01:00
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " expected 0 got %u \n " , index ) ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_VERSION , buffer , & size , & index ) ;
2008-12-01 15:35:05 +01:00
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " expected 0 got %u \n " , index ) ;
2012-05-03 12:19:33 +02:00
test_status_code ( hr , 200 ) ;
2008-12-01 15:35:05 +01:00
index = 0xdeadbeef ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_FORWARDED , buffer , & size , & index ) ;
2008-12-01 15:35:05 +01:00
ok ( ! ret , " HttpQueryInfo succeeded \n " ) ;
ok ( index = = 0xdeadbeef , " expected 0xdeadbeef got %u \n " , index ) ;
index = 0 ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_SERVER , buffer , & size , & index ) ;
2008-12-01 15:35:05 +01:00
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 1 , " expected 1 got %u \n " , index ) ;
index = 0 ;
size = sizeof ( buffer ) ;
strcpy ( buffer , " Server " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_CUSTOM , buffer , & size , & index ) ;
2008-12-01 15:35:05 +01:00
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 1 , " expected 1 got %u \n " , index ) ;
index = 0 ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_SET_COOKIE , buffer , & size , & index ) ;
2008-12-01 15:35:05 +01:00
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 1 , " expected 1 got %u \n " , index ) ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( hr , HTTP_QUERY_SET_COOKIE , buffer , & size , & index ) ;
2008-12-01 15:35:05 +01:00
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 2 , " expected 2 got %u \n " , index ) ;
InternetCloseHandle ( hr ) ;
InternetCloseHandle ( hc ) ;
InternetCloseHandle ( hi ) ;
}
2010-05-25 12:19:58 +02:00
static void test_options ( int port )
{
2013-05-03 15:19:11 +02:00
INTERNET_DIAGNOSTIC_SOCKET_INFO idsi ;
2010-05-25 12:19:58 +02:00
HINTERNET ses , con , req ;
DWORD size , error ;
DWORD_PTR ctx ;
BOOL ret ;
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2010-05-25 12:19:58 +02:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = InternetSetOptionA ( ses , INTERNET_OPTION_CONTEXT_VALUE , NULL , 0 ) ;
2010-05-25 12:19:58 +02:00
error = GetLastError ( ) ;
ok ( ! ret , " InternetSetOption succeeded \n " ) ;
ok ( error = = ERROR_INVALID_PARAMETER , " expected ERROR_INVALID_PARAMETER, got %u \n " , error ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = InternetSetOptionA ( ses , INTERNET_OPTION_CONTEXT_VALUE , NULL , sizeof ( ctx ) ) ;
2010-05-25 12:19:58 +02:00
ok ( ! ret , " InternetSetOption succeeded \n " ) ;
error = GetLastError ( ) ;
ok ( error = = ERROR_INVALID_PARAMETER , " expected ERROR_INVALID_PARAMETER, got %u \n " , error ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = InternetSetOptionA ( ses , INTERNET_OPTION_CONTEXT_VALUE , & ctx , 0 ) ;
2010-05-25 12:19:58 +02:00
ok ( ! ret , " InternetSetOption succeeded \n " ) ;
error = GetLastError ( ) ;
ok ( error = = ERROR_INVALID_PARAMETER , " expected ERROR_INVALID_PARAMETER, got %u \n " , error ) ;
ctx = 1 ;
2013-10-24 12:15:43 +02:00
ret = InternetSetOptionA ( ses , INTERNET_OPTION_CONTEXT_VALUE , & ctx , sizeof ( ctx ) ) ;
2010-05-25 12:19:58 +02:00
ok ( ret , " InternetSetOption failed %u \n " , GetLastError ( ) ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( ses , INTERNET_OPTION_CONTEXT_VALUE , NULL , NULL ) ;
2010-05-25 12:19:58 +02:00
error = GetLastError ( ) ;
ok ( ! ret , " InternetQueryOption succeeded \n " ) ;
ok ( error = = ERROR_INVALID_PARAMETER , " expected ERROR_INVALID_PARAMETER, got %u \n " , error ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( ses , INTERNET_OPTION_CONTEXT_VALUE , & ctx , NULL ) ;
2010-05-25 12:19:58 +02:00
error = GetLastError ( ) ;
ok ( ! ret , " InternetQueryOption succeeded \n " ) ;
ok ( error = = ERROR_INVALID_PARAMETER , " expected ERROR_INVALID_PARAMETER, got %u \n " , error ) ;
size = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( ses , INTERNET_OPTION_CONTEXT_VALUE , NULL , & size ) ;
2010-05-25 12:19:58 +02:00
error = GetLastError ( ) ;
ok ( ! ret , " InternetQueryOption succeeded \n " ) ;
ok ( error = = ERROR_INSUFFICIENT_BUFFER , " expected ERROR_INSUFFICIENT_BUFFER, got %u \n " , error ) ;
size = sizeof ( ctx ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( NULL , INTERNET_OPTION_CONTEXT_VALUE , & ctx , & size ) ;
2010-05-25 12:19:58 +02:00
error = GetLastError ( ) ;
ok ( ! ret , " InternetQueryOption succeeded \n " ) ;
ok ( error = = ERROR_INTERNET_INCORRECT_HANDLE_TYPE , " expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u \n " , error ) ;
ctx = 0xdeadbeef ;
size = sizeof ( ctx ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( ses , INTERNET_OPTION_CONTEXT_VALUE , & ctx , & size ) ;
2010-05-25 12:19:58 +02:00
ok ( ret , " InternetQueryOption failed %u \n " , GetLastError ( ) ) ;
ok ( ctx = = 1 , " expected 1 got %lu \n " , ctx ) ;
2013-10-24 12:15:43 +02:00
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2010-05-25 12:19:58 +02:00
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
ctx = 0xdeadbeef ;
size = sizeof ( ctx ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( con , INTERNET_OPTION_CONTEXT_VALUE , & ctx , & size ) ;
2010-05-25 12:19:58 +02:00
ok ( ret , " InternetQueryOption failed %u \n " , GetLastError ( ) ) ;
ok ( ctx = = 0 , " expected 0 got %lu \n " , ctx ) ;
ctx = 2 ;
2013-10-24 12:15:43 +02:00
ret = InternetSetOptionA ( con , INTERNET_OPTION_CONTEXT_VALUE , & ctx , sizeof ( ctx ) ) ;
2010-05-25 12:19:58 +02:00
ok ( ret , " InternetSetOption failed %u \n " , GetLastError ( ) ) ;
ctx = 0xdeadbeef ;
size = sizeof ( ctx ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( con , INTERNET_OPTION_CONTEXT_VALUE , & ctx , & size ) ;
2010-05-25 12:19:58 +02:00
ok ( ret , " InternetQueryOption failed %u \n " , GetLastError ( ) ) ;
ok ( ctx = = 2 , " expected 2 got %lu \n " , ctx ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , " /test1 " , NULL , NULL , NULL , 0 , 0 ) ;
2010-05-25 12:19:58 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ctx = 0xdeadbeef ;
size = sizeof ( ctx ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( req , INTERNET_OPTION_CONTEXT_VALUE , & ctx , & size ) ;
2010-05-25 12:19:58 +02:00
ok ( ret , " InternetQueryOption failed %u \n " , GetLastError ( ) ) ;
ok ( ctx = = 0 , " expected 0 got %lu \n " , ctx ) ;
ctx = 3 ;
2013-10-24 12:15:43 +02:00
ret = InternetSetOptionA ( req , INTERNET_OPTION_CONTEXT_VALUE , & ctx , sizeof ( ctx ) ) ;
2010-05-25 12:19:58 +02:00
ok ( ret , " InternetSetOption failed %u \n " , GetLastError ( ) ) ;
ctx = 0xdeadbeef ;
size = sizeof ( ctx ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( req , INTERNET_OPTION_CONTEXT_VALUE , & ctx , & size ) ;
2010-05-25 12:19:58 +02:00
ok ( ret , " InternetQueryOption failed %u \n " , GetLastError ( ) ) ;
ok ( ctx = = 3 , " expected 3 got %lu \n " , ctx ) ;
2013-05-03 15:19:11 +02:00
size = sizeof ( idsi ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( req , INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO , & idsi , & size ) ;
2013-05-03 15:19:11 +02:00
ok ( ret , " InternetQueryOption failed %u \n " , GetLastError ( ) ) ;
2013-05-03 15:19:22 +02:00
size = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( req , INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT , NULL , & size ) ;
2013-05-03 15:19:22 +02:00
error = GetLastError ( ) ;
ok ( ! ret , " InternetQueryOption succeeded \n " ) ;
ok ( error = = ERROR_INTERNET_INVALID_OPERATION , " expected ERROR_INTERNET_INVALID_OPERATION, got %u \n " , error ) ;
2011-08-23 21:01:44 +02:00
/* INTERNET_OPTION_PROXY */
SetLastError ( 0xdeadbeef ) ;
ret = InternetQueryOptionA ( ses , INTERNET_OPTION_PROXY , NULL , NULL ) ;
error = GetLastError ( ) ;
ok ( ! ret , " InternetQueryOption succeeded \n " ) ;
ok ( error = = ERROR_INVALID_PARAMETER , " expected ERROR_INVALID_PARAMETER, got %u \n " , error ) ;
SetLastError ( 0xdeadbeef ) ;
ret = InternetQueryOptionA ( ses , INTERNET_OPTION_PROXY , & ctx , NULL ) ;
error = GetLastError ( ) ;
ok ( ! ret , " InternetQueryOption succeeded \n " ) ;
ok ( error = = ERROR_INVALID_PARAMETER , " expected ERROR_INVALID_PARAMETER, got %u \n " , error ) ;
size = 0 ;
SetLastError ( 0xdeadbeef ) ;
ret = InternetQueryOptionA ( ses , INTERNET_OPTION_PROXY , NULL , & size ) ;
error = GetLastError ( ) ;
ok ( ! ret , " InternetQueryOption succeeded \n " ) ;
ok ( error = = ERROR_INSUFFICIENT_BUFFER , " expected ERROR_INSUFFICIENT_BUFFER, got %u \n " , error ) ;
ok ( size > = sizeof ( INTERNET_PROXY_INFOA ) , " expected size to be greater or equal to the struct size \n " ) ;
2010-05-25 12:19:58 +02:00
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2013-07-12 15:05:57 +02:00
typedef struct {
const char * response_text ;
int status_code ;
const char * status_text ;
const char * raw_headers ;
} http_status_test_t ;
static const http_status_test_t http_status_tests [ ] = {
{
" HTTP/1.1 200 OK \r \n "
" Content-Length: 1 \r \n "
" \r \n x " ,
200 ,
" OK "
} ,
{
" HTTP/1.1 404 Fail \r \n "
" Content-Length: 1 \r \n "
" \r \n x " ,
404 ,
" Fail "
2013-07-19 12:02:18 +02:00
} ,
{
" HTTP/1.1 200 \r \n "
" Content-Length: 1 \r \n "
" \r \n x " ,
200 ,
" "
} ,
{
" HTTP/1.1 410 \r \n "
" Content-Length: 1 \r \n "
" \r \n x " ,
410 ,
" "
2013-07-12 15:05:57 +02:00
}
} ;
static void test_http_status ( int port )
{
HINTERNET ses , con , req ;
char buf [ 1000 ] ;
DWORD i , size ;
BOOL res ;
for ( i = 0 ; i < sizeof ( http_status_tests ) / sizeof ( * http_status_tests ) ; i + + ) {
send_buffer = http_status_tests [ i ] . response_text ;
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( NULL , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2013-07-12 15:05:57 +02:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2013-07-12 15:05:57 +02:00
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , NULL , " /send_from_buffer " , NULL , NULL , NULL , 0 , 0 ) ;
2013-07-12 15:05:57 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
res = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2013-07-12 15:05:57 +02:00
ok ( res , " HttpSendRequest failed \n " ) ;
test_status_code ( req , http_status_tests [ i ] . status_code ) ;
size = sizeof ( buf ) ;
2013-10-24 12:15:43 +02:00
res = HttpQueryInfoA ( req , HTTP_QUERY_STATUS_TEXT , buf , & size , NULL ) ;
2013-07-12 15:05:57 +02:00
ok ( res , " HttpQueryInfo failed: %u \n " , GetLastError ( ) ) ;
ok ( ! strcmp ( buf , http_status_tests [ i ] . status_text ) , " [%u] Unexpected status text \" %s \" , expected \" %s \" \n " ,
i , buf , http_status_tests [ i ] . status_text ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
}
2013-07-30 11:08:49 +02:00
static void test_cache_control_verb ( int port )
{
HINTERNET session , connect , request ;
BOOL ret ;
2013-10-24 12:15:43 +02:00
session = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2013-07-30 11:08:49 +02:00
ok ( session ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
connect = InternetConnectA ( session , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2013-07-30 11:08:49 +02:00
ok ( connect ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
request = HttpOpenRequestA ( connect , " RPC_OUT_DATA " , " /test_cache_control_verb " , NULL , NULL , NULL ,
2013-07-30 11:08:49 +02:00
INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2013-07-30 11:08:49 +02:00
ok ( ret , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
test_status_code ( request , 200 ) ;
2014-03-24 16:25:16 +01:00
InternetCloseHandle ( request ) ;
2013-07-30 11:08:49 +02:00
2013-10-24 12:15:43 +02:00
request = HttpOpenRequestA ( connect , " POST " , " /test_cache_control_verb " , NULL , NULL , NULL ,
2013-07-30 11:08:49 +02:00
INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2013-07-30 11:08:49 +02:00
ok ( ret , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
test_status_code ( request , 200 ) ;
2014-03-24 16:25:16 +01:00
InternetCloseHandle ( request ) ;
2013-07-30 11:08:49 +02:00
2013-10-24 12:15:43 +02:00
request = HttpOpenRequestA ( connect , " HEAD " , " /test_cache_control_verb " , NULL , NULL , NULL ,
2013-07-30 11:08:49 +02:00
INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2013-07-30 11:08:49 +02:00
ok ( ret , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
test_status_code ( request , 200 ) ;
2014-03-24 16:25:16 +01:00
InternetCloseHandle ( request ) ;
2013-07-30 11:08:49 +02:00
2013-10-24 12:15:43 +02:00
request = HttpOpenRequestA ( connect , " GET " , " /test_cache_control_verb " , NULL , NULL , NULL ,
2013-07-30 11:08:49 +02:00
INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2013-07-30 11:08:49 +02:00
ok ( ret , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
test_status_code ( request , 200 ) ;
InternetCloseHandle ( request ) ;
2014-03-24 16:25:16 +01:00
2013-07-30 11:08:49 +02:00
InternetCloseHandle ( connect ) ;
InternetCloseHandle ( session ) ;
}
2014-12-19 16:50:17 +01:00
static void test_request_content_length ( int port )
{
char data [ ] = { ' t ' , ' e ' , ' s ' , ' t ' } ;
HINTERNET ses , con , req ;
BOOL ret ;
hCompleteEvent = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
req = HttpOpenRequestA ( con , " POST " , " /test_request_content_length " , NULL , NULL , NULL ,
INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
test_status_code ( req , 200 ) ;
SetEvent ( hCompleteEvent ) ;
ret = HttpSendRequestA ( req , NULL , 0 , data , sizeof ( data ) ) ;
ok ( ret , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
test_status_code ( req , 200 ) ;
SetEvent ( hCompleteEvent ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
CloseHandle ( hCompleteEvent ) ;
}
2014-12-08 02:51:30 +01:00
static void test_accept_encoding ( int port )
{
HINTERNET ses , con , req ;
BOOL ret ;
2015-09-22 15:59:01 +02:00
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2014-12-08 02:51:30 +01:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
req = HttpOpenRequestA ( con , " GET " , " /test_accept_encoding_http10 " , " HTTP/1.0 " , NULL , NULL , 0 , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpAddRequestHeadersA ( req , " Accept-Encoding: gzip \r \n " , ~ 0u , HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD ) ;
ok ( ret , " HttpAddRequestHeaders failed \n " ) ;
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequestA failed \n " ) ;
test_status_code ( req , 200 ) ;
InternetCloseHandle ( req ) ;
req = HttpOpenRequestA ( con , " GET " , " /test_accept_encoding_http10 " , " HTTP/1.0 " , NULL , NULL , 0 , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpSendRequestA ( req , " Accept-Encoding: gzip " , ~ 0u , NULL , 0 ) ;
ok ( ret , " HttpSendRequestA failed \n " ) ;
test_status_code ( req , 200 ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2015-04-30 11:50:26 +02:00
static void test_basic_auth_credentials_reuse ( int port )
{
HINTERNET ses , con , req ;
DWORD status , size ;
BOOL ret ;
2015-09-22 15:59:01 +02:00
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2015-04-30 11:50:26 +02:00
ok ( ses ! = NULL , " InternetOpenA failed \n " ) ;
con = InternetConnectA ( ses , " localhost " , port , " user " , " pwd " ,
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( con ! = NULL , " InternetConnectA failed %u \n " , GetLastError ( ) ) ;
req = HttpOpenRequestA ( con , " HEAD " , " /upload.txt " , NULL , NULL , NULL , 0 , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequestA failed %u \n " , GetLastError ( ) ) ;
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequestA failed %u \n " , GetLastError ( ) ) ;
status = 0xdeadbeef ;
size = sizeof ( status ) ;
ret = HttpQueryInfoA ( req , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
ok ( ret , " HttpQueryInfoA failed %u \n " , GetLastError ( ) ) ;
ok ( status = = 200 , " got %u \n " , status ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
2015-09-22 15:59:01 +02:00
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2015-04-30 11:50:26 +02:00
ok ( ses ! = NULL , " InternetOpenA failed \n " ) ;
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL ,
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( con ! = NULL , " InternetConnectA failed %u \n " , GetLastError ( ) ) ;
req = HttpOpenRequestA ( con , " PUT " , " /upload2.txt " , NULL , NULL , NULL , 0 , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequestA failed %u \n " , GetLastError ( ) ) ;
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequestA failed %u \n " , GetLastError ( ) ) ;
status = 0xdeadbeef ;
size = sizeof ( status ) ;
ret = HttpQueryInfoA ( req , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
ok ( ret , " HttpQueryInfoA failed %u \n " , GetLastError ( ) ) ;
ok ( status = = 200 , " got %u \n " , status ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2016-04-28 05:10:07 +02:00
static void test_async_read ( int port )
{
HINTERNET ses , con , req ;
INTERNET_BUFFERSA ib ;
char buffer [ 0x100 ] ;
DWORD pending_reads ;
2016-04-28 05:15:25 +02:00
DWORD res , count , bytes ;
2016-04-28 05:10:07 +02:00
BOOL ret ;
hCompleteEvent = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
conn_wait_event = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
/* test asynchronous InternetReadFileEx */
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
ok ( ses ! = NULL , " InternetOpenA failed \n " ) ;
pInternetSetStatusCallbackA ( ses , & callback ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0xdeadbeef ) ;
ok ( con ! = NULL , " InternetConnectA failed %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
req = HttpOpenRequestA ( con , " GET " , " /async_read " , NULL , NULL , NULL , INTERNET_FLAG_RELOAD , 0xdeadbeef ) ;
ok ( req ! = NULL , " HttpOpenRequestA failed %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
SET_OPTIONAL ( INTERNET_STATUS_DETECTING_PROXY ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_OPTIONAL ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_OPTIONAL ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
SetLastError ( 0xdeadbeef ) ;
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ! ret , " HttpSendRequestA unexpectedly succeeded \n " ) ;
ok ( GetLastError ( ) = = ERROR_IO_PENDING , " expected ERROR_IO_PENDING, got %u \n " , GetLastError ( ) ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( req_error = = ERROR_SUCCESS , " expected ERROR_SUCCESS, got %u \n " , req_error ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
pending_reads = 0 ;
memset ( & ib , 0 , sizeof ( ib ) ) ;
memset ( buffer , 0 , sizeof ( buffer ) ) ;
ib . dwStructSize = sizeof ( ib ) ;
for ( count = 0 ; count < sizeof ( buffer ) ; count + = ib . dwBufferLength )
{
ib . lpvBuffer = buffer + count ;
ib . dwBufferLength = min ( 16 , sizeof ( buffer ) - count ) ;
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
ret = InternetReadFileExA ( req , & ib , 0 , 0xdeadbeef ) ;
if ( ! count ) /* the first part should arrive immediately */
ok ( ret , " InternetReadFileExA failed %u \n " , GetLastError ( ) ) ;
if ( ! ret )
{
ok ( GetLastError ( ) = = ERROR_IO_PENDING , " expected ERROR_IO_PENDING, got %u \n " , GetLastError ( ) ) ;
2016-04-28 05:12:49 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
2016-04-28 05:10:07 +02:00
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
if ( ! pending_reads + + )
{
res = WaitForSingleObject ( hCompleteEvent , 0 ) ;
ok ( res = = WAIT_TIMEOUT , " expected WAIT_TIMEOUT, got %u \n " , res ) ;
SetEvent ( conn_wait_event ) ;
}
res = WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( res = = WAIT_OBJECT_0 , " expected WAIT_OBJECT_0, got %u \n " , res ) ;
ok ( req_error = = ERROR_SUCCESS , " expected ERROR_SUCCESS, got %u \n " , req_error ) ;
todo_wine_if ( pending_reads > 1 )
ok ( ib . dwBufferLength ! = 0 , " expected ib.dwBufferLength != 0 \n " ) ;
2016-04-28 05:12:49 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
2016-04-28 05:10:07 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
}
CLEAR_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
if ( ! ib . dwBufferLength ) break ;
}
2016-04-28 05:15:25 +02:00
todo_wine
ok ( pending_reads = = 1 , " expected 1 pending read, got %u \n " , pending_reads ) ;
ok ( ! strcmp ( buffer , page1 ) , " unexpected buffer content \n " ) ;
close_async_handle ( ses , hCompleteEvent , 2 ) ;
ResetEvent ( conn_wait_event ) ;
/* test asynchronous InternetReadFile */
ses = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
ok ( ses ! = NULL , " InternetOpenA failed \n " ) ;
pInternetSetStatusCallbackA ( ses , & callback ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
con = InternetConnectA ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0xdeadbeef ) ;
ok ( con ! = NULL , " InternetConnectA failed %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
req = HttpOpenRequestA ( con , " GET " , " /async_read " , NULL , NULL , NULL , INTERNET_FLAG_RELOAD , 0xdeadbeef ) ;
ok ( req ! = NULL , " HttpOpenRequestA failed %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
SET_OPTIONAL ( INTERNET_STATUS_DETECTING_PROXY ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_OPTIONAL ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_OPTIONAL ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
SetLastError ( 0xdeadbeef ) ;
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
ok ( ! ret , " HttpSendRequestA unexpectedly succeeded \n " ) ;
ok ( GetLastError ( ) = = ERROR_IO_PENDING , " expected ERROR_IO_PENDING, got %u \n " , GetLastError ( ) ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( req_error = = ERROR_SUCCESS , " expected ERROR_SUCCESS, got %u \n " , req_error ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
pending_reads = 0 ;
memset ( buffer , 0 , sizeof ( buffer ) ) ;
for ( count = 0 ; count < sizeof ( buffer ) ; count + = bytes )
{
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
bytes = 0xdeadbeef ;
ret = InternetReadFile ( req , buffer + count , min ( 16 , sizeof ( buffer ) - count ) , & bytes ) ;
if ( ! count ) /* the first part should arrive immediately */
ok ( ret , " InternetReadFile failed %u \n " , GetLastError ( ) ) ;
if ( ! ret )
{
ok ( GetLastError ( ) = = ERROR_IO_PENDING , " expected ERROR_IO_PENDING, got %u \n " , GetLastError ( ) ) ;
ok ( bytes = = 0 , " expected 0, got %u \n " , bytes ) ;
todo_wine
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
if ( ! pending_reads + + )
{
res = WaitForSingleObject ( hCompleteEvent , 0 ) ;
ok ( res = = WAIT_TIMEOUT , " expected WAIT_TIMEOUT, got %u \n " , res ) ;
SetEvent ( conn_wait_event ) ;
}
res = WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( res = = WAIT_OBJECT_0 , " expected WAIT_OBJECT_0, got %u \n " , res ) ;
ok ( req_error = = ERROR_SUCCESS , " expected ERROR_SUCCESS, got %u \n " , req_error ) ;
todo_wine_if ( pending_reads > 1 )
ok ( bytes ! = 0 , " expected bytes != 0 \n " ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
}
CLEAR_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
if ( ! bytes ) break ;
}
2016-04-28 05:10:07 +02:00
todo_wine
ok ( pending_reads = = 1 , " expected 1 pending read, got %u \n " , pending_reads ) ;
ok ( ! strcmp ( buffer , page1 ) , " unexpected buffer content \n " ) ;
close_async_handle ( ses , hCompleteEvent , 2 ) ;
CloseHandle ( hCompleteEvent ) ;
CloseHandle ( conn_wait_event ) ;
}
2016-05-04 12:40:03 +02:00
typedef struct {
HINTERNET session ;
HINTERNET connection ;
HINTERNET request ;
} test_request_t ;
static void server_send_string ( const char * msg )
{
send ( server_socket , msg , strlen ( msg ) , 0 ) ;
}
static void WINAPI readex_callback ( HINTERNET handle , DWORD_PTR context , DWORD status , void * info , DWORD info_size )
{
switch ( status ) {
case INTERNET_STATUS_RECEIVING_RESPONSE :
case INTERNET_STATUS_RESPONSE_RECEIVED :
break ;
default :
callback ( handle , context , status , info , info_size ) ;
}
}
static void open_read_test_request ( int port , test_request_t * req , const char * response )
{
BOOL ret ;
req - > session = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
ok ( req - > session ! = NULL , " InternetOpenA failed \n " ) ;
pInternetSetStatusCallbackA ( req - > session , readex_callback ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
req - > connection = InternetConnectA ( req - > session , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0xdeadbeef ) ;
ok ( req - > connection ! = NULL , " InternetConnectA failed %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
req - > request = HttpOpenRequestA ( req - > connection , " GET " , " /socket " , NULL , NULL , NULL , INTERNET_FLAG_RELOAD , 0xdeadbeef ) ;
ok ( req - > request ! = NULL , " HttpOpenRequestA failed %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
SET_OPTIONAL ( INTERNET_STATUS_DETECTING_PROXY ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_SENT ) ;
SetLastError ( 0xdeadbeef ) ;
ret = HttpSendRequestA ( req - > request , NULL , 0 , NULL , 0 ) ;
ok ( ! ret , " HttpSendRequestA unexpectedly succeeded \n " ) ;
ok ( GetLastError ( ) = = ERROR_IO_PENDING , " expected ERROR_IO_PENDING, got %u \n " , GetLastError ( ) ) ;
ok ( req_error = = ERROR_SUCCESS , " expected ERROR_SUCCESS, got %u \n " , req_error ) ;
WaitForSingleObject ( server_req_rec_event , INFINITE ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
server_send_string ( response ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
}
# define readex_expect_sync_data(a,b,c,d,e) _readex_expect_sync_data(__LINE__,a,b,c,d,e)
static void _readex_expect_sync_data ( unsigned line , HINTERNET req , DWORD flags , INTERNET_BUFFERSW * buf ,
DWORD buf_size , const char * exdata )
{
DWORD len = strlen ( exdata ) ;
BOOL ret ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
memset ( buf - > lpvBuffer , 0xff , buf_size ) ;
buf - > dwBufferLength = buf_size ;
ret = InternetReadFileExW ( req , buf , flags , 0xdeadbeef ) ;
ok_ ( __FILE__ , line ) ( ret , " InternetReadFileExW failed: %u \n " , GetLastError ( ) ) ;
ok_ ( __FILE__ , line ) ( buf - > dwBufferLength = = len , " dwBufferLength = %u, expected %u \n " , buf - > dwBufferLength , len ) ;
if ( len )
ok_ ( __FILE__ , line ) ( ! memcmp ( buf - > lpvBuffer , exdata , len ) , " Unexpected data \n " ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
}
static void send_response_and_wait ( const char * response , BOOL close_connection , INTERNET_BUFFERSW * buf )
{
DWORD orig_size = buf - > dwBufferLength ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
if ( response )
server_send_string ( response ) ;
if ( close_connection ) {
char c ;
SetEvent ( conn_wait_event ) ;
recv ( server_socket , & c , 1 , 0 ) ;
}
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
/* If IRF_NO_WAIT is used, buffer is not changed. */
ok ( buf - > dwBufferLength = = orig_size , " dwBufferLength = %u \n " , buf - > dwBufferLength ) ;
ok ( ! * ( int * ) buf - > lpvBuffer , " buffer data changed \n " ) ;
}
static void readex_expect_async ( HINTERNET req , DWORD flags , INTERNET_BUFFERSW * buf , DWORD buf_size )
{
BOOL ret ;
memset ( buf - > lpvBuffer , 0 , buf_size ) ;
buf - > dwBufferLength = buf_size ;
ret = InternetReadFileExW ( req , buf , flags , 0xdeadbeef ) ;
ok ( ! ret & & GetLastError ( ) = = ERROR_IO_PENDING , " InternetReadFileExW returned %x (%u) \n " , ret , GetLastError ( ) ) ;
ok ( buf - > dwBufferLength = = buf_size , " dwBufferLength = %u, expected %u \n " , buf - > dwBufferLength , buf_size ) ;
ok ( ! * ( int * ) buf - > lpvBuffer , " buffer data changed \n " ) ;
}
static void test_http_read ( int port )
{
INTERNET_BUFFERSW ib ;
test_request_t req ;
char buf [ 4096 ] ;
hCompleteEvent = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
conn_wait_event = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
server_req_rec_event = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
trace ( " Testing InternetReadFileExW with IRF_NO_WAIT flag... \n " ) ;
open_read_test_request ( port , & req ,
" HTTP/1.1 200 OK \r \n "
" Server: winetest \r \n "
" \r \n "
" xx " ) ;
memset ( & ib , 0 , sizeof ( ib ) ) ;
ib . dwStructSize = sizeof ( ib ) ;
ib . lpvBuffer = buf ;
readex_expect_sync_data ( req . request , IRF_NO_WAIT , & ib , sizeof ( buf ) , " xx " ) ;
readex_expect_async ( req . request , IRF_NO_WAIT , & ib , sizeof ( buf ) ) ;
send_response_and_wait ( " 1234567890 " , FALSE , & ib ) ;
readex_expect_sync_data ( req . request , IRF_NO_WAIT , & ib , 5 , " 12345 " ) ;
readex_expect_sync_data ( req . request , IRF_NO_WAIT , & ib , sizeof ( buf ) , " 67890 " ) ;
readex_expect_async ( req . request , IRF_NO_WAIT , & ib , sizeof ( buf ) ) ;
send_response_and_wait ( " 12345 " , TRUE , & ib ) ;
readex_expect_sync_data ( req . request , IRF_NO_WAIT , & ib , sizeof ( buf ) , " 12345 " ) ;
readex_expect_sync_data ( req . request , IRF_NO_WAIT , & ib , sizeof ( buf ) , " " ) ;
close_async_handle ( req . session , hCompleteEvent , 2 ) ;
CloseHandle ( hCompleteEvent ) ;
CloseHandle ( conn_wait_event ) ;
CloseHandle ( server_req_rec_event ) ;
}
2006-05-30 15:55:16 +02:00
static void test_http_connection ( void )
{
struct server_info si ;
HANDLE hThread ;
DWORD id = 0 , r ;
2013-10-24 12:15:43 +02:00
si . hEvent = CreateEventW ( NULL , 0 , 0 , NULL ) ;
2006-05-30 15:55:16 +02:00
si . port = 7531 ;
hThread = CreateThread ( NULL , 0 , server_thread , ( LPVOID ) & si , 0 , & id ) ;
ok ( hThread ! = NULL , " create thread failed \n " ) ;
r = WaitForSingleObject ( si . hEvent , 10000 ) ;
ok ( r = = WAIT_OBJECT_0 , " failed to start wininet test server \n " ) ;
if ( r ! = WAIT_OBJECT_0 )
return ;
2008-02-02 16:08:28 +01:00
test_basic_request ( si . port , " GET " , " /test1 " ) ;
2006-05-30 15:55:16 +02:00
test_proxy_indirect ( si . port ) ;
test_proxy_direct ( si . port ) ;
2007-08-09 21:43:25 +02:00
test_header_handling_order ( si . port ) ;
2008-02-02 16:08:28 +01:00
test_basic_request ( si . port , " POST " , " /test5 " ) ;
2009-01-14 16:20:11 +01:00
test_basic_request ( si . port , " RPC_IN_DATA " , " /test5 " ) ;
test_basic_request ( si . port , " RPC_OUT_DATA " , " /test5 " ) ;
2008-02-17 20:41:56 +01:00
test_basic_request ( si . port , " GET " , " /test6 " ) ;
2009-06-23 07:30:38 +02:00
test_basic_request ( si . port , " GET " , " /testF " ) ;
2008-05-31 21:47:24 +02:00
test_connection_header ( si . port ) ;
2015-06-25 12:27:30 +02:00
test_header_override ( si . port ) ;
2008-07-02 09:56:12 +02:00
test_http1_1 ( si . port ) ;
2008-07-19 19:55:39 +02:00
test_cookie_header ( si . port ) ;
2008-10-17 13:46:52 +02:00
test_basic_authentication ( si . port ) ;
2009-03-04 12:44:22 +01:00
test_invalid_response_headers ( si . port ) ;
2009-09-29 21:50:12 +02:00
test_response_without_headers ( si . port ) ;
2008-12-01 15:35:05 +01:00
test_HttpQueryInfo ( si . port ) ;
2009-01-15 16:41:53 +01:00
test_HttpSendRequestW ( si . port ) ;
2010-05-25 12:19:58 +02:00
test_options ( si . port ) ;
2011-05-13 13:49:00 +02:00
test_no_content ( si . port ) ;
2011-05-23 16:10:22 +02:00
test_conn_close ( si . port ) ;
2013-03-13 17:06:01 +01:00
test_no_cache ( si . port ) ;
2013-04-30 17:00:36 +02:00
test_cache_read_gzipped ( si . port ) ;
2013-07-12 15:05:57 +02:00
test_http_status ( si . port ) ;
2013-04-17 15:32:54 +02:00
test_premature_disconnect ( si . port ) ;
2013-06-05 17:35:41 +02:00
test_connection_closing ( si . port ) ;
2013-07-30 11:08:49 +02:00
test_cache_control_verb ( si . port ) ;
2013-11-26 00:12:04 +01:00
test_successive_HttpSendRequest ( si . port ) ;
2014-06-25 14:41:47 +02:00
test_head_request ( si . port ) ;
2014-12-19 16:50:17 +01:00
test_request_content_length ( si . port ) ;
2014-12-08 02:51:30 +01:00
test_accept_encoding ( si . port ) ;
2015-04-30 11:50:26 +02:00
test_basic_auth_credentials_reuse ( si . port ) ;
2016-04-28 05:10:07 +02:00
test_async_read ( si . port ) ;
2016-05-04 12:40:03 +02:00
test_http_read ( si . port ) ;
2006-05-30 15:55:16 +02:00
/* send the basic request again to shutdown the server thread */
2008-02-02 16:08:28 +01:00
test_basic_request ( si . port , " GET " , " /quit " ) ;
2006-05-16 16:03:45 +02:00
r = WaitForSingleObject ( hThread , 3000 ) ;
ok ( r = = WAIT_OBJECT_0 , " thread wait failed \n " ) ;
CloseHandle ( hThread ) ;
}
2005-11-22 15:53:30 +01:00
2011-01-13 13:54:38 +01:00
static void release_cert_info ( INTERNET_CERTIFICATE_INFOA * info )
{
LocalFree ( info - > lpszSubjectInfo ) ;
LocalFree ( info - > lpszIssuerInfo ) ;
LocalFree ( info - > lpszProtocolName ) ;
LocalFree ( info - > lpszSignatureAlgName ) ;
LocalFree ( info - > lpszEncryptionAlgName ) ;
}
2013-06-14 15:18:18 +02:00
typedef struct {
const char * ex_subject ;
const char * ex_issuer ;
} cert_struct_test_t ;
static const cert_struct_test_t test_winehq_org_cert = {
" *.winehq.org " ,
" US \r \n "
2014-09-25 14:21:06 +02:00
" GeoTrust Inc. \r \n "
2016-05-13 18:46:21 +02:00
" RapidSSL SHA256 CA "
2013-06-14 15:18:18 +02:00
} ;
static const cert_struct_test_t test_winehq_com_cert = {
" US \r \n "
" Minnesota \r \n "
" Saint Paul \r \n "
" WineHQ \r \n "
" test.winehq.com \r \n "
" webmaster@winehq.org " ,
" US \r \n "
" Minnesota \r \n "
" WineHQ \r \n "
" test.winehq.com \r \n "
" webmaster@winehq.org "
} ;
static void test_cert_struct ( HINTERNET req , const cert_struct_test_t * test )
2012-05-30 12:13:53 +02:00
{
INTERNET_CERTIFICATE_INFOA info ;
DWORD size ;
BOOL res ;
2012-08-19 00:41:48 +02:00
memset ( & info , 0x5 , sizeof ( info ) ) ;
2012-05-30 12:13:53 +02:00
size = sizeof ( info ) ;
2013-10-24 12:15:43 +02:00
res = InternetQueryOptionA ( req , INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT , & info , & size ) ;
2012-05-30 12:13:53 +02:00
ok ( res , " InternetQueryOption failed: %u \n " , GetLastError ( ) ) ;
ok ( size = = sizeof ( info ) , " size = %u \n " , size ) ;
2013-06-14 15:18:18 +02:00
ok ( ! strcmp ( info . lpszSubjectInfo , test - > ex_subject ) , " lpszSubjectInfo = %s \n " , info . lpszSubjectInfo ) ;
ok ( ! strcmp ( info . lpszIssuerInfo , test - > ex_issuer ) , " lpszIssuerInfo = %s \n " , info . lpszIssuerInfo ) ;
2012-05-30 12:13:53 +02:00
ok ( ! info . lpszSignatureAlgName , " lpszSignatureAlgName = %s \n " , info . lpszSignatureAlgName ) ;
ok ( ! info . lpszEncryptionAlgName , " lpszEncryptionAlgName = %s \n " , info . lpszEncryptionAlgName ) ;
ok ( ! info . lpszProtocolName , " lpszProtocolName = %s \n " , info . lpszProtocolName ) ;
2014-10-30 05:16:42 +01:00
ok ( info . dwKeySize > = 128 & & info . dwKeySize < = 256 , " dwKeySize = %u \n " , info . dwKeySize ) ;
2012-05-30 12:13:53 +02:00
release_cert_info ( & info ) ;
}
2012-06-11 10:22:54 +02:00
# define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
static void _test_security_info ( unsigned line , const char * urlc , DWORD error , DWORD ex_flags )
{
char url [ INTERNET_MAX_URL_LENGTH ] ;
const CERT_CHAIN_CONTEXT * chain ;
DWORD flags ;
BOOL res ;
if ( ! pInternetGetSecurityInfoByURLA ) {
win_skip ( " pInternetGetSecurityInfoByURLA not available \n " ) ;
return ;
}
strcpy ( url , urlc ) ;
chain = ( void * ) 0xdeadbeef ;
flags = 0xdeadbeef ;
res = pInternetGetSecurityInfoByURLA ( url , & chain , & flags ) ;
if ( error = = ERROR_SUCCESS ) {
ok_ ( __FILE__ , line ) ( res , " InternetGetSecurityInfoByURLA failed: %u \n " , GetLastError ( ) ) ;
ok_ ( __FILE__ , line ) ( chain ! = NULL , " chain = NULL \n " ) ;
ok_ ( __FILE__ , line ) ( flags = = ex_flags , " flags = %x \n " , flags ) ;
CertFreeCertificateChain ( chain ) ;
} else {
ok_ ( __FILE__ , line ) ( ! res & & GetLastError ( ) = = error ,
2015-08-31 12:24:53 +02:00
" InternetGetSecurityInfoByURLA returned: %x(%u), expected %u \n " , res , GetLastError ( ) , error ) ;
2012-06-11 10:22:54 +02:00
}
}
2014-09-04 11:34:59 +02:00
# define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)
static void _test_secflags_option ( unsigned line , HINTERNET req , DWORD ex_flags , DWORD opt_flags )
2012-05-25 16:36:46 +02:00
{
DWORD flags , size ;
BOOL res ;
flags = 0xdeadbeef ;
size = sizeof ( flags ) ;
res = InternetQueryOptionW ( req , INTERNET_OPTION_SECURITY_FLAGS , & flags , & size ) ;
ok_ ( __FILE__ , line ) ( res , " InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u \n " , GetLastError ( ) ) ;
2014-09-04 11:34:59 +02:00
ok_ ( __FILE__ , line ) ( ( flags & ~ opt_flags ) = = ex_flags , " INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x \n " ,
flags , ex_flags ) ;
2012-06-04 18:01:19 +02:00
/* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
flags = 0xdeadbeef ;
size = sizeof ( flags ) ;
res = InternetQueryOptionW ( req , 98 , & flags , & size ) ;
2012-06-08 15:02:51 +02:00
ok_ ( __FILE__ , line ) ( res , " InternetQueryOptionW(98) failed: %u \n " , GetLastError ( ) ) ;
2014-09-04 11:34:59 +02:00
ok_ ( __FILE__ , line ) ( ( flags & ~ opt_flags ) = = ex_flags , " INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x \n " ,
flags , ex_flags ) ;
2012-05-25 16:36:46 +02:00
}
2012-06-07 15:40:56 +02:00
# define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
static void _set_secflags ( unsigned line , HINTERNET req , BOOL use_undoc , DWORD flags )
2012-05-25 16:36:46 +02:00
{
BOOL res ;
2012-06-07 15:40:56 +02:00
res = InternetSetOptionW ( req , use_undoc ? 99 : INTERNET_OPTION_SECURITY_FLAGS , & flags , sizeof ( flags ) ) ;
2012-05-25 16:36:46 +02:00
ok_ ( __FILE__ , line ) ( res , " InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u \n " , GetLastError ( ) ) ;
}
static void test_security_flags ( void )
{
2013-12-11 10:49:34 +01:00
INTERNET_CERTIFICATE_INFOA * cert ;
2012-05-25 16:36:46 +02:00
HINTERNET ses , conn , req ;
DWORD size , flags ;
char buf [ 100 ] ;
BOOL res ;
trace ( " Testing security flags... \n " ) ;
2013-10-24 12:15:43 +02:00
hCompleteEvent = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
2012-05-25 16:36:46 +02:00
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " WineTest " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
2012-05-25 16:36:46 +02:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
pInternetSetStatusCallbackA ( ses , & callback ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
2013-06-13 15:20:10 +02:00
conn = InternetConnectA ( ses , " test.winehq.com " , INTERNET_DEFAULT_HTTPS_PORT ,
2012-05-25 16:36:46 +02:00
NULL , NULL , INTERNET_SERVICE_HTTP , INTERNET_FLAG_SECURE , 0xdeadbeef ) ;
ok ( conn ! = NULL , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( conn , " GET " , " /tests/hello.html " , NULL , NULL , NULL ,
2012-05-25 16:36:46 +02:00
INTERNET_FLAG_SECURE | INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE ,
0xdeadbeef ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
2012-06-08 15:02:51 +02:00
flags = 0xdeadbeef ;
size = sizeof ( flags ) ;
res = InternetQueryOptionW ( req , 98 , & flags , & size ) ;
if ( ! res & & GetLastError ( ) = = ERROR_INVALID_PARAMETER ) {
win_skip ( " Incomplete security flags support, skipping \n " ) ;
close_async_handle ( ses , hCompleteEvent , 2 ) ;
CloseHandle ( hCompleteEvent ) ;
return ;
}
2014-09-04 11:34:59 +02:00
test_secflags_option ( req , 0 , 0 ) ;
2013-06-13 15:20:10 +02:00
test_security_info ( " https://test.winehq.com/data/some_file.html?q " , ERROR_INTERNET_ITEM_NOT_FOUND , 0 ) ;
2012-06-07 15:40:56 +02:00
set_secflags ( req , TRUE , SECURITY_FLAG_IGNORE_REVOCATION ) ;
2014-09-04 11:34:59 +02:00
test_secflags_option ( req , SECURITY_FLAG_IGNORE_REVOCATION , 0 ) ;
2012-06-07 15:40:56 +02:00
set_secflags ( req , TRUE , SECURITY_FLAG_IGNORE_CERT_CN_INVALID ) ;
2014-09-04 11:34:59 +02:00
test_secflags_option ( req , SECURITY_FLAG_IGNORE_REVOCATION | SECURITY_FLAG_IGNORE_CERT_CN_INVALID , 0 ) ;
2012-06-07 15:40:56 +02:00
set_secflags ( req , FALSE , SECURITY_FLAG_IGNORE_UNKNOWN_CA ) ;
2014-09-04 11:34:59 +02:00
test_secflags_option ( req , SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_IGNORE_REVOCATION | SECURITY_FLAG_IGNORE_CERT_CN_INVALID , 0 ) ;
2012-06-07 15:40:56 +02:00
flags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID | SECURITY_FLAG_SECURE ;
res = InternetSetOptionW ( req , 99 , & flags , sizeof ( flags ) ) ;
ok ( ! res & & GetLastError ( ) = = ERROR_INTERNET_OPTION_NOT_SETTABLE , " InternetSetOption(99) failed: %u \n " , GetLastError ( ) ) ;
2012-05-28 13:54:32 +02:00
SET_EXPECT ( INTERNET_STATUS_RESOLVING_NAME ) ;
SET_EXPECT ( INTERNET_STATUS_NAME_RESOLVED ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2014-09-02 12:37:37 +02:00
SET_OPTIONAL ( INTERNET_STATUS_CLOSING_CONNECTION ) ; /* IE11 calls it, it probably reconnects. */
SET_OPTIONAL ( INTERNET_STATUS_CONNECTION_CLOSED ) ; /* IE11 */
SET_OPTIONAL ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ; /* IE11 */
SET_OPTIONAL ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ; /* IE11 */
2012-05-28 13:54:32 +02:00
SET_EXPECT ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
SET_OPTIONAL ( INTERNET_STATUS_DETECTING_PROXY ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
2013-10-24 12:15:43 +02:00
res = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2012-05-28 13:54:32 +02:00
ok ( ! res & & GetLastError ( ) = = ERROR_IO_PENDING , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( req_error = = ERROR_SUCCESS , " req_error = %d \n " , req_error ) ;
2013-06-13 15:20:10 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
2014-09-02 12:37:37 +02:00
CHECK_NOTIFIED2 ( INTERNET_STATUS_CONNECTING_TO_SERVER , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_CONNECTED_TO_SERVER , 2 ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
2012-05-28 13:54:32 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
test_request_flags ( req , 0 ) ;
2012-06-07 15:40:56 +02:00
test_secflags_option ( req , SECURITY_FLAG_SECURE | SECURITY_FLAG_IGNORE_UNKNOWN_CA
2014-09-04 11:34:59 +02:00
| SECURITY_FLAG_IGNORE_REVOCATION | SECURITY_FLAG_IGNORE_CERT_CN_INVALID | SECURITY_FLAG_STRENGTH_STRONG , 0 ) ;
2012-05-28 13:54:32 +02:00
res = InternetReadFile ( req , buf , sizeof ( buf ) , & size ) ;
ok ( res , " InternetReadFile failed: %u \n " , GetLastError ( ) ) ;
ok ( size , " size = 0 \n " ) ;
/* Collect all existing persistent connections */
res = InternetSetOptionA ( NULL , INTERNET_OPTION_SETTINGS_CHANGED , NULL , 0 ) ;
ok ( res , " InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u \n " , GetLastError ( ) ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( conn , " GET " , " /tests/hello.html " , NULL , NULL , NULL ,
2012-05-28 13:54:32 +02:00
INTERNET_FLAG_SECURE | INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE ,
0xdeadbeef ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
2012-05-25 16:36:46 +02:00
flags = INTERNET_ERROR_MASK_COMBINED_SEC_CERT | INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY ;
2013-10-24 12:15:43 +02:00
res = InternetSetOptionA ( req , INTERNET_OPTION_ERROR_MASK , ( void * ) & flags , sizeof ( flags ) ) ;
2012-05-25 16:36:46 +02:00
ok ( res , " InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u \n " , GetLastError ( ) ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2014-09-02 12:37:37 +02:00
SET_OPTIONAL ( INTERNET_STATUS_CLOSING_CONNECTION ) ; /* IE11 calls it, it probably reconnects. */
SET_OPTIONAL ( INTERNET_STATUS_CONNECTION_CLOSED ) ; /* IE11 */
SET_OPTIONAL ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ; /* IE11 */
SET_OPTIONAL ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ; /* IE11 */
2012-05-25 16:36:46 +02:00
SET_EXPECT ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
SET_OPTIONAL ( INTERNET_STATUS_DETECTING_PROXY ) ;
2013-10-24 12:15:43 +02:00
res = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2012-05-25 16:36:46 +02:00
ok ( ! res & & GetLastError ( ) = = ERROR_IO_PENDING , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( req_error = = ERROR_INTERNET_SEC_CERT_REV_FAILED | | broken ( req_error = = ERROR_INTERNET_SEC_CERT_ERRORS ) ,
" req_error = %d \n " , req_error ) ;
2013-12-11 10:49:34 +01:00
size = 0 ;
res = InternetQueryOptionW ( req , INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT , NULL , & size ) ;
ok ( res | | GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " InternetQueryOption failed: %d \n " , GetLastError ( ) ) ;
ok ( size = = sizeof ( INTERNET_CERTIFICATE_INFOA ) , " size = %u \n " , size ) ;
cert = HeapAlloc ( GetProcessHeap ( ) , 0 , size ) ;
cert - > lpszSubjectInfo = NULL ;
cert - > lpszIssuerInfo = NULL ;
cert - > lpszSignatureAlgName = ( char * ) 0xdeadbeef ;
cert - > lpszEncryptionAlgName = ( char * ) 0xdeadbeef ;
cert - > lpszProtocolName = ( char * ) 0xdeadbeef ;
cert - > dwKeySize = 0xdeadbeef ;
res = InternetQueryOptionW ( req , INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT , cert , & size ) ;
ok ( res , " InternetQueryOption failed: %u \n " , GetLastError ( ) ) ;
if ( res )
{
ok ( cert - > lpszSubjectInfo & & strlen ( cert - > lpszSubjectInfo ) > 1 , " expected a non-empty subject name \n " ) ;
ok ( cert - > lpszIssuerInfo & & strlen ( cert - > lpszIssuerInfo ) > 1 , " expected a non-empty issuer name \n " ) ;
ok ( ! cert - > lpszSignatureAlgName , " unexpected signature algorithm name \n " ) ;
ok ( ! cert - > lpszEncryptionAlgName , " unexpected encryption algorithm name \n " ) ;
ok ( ! cert - > lpszProtocolName , " unexpected protocol name \n " ) ;
ok ( cert - > dwKeySize ! = 0xdeadbeef , " unexpected key size \n " ) ;
}
HeapFree ( GetProcessHeap ( ) , 0 , cert ) ;
2014-09-02 12:37:37 +02:00
CHECK_NOTIFIED2 ( INTERNET_STATUS_CONNECTING_TO_SERVER , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_CONNECTED_TO_SERVER , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_CLOSING_CONNECTION , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_CONNECTION_CLOSED , 2 ) ;
2012-05-25 16:36:46 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
if ( req_error ! = ERROR_INTERNET_SEC_CERT_REV_FAILED ) {
2013-06-14 15:18:18 +02:00
win_skip ( " Unexpected cert errors %u, skipping security flags tests \n " , req_error ) ;
2012-05-25 16:36:46 +02:00
2012-05-28 13:54:32 +02:00
close_async_handle ( ses , hCompleteEvent , 3 ) ;
2012-05-25 16:36:46 +02:00
CloseHandle ( hCompleteEvent ) ;
return ;
}
size = sizeof ( buf ) ;
res = HttpQueryInfoA ( req , HTTP_QUERY_CONTENT_ENCODING , buf , & size , 0 ) ;
ok ( ! res & & GetLastError ( ) = = ERROR_HTTP_HEADER_NOT_FOUND , " HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u \n " , GetLastError ( ) ) ;
test_request_flags ( req , 8 ) ;
2014-09-04 11:34:59 +02:00
/* IE11 finds both rev failure and invalid CA. Previous versions required rev failure
to be ignored before invalid CA was reported . */
test_secflags_option ( req , _SECURITY_FLAG_CERT_REV_FAILED , _SECURITY_FLAG_CERT_INVALID_CA ) ;
2012-05-25 16:36:46 +02:00
2012-06-07 15:40:56 +02:00
set_secflags ( req , FALSE , SECURITY_FLAG_IGNORE_REVOCATION ) ;
2014-09-04 11:34:59 +02:00
test_secflags_option ( req , _SECURITY_FLAG_CERT_REV_FAILED | SECURITY_FLAG_IGNORE_REVOCATION , _SECURITY_FLAG_CERT_INVALID_CA ) ;
2012-06-07 15:40:56 +02:00
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
SET_OPTIONAL ( INTERNET_STATUS_DETECTING_PROXY ) ;
2013-10-24 12:15:43 +02:00
res = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2012-06-07 15:40:56 +02:00
ok ( ! res & & GetLastError ( ) = = ERROR_IO_PENDING , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( req_error = = ERROR_INTERNET_SEC_CERT_ERRORS , " req_error = %d \n " , req_error ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
test_request_flags ( req , INTERNET_REQFLAG_NO_HEADERS ) ;
2014-09-04 11:34:59 +02:00
test_secflags_option ( req , SECURITY_FLAG_IGNORE_REVOCATION | _SECURITY_FLAG_CERT_REV_FAILED | _SECURITY_FLAG_CERT_INVALID_CA , 0 ) ;
2013-06-14 15:18:18 +02:00
test_security_info ( " https://test.winehq.com/data/some_file.html?q " , ERROR_INTERNET_ITEM_NOT_FOUND , 0 ) ;
2012-06-07 15:40:56 +02:00
set_secflags ( req , FALSE , SECURITY_FLAG_IGNORE_UNKNOWN_CA ) ;
2014-09-04 11:34:59 +02:00
test_secflags_option ( req , _SECURITY_FLAG_CERT_INVALID_CA | _SECURITY_FLAG_CERT_REV_FAILED
| SECURITY_FLAG_IGNORE_REVOCATION | SECURITY_FLAG_IGNORE_UNKNOWN_CA , 0 ) ;
2012-05-25 16:36:46 +02:00
test_http_version ( req ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2014-09-02 12:37:37 +02:00
SET_OPTIONAL ( INTERNET_STATUS_CLOSING_CONNECTION ) ; /* IE11 calls it, it probably reconnects. */
SET_OPTIONAL ( INTERNET_STATUS_CONNECTION_CLOSED ) ; /* IE11 */
SET_OPTIONAL ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ; /* IE11 */
SET_OPTIONAL ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ; /* IE11 */
2012-05-25 16:36:46 +02:00
SET_EXPECT ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
SET_OPTIONAL ( INTERNET_STATUS_DETECTING_PROXY ) ;
2013-10-24 12:15:43 +02:00
res = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2012-05-25 16:36:46 +02:00
ok ( ! res & & GetLastError ( ) = = ERROR_IO_PENDING , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( req_error = = ERROR_SUCCESS , " req_error = %d \n " , req_error ) ;
2014-09-02 12:37:37 +02:00
CHECK_NOTIFIED2 ( INTERNET_STATUS_CONNECTING_TO_SERVER , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_CONNECTED_TO_SERVER , 2 ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
2012-05-25 16:36:46 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
test_request_flags ( req , 0 ) ;
2012-06-07 15:40:56 +02:00
test_secflags_option ( req , SECURITY_FLAG_SECURE | SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_IGNORE_REVOCATION
2014-09-04 11:34:59 +02:00
| SECURITY_FLAG_STRENGTH_STRONG | _SECURITY_FLAG_CERT_REV_FAILED | _SECURITY_FLAG_CERT_INVALID_CA , 0 ) ;
2012-05-25 16:36:46 +02:00
2013-06-14 15:18:18 +02:00
test_cert_struct ( req , & test_winehq_com_cert ) ;
2014-09-04 11:34:59 +02:00
test_security_info ( " https://test.winehq.com/data/some_file.html?q " , 0 ,
_SECURITY_FLAG_CERT_INVALID_CA | _SECURITY_FLAG_CERT_REV_FAILED ) ;
2012-05-30 12:13:53 +02:00
2012-05-25 16:36:46 +02:00
res = InternetReadFile ( req , buf , sizeof ( buf ) , & size ) ;
ok ( res , " InternetReadFile failed: %u \n " , GetLastError ( ) ) ;
ok ( size , " size = 0 \n " ) ;
2012-05-28 13:54:32 +02:00
close_async_handle ( ses , hCompleteEvent , 3 ) ;
2012-05-25 16:36:46 +02:00
/* Collect all existing persistent connections */
res = InternetSetOptionA ( NULL , INTERNET_OPTION_SETTINGS_CHANGED , NULL , 0 ) ;
ok ( res , " InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u \n " , GetLastError ( ) ) ;
/* Make another request, without setting security flags */
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " WineTest " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
2012-05-25 16:36:46 +02:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
pInternetSetStatusCallbackA ( ses , & callback ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
2013-06-13 15:20:10 +02:00
conn = InternetConnectA ( ses , " test.winehq.com " , INTERNET_DEFAULT_HTTPS_PORT ,
2012-05-25 16:36:46 +02:00
NULL , NULL , INTERNET_SERVICE_HTTP , INTERNET_FLAG_SECURE , 0xdeadbeef ) ;
ok ( conn ! = NULL , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( conn , " GET " , " /tests/hello.html " , NULL , NULL , NULL ,
2012-05-25 16:36:46 +02:00
INTERNET_FLAG_SECURE | INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE ,
0xdeadbeef ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
2012-06-07 15:40:56 +02:00
test_secflags_option ( req , SECURITY_FLAG_SECURE | SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_STRENGTH_STRONG
2014-09-04 11:34:59 +02:00
| SECURITY_FLAG_IGNORE_REVOCATION | _SECURITY_FLAG_CERT_REV_FAILED | _SECURITY_FLAG_CERT_INVALID_CA , 0 ) ;
2012-05-25 16:36:46 +02:00
test_http_version ( req ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2014-09-02 12:37:37 +02:00
SET_OPTIONAL ( INTERNET_STATUS_CLOSING_CONNECTION ) ; /* IE11 calls it, it probably reconnects. */
SET_OPTIONAL ( INTERNET_STATUS_CONNECTION_CLOSED ) ; /* IE11 */
SET_OPTIONAL ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ; /* IE11 */
SET_OPTIONAL ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ; /* IE11 */
2012-05-25 16:36:46 +02:00
SET_EXPECT ( INTERNET_STATUS_SENDING_REQUEST ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_SENT ) ;
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
SET_OPTIONAL ( INTERNET_STATUS_COOKIE_SENT ) ;
2013-10-24 12:15:43 +02:00
res = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2012-05-25 16:36:46 +02:00
ok ( ! res & & GetLastError ( ) = = ERROR_IO_PENDING , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
ok ( req_error = = ERROR_SUCCESS , " req_error = %d \n " , req_error ) ;
2014-09-02 12:37:37 +02:00
CHECK_NOTIFIED2 ( INTERNET_STATUS_CONNECTING_TO_SERVER , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_CONNECTED_TO_SERVER , 2 ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
2012-05-25 16:36:46 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_SENDING_REQUEST ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_SENT ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_COOKIE_SENT ) ;
test_request_flags ( req , 0 ) ;
2012-06-07 15:40:56 +02:00
test_secflags_option ( req , SECURITY_FLAG_SECURE | SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_STRENGTH_STRONG
2014-09-04 11:34:59 +02:00
| SECURITY_FLAG_IGNORE_REVOCATION | _SECURITY_FLAG_CERT_REV_FAILED | _SECURITY_FLAG_CERT_INVALID_CA , 0 ) ;
2012-05-25 16:36:46 +02:00
res = InternetReadFile ( req , buf , sizeof ( buf ) , & size ) ;
ok ( res , " InternetReadFile failed: %u \n " , GetLastError ( ) ) ;
ok ( size , " size = 0 \n " ) ;
close_async_handle ( ses , hCompleteEvent , 2 ) ;
CloseHandle ( hCompleteEvent ) ;
2012-06-11 10:22:54 +02:00
2013-06-13 15:20:10 +02:00
test_security_info ( " http://test.winehq.com/data/some_file.html?q " , ERROR_INTERNET_ITEM_NOT_FOUND , 0 ) ;
2012-06-11 10:22:54 +02:00
test_security_info ( " file:///c:/dir/file.txt " , ERROR_INTERNET_ITEM_NOT_FOUND , 0 ) ;
test_security_info ( " xxx:///c:/dir/file.txt " , ERROR_INTERNET_ITEM_NOT_FOUND , 0 ) ;
2012-05-25 16:36:46 +02:00
}
2010-09-30 18:53:47 +02:00
static void test_secure_connection ( void )
{
static const WCHAR gizmo5 [ ] = { ' G ' , ' i ' , ' z ' , ' m ' , ' o ' , ' 5 ' , 0 } ;
2013-05-23 19:23:17 +02:00
static const WCHAR testsite [ ] = { ' t ' , ' e ' , ' s ' , ' t ' , ' . ' , ' w ' , ' i ' , ' n ' , ' e ' , ' h ' , ' q ' , ' . ' , ' o ' , ' r ' , ' g ' , 0 } ;
2010-09-30 18:53:47 +02:00
static const WCHAR get [ ] = { ' G ' , ' E ' , ' T ' , 0 } ;
2013-05-23 19:23:17 +02:00
static const WCHAR testpage [ ] = { ' / ' , ' t ' , ' e ' , ' s ' , ' t ' , ' s ' , ' / ' , ' h ' , ' e ' , ' l ' , ' l ' , ' o ' , ' . ' , ' h ' , ' t ' , ' m ' , ' l ' , 0 } ;
2010-09-30 18:53:47 +02:00
HINTERNET ses , con , req ;
DWORD size , flags ;
INTERNET_CERTIFICATE_INFOA * certificate_structA = NULL ;
INTERNET_CERTIFICATE_INFOW * certificate_structW = NULL ;
BOOL ret ;
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " Gizmo5 " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , 0 ) ;
2010-09-30 18:53:47 +02:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
con = InternetConnectA ( ses , " test.winehq.org " ,
2010-09-30 18:53:47 +02:00
INTERNET_DEFAULT_HTTPS_PORT , NULL , NULL ,
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , " GET " , " /tests/hello.html " , NULL , NULL , NULL ,
2010-09-30 18:53:47 +02:00
INTERNET_FLAG_SECURE , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2015-06-12 11:34:13 +02:00
ok ( ret | | broken ( GetLastError ( ) = = ERROR_INTERNET_CANNOT_CONNECT ) ,
" HttpSendRequest failed: %d \n " , GetLastError ( ) ) ;
if ( ! ret )
{
win_skip ( " Cannot connect to https. \n " ) ;
goto done ;
}
2010-09-30 18:53:47 +02:00
size = sizeof ( flags ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( req , INTERNET_OPTION_SECURITY_FLAGS , & flags , & size ) ;
2010-09-30 18:53:47 +02:00
ok ( ret , " InternetQueryOption failed: %d \n " , GetLastError ( ) ) ;
ok ( flags & SECURITY_FLAG_SECURE , " expected secure flag to be set \n " ) ;
2013-06-14 15:18:18 +02:00
test_cert_struct ( req , & test_winehq_org_cert ) ;
2010-09-30 18:53:47 +02:00
/* Querying the same option through InternetQueryOptionW still results in
* ASCII strings being returned .
*/
size = 0 ;
ret = InternetQueryOptionW ( req , INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT ,
NULL , & size ) ;
ok ( ret | | GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " InternetQueryOption failed: %d \n " , GetLastError ( ) ) ;
2011-01-13 13:54:38 +01:00
ok ( size = = sizeof ( INTERNET_CERTIFICATE_INFOW ) , " size = %d \n " , size ) ;
2010-09-30 18:53:47 +02:00
certificate_structW = HeapAlloc ( GetProcessHeap ( ) , 0 , size ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( req , INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT ,
2010-09-30 18:53:47 +02:00
certificate_structW , & size ) ;
certificate_structA = ( INTERNET_CERTIFICATE_INFOA * ) certificate_structW ;
ok ( ret , " InternetQueryOption failed: %d \n " , GetLastError ( ) ) ;
if ( ret )
{
ok ( certificate_structA - > lpszSubjectInfo & &
strlen ( certificate_structA - > lpszSubjectInfo ) > 1 ,
" expected a non-empty subject name \n " ) ;
ok ( certificate_structA - > lpszIssuerInfo & &
strlen ( certificate_structA - > lpszIssuerInfo ) > 1 ,
" expected a non-empty issuer name \n " ) ;
ok ( ! certificate_structA - > lpszSignatureAlgName ,
" unexpected signature algorithm name \n " ) ;
ok ( ! certificate_structA - > lpszEncryptionAlgName ,
" unexpected encryption algorithm name \n " ) ;
ok ( ! certificate_structA - > lpszProtocolName ,
" unexpected protocol name \n " ) ;
ok ( certificate_structA - > dwKeySize , " expected a non-zero key size \n " ) ;
2011-01-13 13:54:38 +01:00
release_cert_info ( certificate_structA ) ;
2010-09-30 18:53:47 +02:00
}
HeapFree ( GetProcessHeap ( ) , 0 , certificate_structW ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
/* Repeating the tests with the W functions has the same result: */
2011-01-21 13:35:40 +01:00
ses = InternetOpenW ( gizmo5 , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , 0 ) ;
2010-09-30 18:53:47 +02:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
2013-05-23 19:23:17 +02:00
con = InternetConnectW ( ses , testsite ,
2010-09-30 18:53:47 +02:00
INTERNET_DEFAULT_HTTPS_PORT , NULL , NULL ,
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
2013-05-23 19:23:17 +02:00
req = HttpOpenRequestW ( con , get , testpage , NULL , NULL , NULL ,
2013-06-14 15:18:18 +02:00
INTERNET_FLAG_SECURE | INTERNET_FLAG_RELOAD , 0 ) ;
2010-09-30 18:53:47 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
2010-09-30 18:53:47 +02:00
ok ( ret , " HttpSendRequest failed: %d \n " , GetLastError ( ) ) ;
size = sizeof ( flags ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( req , INTERNET_OPTION_SECURITY_FLAGS , & flags , & size ) ;
2010-09-30 18:53:47 +02:00
ok ( ret , " InternetQueryOption failed: %d \n " , GetLastError ( ) ) ;
2013-06-14 15:18:18 +02:00
ok ( flags & SECURITY_FLAG_SECURE , " expected secure flag to be set, got %x \n " , flags ) ;
2010-09-30 18:53:47 +02:00
ret = InternetQueryOptionA ( req , INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT ,
NULL , & size ) ;
ok ( ret | | GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " InternetQueryOption failed: %d \n " , GetLastError ( ) ) ;
2011-01-13 13:54:38 +01:00
ok ( size = = sizeof ( INTERNET_CERTIFICATE_INFOA ) , " size = %d \n " , size ) ;
2010-09-30 18:53:47 +02:00
certificate_structA = HeapAlloc ( GetProcessHeap ( ) , 0 , size ) ;
ret = InternetQueryOptionW ( req , INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT ,
certificate_structA , & size ) ;
ok ( ret , " InternetQueryOption failed: %d \n " , GetLastError ( ) ) ;
if ( ret )
{
ok ( certificate_structA - > lpszSubjectInfo & &
strlen ( certificate_structA - > lpszSubjectInfo ) > 1 ,
" expected a non-empty subject name \n " ) ;
ok ( certificate_structA - > lpszIssuerInfo & &
strlen ( certificate_structA - > lpszIssuerInfo ) > 1 ,
" expected a non-empty issuer name \n " ) ;
ok ( ! certificate_structA - > lpszSignatureAlgName ,
" unexpected signature algorithm name \n " ) ;
ok ( ! certificate_structA - > lpszEncryptionAlgName ,
" unexpected encryption algorithm name \n " ) ;
ok ( ! certificate_structA - > lpszProtocolName ,
" unexpected protocol name \n " ) ;
ok ( certificate_structA - > dwKeySize , " expected a non-zero key size \n " ) ;
2011-01-13 13:54:38 +01:00
release_cert_info ( certificate_structA ) ;
2010-09-30 18:53:47 +02:00
}
HeapFree ( GetProcessHeap ( ) , 0 , certificate_structA ) ;
/* Again, querying the same option through InternetQueryOptionW still
* results in ASCII strings being returned .
*/
size = 0 ;
ret = InternetQueryOptionW ( req , INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT ,
NULL , & size ) ;
ok ( ret | | GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " InternetQueryOption failed: %d \n " , GetLastError ( ) ) ;
2011-01-13 13:54:38 +01:00
ok ( size = = sizeof ( INTERNET_CERTIFICATE_INFOW ) , " size = %d \n " , size ) ;
2010-09-30 18:53:47 +02:00
certificate_structW = HeapAlloc ( GetProcessHeap ( ) , 0 , size ) ;
ret = InternetQueryOptionW ( req , INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT ,
certificate_structW , & size ) ;
certificate_structA = ( INTERNET_CERTIFICATE_INFOA * ) certificate_structW ;
ok ( ret , " InternetQueryOption failed: %d \n " , GetLastError ( ) ) ;
if ( ret )
{
ok ( certificate_structA - > lpszSubjectInfo & &
strlen ( certificate_structA - > lpszSubjectInfo ) > 1 ,
" expected a non-empty subject name \n " ) ;
ok ( certificate_structA - > lpszIssuerInfo & &
strlen ( certificate_structA - > lpszIssuerInfo ) > 1 ,
" expected a non-empty issuer name \n " ) ;
ok ( ! certificate_structA - > lpszSignatureAlgName ,
" unexpected signature algorithm name \n " ) ;
ok ( ! certificate_structA - > lpszEncryptionAlgName ,
" unexpected encryption algorithm name \n " ) ;
ok ( ! certificate_structA - > lpszProtocolName ,
" unexpected protocol name \n " ) ;
ok ( certificate_structA - > dwKeySize , " expected a non-zero key size \n " ) ;
2011-01-13 13:54:38 +01:00
release_cert_info ( certificate_structA ) ;
2010-09-30 18:53:47 +02:00
}
HeapFree ( GetProcessHeap ( ) , 0 , certificate_structW ) ;
2015-06-12 11:34:13 +02:00
done :
2010-09-30 18:53:47 +02:00
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2008-05-02 21:59:24 +02:00
static void test_user_agent_header ( void )
{
HINTERNET ses , con , req ;
DWORD size , err ;
char buffer [ 64 ] ;
BOOL ret ;
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " Gizmo5 " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , 0 ) ;
2008-05-02 21:59:24 +02:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
con = InternetConnectA ( ses , " test.winehq.org " , 80 , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2008-05-02 21:59:24 +02:00
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , " GET " , " /tests/hello.html " , " HTTP/1.0 " , NULL , NULL , 0 , 0 ) ;
2008-05-02 21:59:24 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( req , HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
2008-05-02 21:59:24 +02:00
err = GetLastError ( ) ;
ok ( ! ret , " HttpQueryInfo succeeded \n " ) ;
ok ( err = = ERROR_HTTP_HEADER_NOT_FOUND , " expected ERROR_HTTP_HEADER_NOT_FOUND, got %u \n " , err ) ;
2013-10-24 12:15:43 +02:00
ret = HttpAddRequestHeadersA ( req , " User-Agent: Gizmo Project \r \n " , ~ 0u , HTTP_ADDREQ_FLAG_ADD_IF_NEW ) ;
2008-05-02 21:59:24 +02:00
ok ( ret , " HttpAddRequestHeaders succeeded \n " ) ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( req , HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
2008-05-02 21:59:24 +02:00
err = GetLastError ( ) ;
ok ( ret , " HttpQueryInfo failed \n " ) ;
InternetCloseHandle ( req ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , " GET " , " / " , " HTTP/1.0 " , NULL , NULL , 0 , 0 ) ;
2008-05-02 21:59:24 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( req , HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
2008-05-02 21:59:24 +02:00
err = GetLastError ( ) ;
ok ( ! ret , " HttpQueryInfo succeeded \n " ) ;
ok ( err = = ERROR_HTTP_HEADER_NOT_FOUND , " expected ERROR_HTTP_HEADER_NOT_FOUND, got %u \n " , err ) ;
2013-10-24 12:15:43 +02:00
ret = HttpAddRequestHeadersA ( req , " Accept: audio/*, image/*, text/* \r \n User-Agent: Gizmo Project \r \n " , ~ 0u , HTTP_ADDREQ_FLAG_ADD_IF_NEW ) ;
2008-05-02 21:59:24 +02:00
ok ( ret , " HttpAddRequestHeaders failed \n " ) ;
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( req , HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
2008-05-02 21:59:24 +02:00
ok ( ret , " HttpQueryInfo failed: %u \n " , GetLastError ( ) ) ;
ok ( ! strcmp ( buffer , " audio/*, image/*, text/* " ) , " got '%s' expected 'audio/*, image/*, text/*' \n " , buffer ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2008-05-07 13:19:37 +02:00
static void test_bogus_accept_types_array ( void )
{
HINTERNET ses , con , req ;
2008-10-24 11:08:12 +02:00
static const char * types [ ] = { ( const char * ) 6240 , " */* " , " %p " , " " , ( const char * ) 0xffffffff , " */* " , NULL } ;
2011-09-27 11:40:33 +02:00
DWORD size , error ;
2008-05-07 13:19:37 +02:00
char buffer [ 32 ] ;
BOOL ret ;
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " MERONG(0.9/;p) " , INTERNET_OPEN_TYPE_DIRECT , " " , " " , 0 ) ;
con = InternetConnectA ( ses , " www.winehq.org " , 80 , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
req = HttpOpenRequestA ( con , " POST " , " /post/post_action.php " , " HTTP/1.0 " , " " , types , INTERNET_FLAG_FORMS_SUBMIT , 0 ) ;
2008-05-07 13:19:37 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed: %u \n " , GetLastError ( ) ) ;
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
2011-09-27 11:40:33 +02:00
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( req , HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
2011-09-27 11:40:33 +02:00
error = GetLastError ( ) ;
ok ( ! ret | | broken ( ret ) , " HttpQueryInfo succeeded \n " ) ;
if ( ! ret ) ok ( error = = ERROR_HTTP_HEADER_NOT_FOUND , " expected ERROR_HTTP_HEADER_NOT_FOUND, got %u \n " , error ) ;
ok ( broken ( ! strcmp ( buffer , " , */*, %p, , , */* " ) ) /* IE6 */ | |
broken ( ! strcmp ( buffer , " */*, %p, */* " ) ) /* IE7/8 */ | |
! strcmp ( buffer , " " ) , " got '%s' expected '' \n " , buffer ) ;
2008-05-07 13:19:37 +02:00
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2008-05-16 13:50:36 +02:00
struct context
{
HANDLE event ;
HINTERNET req ;
} ;
static void WINAPI cb ( HINTERNET handle , DWORD_PTR context , DWORD status , LPVOID info , DWORD size )
{
2008-05-31 21:46:34 +02:00
INTERNET_ASYNC_RESULT * result = info ;
struct context * ctx = ( struct context * ) context ;
2008-05-16 13:50:36 +02:00
trace ( " %p 0x%08lx %u %p 0x%08x \n " , handle , context , status , info , size ) ;
2013-02-18 15:45:30 +01:00
switch ( status ) {
case INTERNET_STATUS_REQUEST_COMPLETE :
2008-05-16 13:50:36 +02:00
trace ( " request handle: 0x%08lx \n " , result - > dwResult ) ;
ctx - > req = ( HINTERNET ) result - > dwResult ;
SetEvent ( ctx - > event ) ;
2013-02-18 15:45:30 +01:00
break ;
case INTERNET_STATUS_HANDLE_CLOSING : {
2008-05-31 21:46:34 +02:00
DWORD type = INTERNET_HANDLE_TYPE_CONNECT_HTTP , size = sizeof ( type ) ;
2013-10-24 12:15:43 +02:00
if ( InternetQueryOptionA ( handle , INTERNET_OPTION_HANDLE_TYPE , & type , & size ) )
2008-05-31 21:46:34 +02:00
ok ( type ! = INTERNET_HANDLE_TYPE_CONNECT_HTTP , " unexpected callback \n " ) ;
SetEvent ( ctx - > event ) ;
2013-02-18 15:45:30 +01:00
break ;
}
case INTERNET_STATUS_NAME_RESOLVED :
case INTERNET_STATUS_CONNECTING_TO_SERVER :
case INTERNET_STATUS_CONNECTED_TO_SERVER : {
char * str = info ;
ok ( str [ 0 ] & & str [ 1 ] , " Got string: %s \n " , str ) ;
ok ( size = = strlen ( str ) + 1 , " unexpected size %u \n " , size ) ;
}
2008-05-31 21:46:34 +02:00
}
2008-05-16 13:50:36 +02:00
}
static void test_open_url_async ( void )
{
BOOL ret ;
HINTERNET ses , req ;
2008-10-06 15:48:04 +02:00
DWORD size , error ;
2008-05-16 13:50:36 +02:00
struct context ctx ;
ULONG type ;
2013-02-18 15:45:30 +01:00
/* Collect all existing persistent connections */
ret = InternetSetOptionA ( NULL , INTERNET_OPTION_SETTINGS_CHANGED , NULL , 0 ) ;
ok ( ret , " InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u \n " , GetLastError ( ) ) ;
2013-03-09 17:52:02 +01:00
/*
* Some versions of IE6 fail those tests . They pass some notification data as UNICODE string , while
* other versions never do . They also hang of following tests . We disable it for everything older
* than IE7 .
*/
if ( ! pInternetGetSecurityInfoByURLA ) {
win_skip ( " Skipping async open on too old wininet version. \n " ) ;
return ;
}
2008-05-16 13:50:36 +02:00
ctx . req = NULL ;
2013-10-24 12:15:43 +02:00
ctx . event = CreateEventA ( NULL , TRUE , FALSE , " Z:_home_hans_jaman-installer.exe_ev1 " ) ;
2008-05-16 13:50:36 +02:00
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " AdvancedInstaller " , 0 , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
2008-05-16 13:50:36 +02:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
2008-10-06 15:48:04 +02:00
SetLastError ( 0xdeadbeef ) ;
ret = InternetSetOptionA ( NULL , INTERNET_OPTION_CALLBACK , & cb , sizeof ( DWORD_PTR ) ) ;
error = GetLastError ( ) ;
ok ( ! ret , " InternetSetOptionA succeeded \n " ) ;
ok ( error = = ERROR_INTERNET_INCORRECT_HANDLE_TYPE , " got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE \n " , error ) ;
ret = InternetSetOptionA ( ses , INTERNET_OPTION_CALLBACK , & cb , sizeof ( DWORD_PTR ) ) ;
error = GetLastError ( ) ;
ok ( ! ret , " InternetSetOptionA failed \n " ) ;
ok ( error = = ERROR_INTERNET_OPTION_NOT_SETTABLE , " got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE \n " , error ) ;
2013-02-18 15:45:30 +01:00
pInternetSetStatusCallbackW ( ses , cb ) ;
2008-05-16 13:50:36 +02:00
ResetEvent ( ctx . event ) ;
2013-10-24 12:15:43 +02:00
req = InternetOpenUrlA ( ses , " http://test.winehq.org " , NULL , 0 , 0 , ( DWORD_PTR ) & ctx ) ;
2008-05-16 13:50:36 +02:00
ok ( ! req & & GetLastError ( ) = = ERROR_IO_PENDING , " InternetOpenUrl failed \n " ) ;
WaitForSingleObject ( ctx . event , INFINITE ) ;
type = 0 ;
size = sizeof ( type ) ;
2013-10-24 12:15:43 +02:00
ret = InternetQueryOptionA ( ctx . req , INTERNET_OPTION_HANDLE_TYPE , & type , & size ) ;
2008-05-18 21:09:50 +02:00
ok ( ret , " InternetQueryOption failed: %u \n " , GetLastError ( ) ) ;
2008-05-16 13:50:36 +02:00
ok ( type = = INTERNET_HANDLE_TYPE_HTTP_REQUEST ,
" expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u \n " , type ) ;
2008-05-18 21:09:50 +02:00
size = 0 ;
2013-10-24 12:15:43 +02:00
ret = HttpQueryInfoA ( ctx . req , HTTP_QUERY_RAW_HEADERS_CRLF , NULL , & size , NULL ) ;
2008-05-18 21:09:50 +02:00
ok ( ! ret & & GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " HttpQueryInfo failed \n " ) ;
ok ( size > 0 , " expected size > 0 \n " ) ;
2008-05-31 21:46:34 +02:00
ResetEvent ( ctx . event ) ;
2008-05-16 13:50:36 +02:00
InternetCloseHandle ( ctx . req ) ;
2008-05-31 21:46:34 +02:00
WaitForSingleObject ( ctx . event , INFINITE ) ;
2008-05-16 13:50:36 +02:00
InternetCloseHandle ( ses ) ;
2008-05-31 21:46:34 +02:00
CloseHandle ( ctx . event ) ;
2008-05-16 13:50:36 +02:00
}
2009-04-08 15:23:14 +02:00
enum api
{
internet_connect = 1 ,
http_open_request ,
http_send_request_ex ,
internet_writefile ,
http_end_request ,
internet_close_handle
} ;
struct notification
{
enum api function ; /* api responsible for notification */
unsigned int status ; /* status received */
2013-11-27 08:51:59 +01:00
BOOL async ; /* delivered from another thread? */
BOOL todo ;
BOOL optional ;
2009-04-08 15:23:14 +02:00
} ;
struct info
{
enum api function ;
const struct notification * test ;
unsigned int count ;
unsigned int index ;
HANDLE wait ;
DWORD thread ;
unsigned int line ;
2011-12-07 16:40:43 +01:00
DWORD expect_result ;
BOOL is_aborted ;
2009-04-08 15:23:14 +02:00
} ;
static CRITICAL_SECTION notification_cs ;
static void CALLBACK check_notification ( HINTERNET handle , DWORD_PTR context , DWORD status , LPVOID buffer , DWORD buflen )
{
BOOL status_ok , function_ok ;
struct info * info = ( struct info * ) context ;
unsigned int i ;
EnterCriticalSection ( & notification_cs ) ;
2011-12-07 16:40:43 +01:00
if ( info - > is_aborted ) {
LeaveCriticalSection ( & notification_cs ) ;
return ;
}
2009-04-08 15:23:14 +02:00
if ( status = = INTERNET_STATUS_HANDLE_CREATED )
{
DWORD size = sizeof ( struct info * ) ;
HttpQueryInfoA ( handle , INTERNET_OPTION_CONTEXT_VALUE , & info , & size , 0 ) ;
2011-12-07 16:40:43 +01:00
} else if ( status = = INTERNET_STATUS_REQUEST_COMPLETE ) {
INTERNET_ASYNC_RESULT * ar = ( INTERNET_ASYNC_RESULT * ) buffer ;
ok ( buflen = = sizeof ( * ar ) , " unexpected buflen = %d \n " , buflen ) ;
if ( info - > expect_result = = ERROR_SUCCESS ) {
ok ( ar - > dwResult = = 1 , " ar->dwResult = %ld, expected 1 \n " , ar - > dwResult ) ;
} else {
ok ( ! ar - > dwResult , " ar->dwResult = %ld, expected 1 \n " , ar - > dwResult ) ;
ok ( ar - > dwError = = info - > expect_result , " ar->dwError = %d, expected %d \n " , ar - > dwError , info - > expect_result ) ;
}
2009-04-08 15:23:14 +02:00
}
2011-12-07 16:40:43 +01:00
2009-04-08 15:23:14 +02:00
i = info - > index ;
if ( i > = info - > count )
{
LeaveCriticalSection ( & notification_cs ) ;
return ;
}
2011-11-23 15:45:44 +01:00
while ( info - > test [ i ] . status ! = status & &
( info - > test [ i ] . optional | | info - > test [ i ] . todo ) & &
2009-05-10 00:45:02 +02:00
i < info - > count - 1 & &
info - > test [ i ] . function = = info - > test [ i + 1 ] . function )
{
i + + ;
}
2009-04-08 15:23:14 +02:00
status_ok = ( info - > test [ i ] . status = = status ) ;
function_ok = ( info - > test [ i ] . function = = info - > function ) ;
if ( ! info - > test [ i ] . todo )
{
ok ( status_ok , " %u: expected status %u got %u \n " , info - > line , info - > test [ i ] . status , status ) ;
ok ( function_ok , " %u: expected function %u got %u \n " , info - > line , info - > test [ i ] . function , info - > function ) ;
if ( info - > test [ i ] . async )
ok ( info - > thread ! = GetCurrentThreadId ( ) , " %u: expected thread %u got %u \n " ,
info - > line , info - > thread , GetCurrentThreadId ( ) ) ;
}
else
{
todo_wine ok ( status_ok , " %u: expected status %u got %u \n " , info - > line , info - > test [ i ] . status , status ) ;
if ( status_ok )
todo_wine ok ( function_ok , " %u: expected function %u got %u \n " , info - > line , info - > test [ i ] . function , info - > function ) ;
}
if ( i = = info - > count - 1 | | info - > test [ i ] . function ! = info - > test [ i + 1 ] . function ) SetEvent ( info - > wait ) ;
2009-05-10 00:45:02 +02:00
info - > index = i + 1 ;
2009-04-08 15:23:14 +02:00
LeaveCriticalSection ( & notification_cs ) ;
}
2011-12-07 16:40:43 +01:00
static void setup_test ( struct info * info , enum api function , unsigned int line , DWORD expect_result )
2009-04-08 15:23:14 +02:00
{
info - > function = function ;
info - > line = line ;
2011-12-07 16:40:43 +01:00
info - > expect_result = expect_result ;
2009-04-08 15:23:14 +02:00
}
2011-11-23 15:45:44 +01:00
struct notification_data
{
const struct notification * test ;
const unsigned int count ;
2011-12-07 16:40:43 +01:00
const char * method ;
const char * host ;
const char * path ;
2011-11-23 15:45:44 +01:00
const char * data ;
2011-12-07 16:40:43 +01:00
BOOL expect_conn_failure ;
2011-11-23 15:45:44 +01:00
} ;
2009-04-08 15:23:14 +02:00
static const struct notification async_send_request_ex_test [ ] =
{
2013-11-27 08:51:59 +01:00
{ internet_connect , INTERNET_STATUS_HANDLE_CREATED , FALSE } ,
{ http_open_request , INTERNET_STATUS_HANDLE_CREATED , FALSE } ,
{ http_send_request_ex , INTERNET_STATUS_DETECTING_PROXY , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_COOKIE_SENT , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_RESOLVING_NAME , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_NAME_RESOLVED , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_CONNECTING_TO_SERVER , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_CONNECTED_TO_SERVER , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_SENDING_REQUEST , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_REQUEST_SENT , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_REQUEST_COMPLETE , TRUE } ,
{ internet_writefile , INTERNET_STATUS_SENDING_REQUEST , FALSE } ,
{ internet_writefile , INTERNET_STATUS_REQUEST_SENT , FALSE } ,
{ http_end_request , INTERNET_STATUS_RECEIVING_RESPONSE , TRUE } ,
{ http_end_request , INTERNET_STATUS_RESPONSE_RECEIVED , TRUE } ,
{ http_end_request , INTERNET_STATUS_REQUEST_COMPLETE , TRUE } ,
{ internet_close_handle , INTERNET_STATUS_CLOSING_CONNECTION , FALSE , FALSE , TRUE } ,
{ internet_close_handle , INTERNET_STATUS_CONNECTION_CLOSED , FALSE , FALSE , TRUE } ,
{ internet_close_handle , INTERNET_STATUS_HANDLE_CLOSING , FALSE , } ,
{ internet_close_handle , INTERNET_STATUS_HANDLE_CLOSING , FALSE , }
2009-04-08 15:23:14 +02:00
} ;
2011-11-23 15:45:44 +01:00
static const struct notification async_send_request_ex_test2 [ ] =
{
2013-11-27 08:51:59 +01:00
{ internet_connect , INTERNET_STATUS_HANDLE_CREATED , FALSE } ,
{ http_open_request , INTERNET_STATUS_HANDLE_CREATED , FALSE } ,
{ http_send_request_ex , INTERNET_STATUS_DETECTING_PROXY , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_COOKIE_SENT , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_RESOLVING_NAME , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_NAME_RESOLVED , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_CONNECTING_TO_SERVER , TRUE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_CONNECTED_TO_SERVER , TRUE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_SENDING_REQUEST , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_REQUEST_SENT , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_REQUEST_COMPLETE , TRUE } ,
{ http_end_request , INTERNET_STATUS_RECEIVING_RESPONSE , TRUE } ,
{ http_end_request , INTERNET_STATUS_RESPONSE_RECEIVED , TRUE } ,
{ http_end_request , INTERNET_STATUS_REQUEST_COMPLETE , TRUE } ,
{ internet_close_handle , INTERNET_STATUS_CLOSING_CONNECTION , FALSE , FALSE , TRUE } ,
{ internet_close_handle , INTERNET_STATUS_CONNECTION_CLOSED , FALSE , FALSE , TRUE } ,
{ internet_close_handle , INTERNET_STATUS_HANDLE_CLOSING , FALSE , } ,
{ internet_close_handle , INTERNET_STATUS_HANDLE_CLOSING , FALSE , }
2011-11-23 15:45:44 +01:00
} ;
2011-12-07 16:40:43 +01:00
static const struct notification async_send_request_ex_resolve_failure_test [ ] =
{
2013-11-27 08:51:59 +01:00
{ internet_connect , INTERNET_STATUS_HANDLE_CREATED , FALSE } ,
{ http_open_request , INTERNET_STATUS_HANDLE_CREATED , FALSE } ,
{ http_send_request_ex , INTERNET_STATUS_DETECTING_PROXY , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_RESOLVING_NAME , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_DETECTING_PROXY , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_REQUEST_COMPLETE , TRUE } ,
{ http_end_request , INTERNET_STATUS_REQUEST_COMPLETE , TRUE } ,
{ internet_close_handle , INTERNET_STATUS_CLOSING_CONNECTION , FALSE , FALSE , TRUE } ,
{ internet_close_handle , INTERNET_STATUS_CONNECTION_CLOSED , FALSE , FALSE , TRUE } ,
{ internet_close_handle , INTERNET_STATUS_HANDLE_CLOSING , FALSE , } ,
{ internet_close_handle , INTERNET_STATUS_HANDLE_CLOSING , FALSE , }
2011-12-07 16:40:43 +01:00
} ;
2013-09-18 13:40:24 +02:00
static const struct notification async_send_request_ex_chunked_test [ ] =
{
{ internet_connect , INTERNET_STATUS_HANDLE_CREATED } ,
{ http_open_request , INTERNET_STATUS_HANDLE_CREATED } ,
2013-11-27 08:51:59 +01:00
{ http_send_request_ex , INTERNET_STATUS_DETECTING_PROXY , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_COOKIE_SENT , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_RESOLVING_NAME , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_NAME_RESOLVED , TRUE , FALSE , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_CONNECTING_TO_SERVER , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_CONNECTED_TO_SERVER , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_SENDING_REQUEST , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_REQUEST_SENT , TRUE } ,
{ http_send_request_ex , INTERNET_STATUS_REQUEST_COMPLETE , TRUE } ,
{ http_end_request , INTERNET_STATUS_RECEIVING_RESPONSE , TRUE } ,
{ http_end_request , INTERNET_STATUS_RESPONSE_RECEIVED , TRUE } ,
{ http_end_request , INTERNET_STATUS_REQUEST_COMPLETE , TRUE } ,
2013-09-18 13:40:24 +02:00
{ internet_close_handle , INTERNET_STATUS_CLOSING_CONNECTION } ,
{ internet_close_handle , INTERNET_STATUS_CONNECTION_CLOSED } ,
{ internet_close_handle , INTERNET_STATUS_HANDLE_CLOSING } ,
{ internet_close_handle , INTERNET_STATUS_HANDLE_CLOSING }
} ;
2011-11-23 15:45:44 +01:00
static const struct notification_data notification_data [ ] = {
2013-09-18 13:40:24 +02:00
{
async_send_request_ex_chunked_test ,
sizeof ( async_send_request_ex_chunked_test ) / sizeof ( async_send_request_ex_chunked_test [ 0 ] ) ,
" GET " ,
" test.winehq.org " ,
" tests/data.php "
} ,
2011-11-23 15:45:44 +01:00
{
async_send_request_ex_test ,
sizeof ( async_send_request_ex_test ) / sizeof ( async_send_request_ex_test [ 0 ] ) ,
2011-12-07 16:40:43 +01:00
" POST " ,
" test.winehq.org " ,
2014-09-03 14:39:51 +02:00
" tests/post.php " ,
2011-11-23 15:45:44 +01:00
" Public ID=codeweavers "
} ,
{
async_send_request_ex_test2 ,
2011-12-07 16:40:43 +01:00
sizeof ( async_send_request_ex_test ) / sizeof ( async_send_request_ex_test [ 0 ] ) ,
" POST " ,
" test.winehq.org " ,
2014-09-03 14:39:51 +02:00
" tests/post.php "
2011-11-23 15:45:44 +01:00
} ,
2011-12-07 16:40:43 +01:00
{
async_send_request_ex_resolve_failure_test ,
sizeof ( async_send_request_ex_resolve_failure_test ) / sizeof ( async_send_request_ex_resolve_failure_test [ 0 ] ) ,
" GET " ,
" brokenhost " ,
" index.html " ,
NULL ,
TRUE
}
2011-11-23 15:45:44 +01:00
} ;
static void test_async_HttpSendRequestEx ( const struct notification_data * nd )
2009-04-08 15:23:14 +02:00
{
BOOL ret ;
HINTERNET ses , req , con ;
struct info info ;
DWORD size , written , error ;
INTERNET_BUFFERSA b ;
static const char * accept [ 2 ] = { " */* " , NULL } ;
char buffer [ 32 ] ;
2011-12-07 16:40:43 +01:00
trace ( " Async HttpSendRequestEx test (%s %s) \n " , nd - > method , nd - > host ) ;
2011-11-23 15:45:44 +01:00
2009-04-08 15:23:14 +02:00
InitializeCriticalSection ( & notification_cs ) ;
2011-11-23 15:45:44 +01:00
info . test = nd - > test ;
info . count = nd - > count ;
2009-04-08 15:23:14 +02:00
info . index = 0 ;
2013-10-24 12:15:43 +02:00
info . wait = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
2009-04-08 15:23:14 +02:00
info . thread = GetCurrentThreadId ( ) ;
2011-12-07 16:40:43 +01:00
info . is_aborted = FALSE ;
2009-04-08 15:23:14 +02:00
2013-10-24 12:15:43 +02:00
ses = InternetOpenA ( " winetest " , 0 , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
2009-04-08 15:23:14 +02:00
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
pInternetSetStatusCallbackA ( ses , check_notification ) ;
2011-12-07 16:40:43 +01:00
setup_test ( & info , internet_connect , __LINE__ , ERROR_SUCCESS ) ;
2013-10-24 12:15:43 +02:00
con = InternetConnectA ( ses , nd - > host , 80 , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , ( DWORD_PTR ) & info ) ;
2009-04-08 15:23:14 +02:00
ok ( con ! = NULL , " InternetConnect failed %u \n " , GetLastError ( ) ) ;
WaitForSingleObject ( info . wait , 10000 ) ;
2011-12-07 16:40:43 +01:00
setup_test ( & info , http_open_request , __LINE__ , ERROR_SUCCESS ) ;
2013-10-24 12:15:43 +02:00
req = HttpOpenRequestA ( con , nd - > method , nd - > path , NULL , NULL , accept , 0 , ( DWORD_PTR ) & info ) ;
2009-04-08 15:23:14 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed %u \n " , GetLastError ( ) ) ;
WaitForSingleObject ( info . wait , 10000 ) ;
2011-12-07 16:40:43 +01:00
if ( nd - > data ) {
memset ( & b , 0 , sizeof ( INTERNET_BUFFERSA ) ) ;
b . dwStructSize = sizeof ( INTERNET_BUFFERSA ) ;
b . lpcszHeader = " Content-Type: application/x-www-form-urlencoded " ;
b . dwHeadersLength = strlen ( b . lpcszHeader ) ;
b . dwBufferTotal = nd - > data ? strlen ( nd - > data ) : 0 ;
}
2009-04-08 15:23:14 +02:00
2011-12-07 16:40:43 +01:00
setup_test ( & info , http_send_request_ex , __LINE__ ,
nd - > expect_conn_failure ? ERROR_INTERNET_NAME_NOT_RESOLVED : ERROR_SUCCESS ) ;
2011-11-23 15:45:44 +01:00
ret = HttpSendRequestExA ( req , nd - > data ? & b : NULL , NULL , 0x28 , 0 ) ;
2009-04-08 15:23:14 +02:00
ok ( ! ret & & GetLastError ( ) = = ERROR_IO_PENDING , " HttpSendRequestExA failed %d %u \n " , ret , GetLastError ( ) ) ;
2011-12-07 16:40:43 +01:00
error = WaitForSingleObject ( info . wait , 10000 ) ;
if ( error ! = WAIT_OBJECT_0 ) {
skip ( " WaitForSingleObject returned %d, assuming DNS problem \n " , error ) ;
info . is_aborted = TRUE ;
goto abort ;
}
2009-04-08 15:23:14 +02:00
size = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
ret = HttpQueryInfoA ( req , HTTP_QUERY_CONTENT_ENCODING , buffer , & size , 0 ) ;
error = GetLastError ( ) ;
ok ( ! ret , " HttpQueryInfoA failed %u \n " , GetLastError ( ) ) ;
2011-12-07 16:40:43 +01:00
if ( nd - > expect_conn_failure ) {
ok ( error = = ERROR_HTTP_HEADER_NOT_FOUND , " expected ERROR_HTTP_HEADER_NOT_FOUND got %u \n " , error ) ;
} else {
todo_wine
ok ( error = = ERROR_INTERNET_INCORRECT_HANDLE_STATE ,
" expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u \n " , error ) ;
}
2009-04-08 15:23:14 +02:00
2011-11-23 15:45:44 +01:00
if ( nd - > data )
{
written = 0 ;
size = strlen ( nd - > data ) ;
2011-12-07 16:40:43 +01:00
setup_test ( & info , internet_writefile , __LINE__ , ERROR_SUCCESS ) ;
2011-11-23 15:45:44 +01:00
ret = InternetWriteFile ( req , nd - > data , size , & written ) ;
ok ( ret , " InternetWriteFile failed %u \n " , GetLastError ( ) ) ;
ok ( written = = size , " expected %u got %u \n " , written , size ) ;
WaitForSingleObject ( info . wait , 10000 ) ;
SetLastError ( 0xdeadbeef ) ;
ret = HttpEndRequestA ( req , ( void * ) nd - > data , 0x28 , 0 ) ;
error = GetLastError ( ) ;
ok ( ! ret , " HttpEndRequestA succeeded \n " ) ;
ok ( error = = ERROR_INVALID_PARAMETER , " expected ERROR_INVALID_PARAMETER got %u \n " , error ) ;
}
2009-04-08 15:23:14 +02:00
SetLastError ( 0xdeadbeef ) ;
2011-12-07 16:40:43 +01:00
setup_test ( & info , http_end_request , __LINE__ ,
nd - > expect_conn_failure ? ERROR_INTERNET_OPERATION_CANCELLED : ERROR_SUCCESS ) ;
2009-04-08 15:23:14 +02:00
ret = HttpEndRequestA ( req , NULL , 0x28 , 0 ) ;
error = GetLastError ( ) ;
ok ( ! ret , " HttpEndRequestA succeeded \n " ) ;
ok ( error = = ERROR_IO_PENDING , " expected ERROR_IO_PENDING got %u \n " , error ) ;
WaitForSingleObject ( info . wait , 10000 ) ;
2011-12-07 16:40:43 +01:00
setup_test ( & info , internet_close_handle , __LINE__ , ERROR_SUCCESS ) ;
abort :
2009-04-08 15:23:14 +02:00
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
WaitForSingleObject ( info . wait , 10000 ) ;
2009-05-10 00:40:03 +02:00
Sleep ( 100 ) ;
2009-04-08 15:23:14 +02:00
CloseHandle ( info . wait ) ;
2015-11-11 04:44:04 +01:00
DeleteCriticalSection ( & notification_cs ) ;
2009-04-08 15:23:14 +02:00
}
2011-02-02 22:50:59 +01:00
static HINTERNET closetest_session , closetest_req , closetest_conn ;
static BOOL closetest_closed ;
static void WINAPI closetest_callback ( HINTERNET hInternet , DWORD_PTR dwContext , DWORD dwInternetStatus ,
LPVOID lpvStatusInformation , DWORD dwStatusInformationLength )
{
DWORD len , type ;
BOOL res ;
trace ( " closetest_callback %p: %d \n " , hInternet , dwInternetStatus ) ;
ok ( hInternet = = closetest_session | | hInternet = = closetest_conn | | hInternet = = closetest_req ,
" Unexpected hInternet %p \n " , hInternet ) ;
if ( ! closetest_closed )
return ;
len = sizeof ( type ) ;
res = InternetQueryOptionA ( closetest_req , INTERNET_OPTION_HANDLE_TYPE , & type , & len ) ;
ok ( ! res & & GetLastError ( ) = = ERROR_INVALID_HANDLE ,
" InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE \n " ,
closetest_req , res , GetLastError ( ) ) ;
}
static void test_InternetCloseHandle ( void )
{
DWORD len , flags ;
BOOL res ;
closetest_session = InternetOpenA ( " " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
ok ( closetest_session ! = NULL , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
pInternetSetStatusCallbackA ( closetest_session , closetest_callback ) ;
closetest_conn = InternetConnectA ( closetest_session , " source.winehq.org " , INTERNET_INVALID_PORT_NUMBER ,
NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
ok ( closetest_conn ! = NULL , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
closetest_req = HttpOpenRequestA ( closetest_conn , " GET " , " winegecko.php " , NULL , NULL , NULL ,
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE , 0xdeadbead ) ;
res = HttpSendRequestA ( closetest_req , NULL , - 1 , NULL , 0 ) ;
ok ( ! res & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
2012-05-24 15:24:55 +02:00
test_request_flags ( closetest_req , INTERNET_REQFLAG_NO_HEADERS ) ;
2011-02-02 22:50:59 +01:00
res = InternetCloseHandle ( closetest_session ) ;
ok ( res , " InternetCloseHandle failed: %u \n " , GetLastError ( ) ) ;
closetest_closed = TRUE ;
trace ( " Closed session handle \n " ) ;
res = InternetCloseHandle ( closetest_conn ) ;
ok ( ! res & & GetLastError ( ) = = ERROR_INVALID_HANDLE , " InternetCloseConnection(conn) failed: %x %u \n " ,
res , GetLastError ( ) ) ;
res = InternetCloseHandle ( closetest_req ) ;
ok ( ! res & & GetLastError ( ) = = ERROR_INVALID_HANDLE , " InternetCloseConnection(req) failed: %x %u \n " ,
res , GetLastError ( ) ) ;
len = sizeof ( flags ) ;
res = InternetQueryOptionA ( closetest_req , INTERNET_OPTION_REQUEST_FLAGS , & flags , & len ) ;
ok ( ! res & & GetLastError ( ) = = ERROR_INVALID_HANDLE ,
" InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE \n " ,
closetest_req , res , GetLastError ( ) ) ;
}
2012-12-19 12:02:36 +01:00
static void test_connection_failure ( void )
{
HINTERNET session , connect , request ;
DWORD error ;
BOOL ret ;
2015-09-22 15:59:01 +02:00
session = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2012-12-19 12:02:36 +01:00
ok ( session ! = NULL , " failed to get session handle \n " ) ;
connect = InternetConnectA ( session , " localhost " , 1 , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( connect ! = NULL , " failed to get connection handle \n " ) ;
request = HttpOpenRequestA ( connect , NULL , " / " , NULL , NULL , NULL , 0 , 0 ) ;
ok ( request ! = NULL , " failed to get request handle \n " ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2012-12-19 12:02:36 +01:00
error = GetLastError ( ) ;
ok ( ! ret , " unexpected success \n " ) ;
ok ( error = = ERROR_INTERNET_CANNOT_CONNECT , " wrong error %u \n " , error ) ;
InternetCloseHandle ( request ) ;
InternetCloseHandle ( connect ) ;
InternetCloseHandle ( session ) ;
}
2013-03-06 13:30:49 +01:00
static void test_default_service_port ( void )
{
HINTERNET session , connect , request ;
2016-04-26 23:38:52 +02:00
DWORD size , error ;
char buffer [ 128 ] ;
2013-03-06 13:30:49 +01:00
BOOL ret ;
2013-10-24 12:15:43 +02:00
session = InternetOpenA ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2013-03-06 13:30:49 +01:00
ok ( session ! = NULL , " InternetOpen failed \n " ) ;
2013-10-24 12:15:43 +02:00
connect = InternetConnectA ( session , " test.winehq.org " , INTERNET_INVALID_PORT_NUMBER , NULL , NULL ,
2013-03-06 13:30:49 +01:00
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( connect ! = NULL , " InternetConnect failed \n " ) ;
2013-10-24 12:15:43 +02:00
request = HttpOpenRequestA ( connect , NULL , " / " , NULL , NULL , NULL , INTERNET_FLAG_SECURE , 0 ) ;
2013-03-06 13:30:49 +01:00
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
2013-03-06 13:30:49 +01:00
error = GetLastError ( ) ;
ok ( ! ret , " HttpSendRequest succeeded \n " ) ;
ok ( error = = ERROR_INTERNET_SECURITY_CHANNEL_ERROR | | error = = ERROR_INTERNET_CANNOT_CONNECT ,
" got %u \n " , error ) ;
2016-04-26 23:38:52 +02:00
size = sizeof ( buffer ) ;
memset ( buffer , 0 , sizeof ( buffer ) ) ;
ret = HttpQueryInfoA ( request , HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed with error %u \n " , GetLastError ( ) ) ;
ok ( ! strcmp ( buffer , " test.winehq.org:80 " ) , " Expected test.winehg.org:80, got '%s' \n " , buffer ) ;
InternetCloseHandle ( request ) ;
InternetCloseHandle ( connect ) ;
connect = InternetConnectA ( session , " test.winehq.org " , INTERNET_INVALID_PORT_NUMBER , NULL , NULL ,
INTERNET_SERVICE_HTTP , INTERNET_FLAG_SECURE , 0 ) ;
ok ( connect ! = NULL , " InternetConnect failed \n " ) ;
request = HttpOpenRequestA ( connect , NULL , " / " , NULL , NULL , NULL , INTERNET_FLAG_SECURE , 0 ) ;
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
todo_wine ok ( ret , " HttpSendRequest failed with error %u \n " , GetLastError ( ) ) ;
size = sizeof ( buffer ) ;
memset ( buffer , 0 , sizeof ( buffer ) ) ;
ret = HttpQueryInfoA ( request , HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed with error %u \n " , GetLastError ( ) ) ;
todo_wine ok ( ! strcmp ( buffer , " test.winehq.org " ) , " Expected test.winehg.org, got '%s' \n " , buffer ) ;
InternetCloseHandle ( request ) ;
InternetCloseHandle ( connect ) ;
connect = InternetConnectA ( session , " test.winehq.org " , INTERNET_INVALID_PORT_NUMBER , NULL , NULL ,
INTERNET_SERVICE_HTTP , INTERNET_FLAG_SECURE , 0 ) ;
ok ( connect ! = NULL , " InternetConnect failed \n " ) ;
request = HttpOpenRequestA ( connect , NULL , " / " , NULL , NULL , NULL , 0 , 0 ) ;
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpSendRequestA ( request , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed with error %u \n " , GetLastError ( ) ) ;
size = sizeof ( buffer ) ;
memset ( buffer , 0 , sizeof ( buffer ) ) ;
ret = HttpQueryInfoA ( request , HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed with error %u \n " , GetLastError ( ) ) ;
todo_wine ok ( ! strcmp ( buffer , " test.winehq.org:443 " ) , " Expected test.winehg.org:443, got '%s' \n " , buffer ) ;
2013-03-06 13:30:49 +01:00
InternetCloseHandle ( request ) ;
InternetCloseHandle ( connect ) ;
InternetCloseHandle ( session ) ;
}
2007-07-15 23:29:48 +02:00
static void init_status_tests ( void )
{
memset ( expect , 0 , sizeof ( expect ) ) ;
2008-08-26 11:27:26 +02:00
memset ( optional , 0 , sizeof ( optional ) ) ;
2007-07-15 23:29:48 +02:00
memset ( wine_allow , 0 , sizeof ( wine_allow ) ) ;
memset ( notified , 0 , sizeof ( notified ) ) ;
memset ( status_string , 0 , sizeof ( status_string ) ) ;
2011-02-03 20:46:05 +01:00
# define STATUS_STRING(status) status_string[status] = #status
2007-07-15 23:29:48 +02:00
STATUS_STRING ( INTERNET_STATUS_RESOLVING_NAME ) ;
STATUS_STRING ( INTERNET_STATUS_NAME_RESOLVED ) ;
STATUS_STRING ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
STATUS_STRING ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
STATUS_STRING ( INTERNET_STATUS_SENDING_REQUEST ) ;
STATUS_STRING ( INTERNET_STATUS_REQUEST_SENT ) ;
STATUS_STRING ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
STATUS_STRING ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
STATUS_STRING ( INTERNET_STATUS_CTL_RESPONSE_RECEIVED ) ;
STATUS_STRING ( INTERNET_STATUS_PREFETCH ) ;
STATUS_STRING ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
STATUS_STRING ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
STATUS_STRING ( INTERNET_STATUS_HANDLE_CREATED ) ;
STATUS_STRING ( INTERNET_STATUS_HANDLE_CLOSING ) ;
2008-05-06 23:58:31 +02:00
STATUS_STRING ( INTERNET_STATUS_DETECTING_PROXY ) ;
2007-07-15 23:29:48 +02:00
STATUS_STRING ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
STATUS_STRING ( INTERNET_STATUS_REDIRECT ) ;
STATUS_STRING ( INTERNET_STATUS_INTERMEDIATE_RESPONSE ) ;
STATUS_STRING ( INTERNET_STATUS_USER_INPUT_REQUIRED ) ;
STATUS_STRING ( INTERNET_STATUS_STATE_CHANGE ) ;
STATUS_STRING ( INTERNET_STATUS_COOKIE_SENT ) ;
STATUS_STRING ( INTERNET_STATUS_COOKIE_RECEIVED ) ;
STATUS_STRING ( INTERNET_STATUS_PRIVACY_IMPACTED ) ;
STATUS_STRING ( INTERNET_STATUS_P3P_HEADER ) ;
STATUS_STRING ( INTERNET_STATUS_P3P_POLICYREF ) ;
STATUS_STRING ( INTERNET_STATUS_COOKIE_HISTORY ) ;
# undef STATUS_STRING
2011-02-03 20:46:05 +01:00
}
2007-07-15 23:29:48 +02:00
2014-09-25 14:21:37 +02:00
static void WINAPI header_cb ( HINTERNET handle , DWORD_PTR ctx , DWORD status , LPVOID info , DWORD len )
{
2016-01-26 11:14:31 +01:00
BOOL ret ;
DWORD index , size ;
char buf [ 256 ] ;
if ( status = = INTERNET_STATUS_SENDING_REQUEST )
{
ret = HttpAddRequestHeadersA ( handle , " winetest: winetest " , ~ 0u , HTTP_ADDREQ_FLAG_ADD ) ;
ok ( ret , " HttpAddRequestHeadersA failed %u \n " , GetLastError ( ) ) ;
SetEvent ( ( HANDLE ) ctx ) ;
}
else if ( status = = INTERNET_STATUS_REQUEST_SENT )
{
index = 0 ;
size = sizeof ( buf ) ;
ret = HttpQueryInfoA ( handle , HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buf , & size , & index ) ;
ok ( ret , " HttpQueryInfoA failed %u \n " , GetLastError ( ) ) ;
ok ( strstr ( buf , " winetest: winetest " ) ! = NULL , " header missing \n " ) ;
SetEvent ( ( HANDLE ) ctx ) ;
}
2014-09-25 14:21:37 +02:00
}
static void test_concurrent_header_access ( void )
{
HINTERNET ses , con , req ;
2016-01-26 11:14:31 +01:00
DWORD err ;
2014-09-25 14:21:37 +02:00
BOOL ret ;
HANDLE wait = CreateEventW ( NULL , FALSE , FALSE , NULL ) ;
ses = InternetOpenA ( " winetest " , 0 , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
ok ( ses ! = NULL , " InternetOpenA failed \n " ) ;
con = InternetConnectA ( ses , " test.winehq.org " , INTERNET_DEFAULT_HTTP_PORT , NULL , NULL ,
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( con ! = NULL , " InternetConnectA failed %u \n " , GetLastError ( ) ) ;
req = HttpOpenRequestA ( con , NULL , " / " , NULL , NULL , NULL , 0 , ( DWORD_PTR ) wait ) ;
ok ( req ! = NULL , " HttpOpenRequestA failed %u \n " , GetLastError ( ) ) ;
pInternetSetStatusCallbackA ( req , header_cb ) ;
SetLastError ( 0xdeadbeef ) ;
ret = HttpSendRequestA ( req , NULL , 0 , NULL , 0 ) ;
err = GetLastError ( ) ;
ok ( ! ret , " HttpSendRequestA succeeded \n " ) ;
ok ( err = = ERROR_IO_PENDING , " got %u \n " , ERROR_IO_PENDING ) ;
2016-01-26 11:14:31 +01:00
WaitForSingleObject ( wait , 5000 ) ;
2014-09-25 14:21:37 +02:00
WaitForSingleObject ( wait , 5000 ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
CloseHandle ( wait ) ;
}
2002-06-22 01:59:49 +02:00
START_TEST ( http )
{
2007-02-20 15:53:49 +01:00
HMODULE hdll ;
hdll = GetModuleHandleA ( " wininet.dll " ) ;
2010-10-19 10:44:03 +02:00
if ( ! GetProcAddress ( hdll , " InternetGetCookieExW " ) ) {
win_skip ( " Too old IE (older than 6.0) \n " ) ;
return ;
2007-02-20 15:53:49 +01:00
}
2010-10-19 10:44:03 +02:00
pInternetSetStatusCallbackA = ( void * ) GetProcAddress ( hdll , " InternetSetStatusCallbackA " ) ;
2013-02-18 15:45:30 +01:00
pInternetSetStatusCallbackW = ( void * ) GetProcAddress ( hdll , " InternetSetStatusCallbackW " ) ;
2012-06-11 10:22:54 +02:00
pInternetGetSecurityInfoByURLA = ( void * ) GetProcAddress ( hdll , " InternetGetSecurityInfoByURLA " ) ;
2010-10-19 10:44:03 +02:00
init_status_tests ( ) ;
2011-05-10 11:26:43 +02:00
test_InternetCloseHandle ( ) ;
2010-10-19 10:44:03 +02:00
InternetReadFile_test ( INTERNET_FLAG_ASYNC , & test_data [ 0 ] ) ;
InternetReadFile_test ( INTERNET_FLAG_ASYNC , & test_data [ 1 ] ) ;
InternetReadFile_test ( 0 , & test_data [ 1 ] ) ;
2011-04-02 15:20:53 +02:00
InternetReadFile_test ( INTERNET_FLAG_ASYNC , & test_data [ 2 ] ) ;
2012-05-25 16:36:46 +02:00
test_security_flags ( ) ;
2011-04-02 15:20:53 +02:00
InternetReadFile_test ( 0 , & test_data [ 2 ] ) ;
2010-10-19 10:44:03 +02:00
InternetReadFileExA_test ( INTERNET_FLAG_ASYNC ) ;
test_open_url_async ( ) ;
2011-11-23 15:45:44 +01:00
test_async_HttpSendRequestEx ( & notification_data [ 0 ] ) ;
test_async_HttpSendRequestEx ( & notification_data [ 1 ] ) ;
2011-12-07 16:40:43 +01:00
test_async_HttpSendRequestEx ( & notification_data [ 2 ] ) ;
2013-09-18 13:40:24 +02:00
test_async_HttpSendRequestEx ( & notification_data [ 3 ] ) ;
2007-02-12 15:19:17 +01:00
InternetOpenRequest_test ( ) ;
2008-02-13 13:33:42 +01:00
test_http_cache ( ) ;
2013-10-04 16:53:34 +02:00
InternetLockRequestFile_test ( ) ;
2003-02-25 04:57:59 +01:00
InternetOpenUrlA_test ( ) ;
2005-11-22 15:53:30 +01:00
HttpHeaders_test ( ) ;
2006-05-16 16:03:45 +02:00
test_http_connection ( ) ;
2010-09-30 18:53:47 +02:00
test_secure_connection ( ) ;
2008-05-02 21:59:24 +02:00
test_user_agent_header ( ) ;
2008-05-07 13:19:37 +02:00
test_bogus_accept_types_array ( ) ;
2009-05-14 16:49:19 +02:00
InternetReadFile_chunked_test ( ) ;
2009-05-10 00:40:03 +02:00
HttpSendRequestEx_test ( ) ;
2011-04-02 15:20:53 +02:00
InternetReadFile_test ( INTERNET_FLAG_ASYNC , & test_data [ 3 ] ) ;
2012-12-19 12:02:36 +01:00
test_connection_failure ( ) ;
2013-03-06 13:30:49 +01:00
test_default_service_port ( ) ;
2014-09-25 14:21:37 +02:00
test_concurrent_header_access ( ) ;
2002-06-22 01:59:49 +02:00
}