Commit 1e946d3e authored by Aric Stewart's avatar Aric Stewart Committed by Alexandre Julliard

wininet: HTTP headers reworking.

Redo how headers are handled, eliminating the concept of Standard Headers and allow all headers to be added multiple times. Allow querying of headers with an index to get the multiple headers. Respect response vs request headers in HttpQueryInfo. Add a number of tests to extensively test header adding and replacing.
parent 7e2be17d
......@@ -2030,9 +2030,12 @@ static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD d
LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
WCHAR url[1023];
static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
static const WCHAR szHost[] = {'H','o','s','t',0};
DWORD sizeRequired;
LPHTTPHEADERW Host;
sprintfW(url,szFmt,lpreq->StdHeaders[HTTP_QUERY_HOST].lpszValue,lpreq->lpszPath);
Host = HTTP_GetHeader(lpreq,szHost);
sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
if(!bIsUnicode)
{
......
......@@ -192,7 +192,8 @@ typedef struct
LPWSTR lpszVerb;
LPWSTR lpszRawHeaders;
WININET_NETCONNECTION netConnection;
HTTPHEADERW StdHeaders[HTTP_QUERY_MAX+1];
LPWSTR lpszVersion;
LPWSTR lpszStatusText;
HTTPHEADERW *pCustHeaders;
DWORD nCustHeaders;
} WININETHTTPREQW, *LPWININETHTTPREQW;
......@@ -464,6 +465,8 @@ VOID INTERNET_SendCallback(LPWININETHANDLEHEADER hdr, DWORD dwContext,
DWORD dwInternetStatus, LPVOID lpvStatusInfo,
DWORD dwStatusInfoLength);
LPHTTPHEADERW HTTP_GetHeader(LPWININETHTTPREQW lpwhr, LPCWSTR header);
BOOL NETCON_connected(WININET_NETCONNECTION *connection);
void NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
......
......@@ -1120,6 +1120,9 @@ static void HttpHeaders_test(void)
HINTERNET hSession;
HINTERNET hConnect;
HINTERNET hRequest;
CHAR buffer[256];
DWORD len = 256;
DWORD index = 0;
hSession = InternetOpen("Wine Regression Test",
INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
......@@ -1132,11 +1135,158 @@ static void HttpHeaders_test(void)
NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
ok( hRequest != NULL, "Failed to open request handle\n");
ok(HttpAddRequestHeaders(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD), "Failed to add new header\n");
ok(HttpAddRequestHeaders(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD), "Failed to replace header using HTTP_ADDREQ_FLAG_ADD\n");
index = 0;
len = sizeof(buffer);
strcpy(buffer,"Warning");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
ok(HttpAddRequestHeaders(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
"Failed to add new header\n");
index = 0;
len = sizeof(buffer);
strcpy(buffer,"Warning");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
buffer,&len,&index)==0,"Second Index Should Not Exist\n");
ok(HttpAddRequestHeaders(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
"Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
index = 0;
len = sizeof(buffer);
strcpy(buffer,"Warning");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
buffer,&len,&index)==0,"Third Header Should Not Exist\n");
ok(HttpAddRequestHeaders(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
index = 0;
len = sizeof(buffer);
strcpy(buffer,"Warning");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
buffer,&len,&index)==0,"Third Header Should Not Exist\n");
ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
index = 0;
len = sizeof(buffer);
strcpy(buffer,"Warning");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
buffer,&len,&index)==0,"Third Header Should Not Exist\n");
ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
index = 0;
len = sizeof(buffer);
strcpy(buffer,"Warning");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, 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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
ok(HttpAddRequestHeaders(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
index = 0;
len = sizeof(buffer);
strcpy(buffer,"Warning");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, 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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
ok(HttpAddRequestHeaders(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
index = 0;
len = sizeof(buffer);
strcpy(buffer,"Warning");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, 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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
ok(HttpAddRequestHeaders(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");
index = 0;
len = sizeof(buffer);
strcpy(buffer,"Warning");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
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");
ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
ok(InternetCloseHandle(hSession), "Close session handle failed\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment