winhttp: Fix up headers with wrong termination.
Hans Leidekker
hans at codeweavers.com
Mon Mar 12 06:25:14 CDT 2012
Fixes http://bugs.winehq.org/show_bug.cgi?id=29891
---
dlls/winhttp/request.c | 5 ++++
dlls/winhttp/tests/winhttp.c | 43 +++++++++++++++++++++++++++++++++++++----
2 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c
index 040f79b..8870e50 100644
--- a/dlls/winhttp/request.c
+++ b/dlls/winhttp/request.c
@@ -425,6 +425,11 @@ BOOL add_request_headers( request_t *request, LPCWSTR headers, DWORD len, DWORD
q = p;
while (*q)
{
+ if (q[0] == '\n' && q[1] == '\r')
+ {
+ q[0] = '\r';
+ q[1] = '\n';
+ }
if (q[0] == '\r' && q[1] == '\n') break;
q++;
}
diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c
index da59dd4..dd7ec76 100644
--- a/dlls/winhttp/tests/winhttp.c
+++ b/dlls/winhttp/tests/winhttp.c
@@ -1755,11 +1755,6 @@ static const char okmsg[] =
"Server: winetest\r\n"
"\r\n";
-static const char notokmsg[] =
-"HTTP/1.1 400 Bad Request\r\n"
-"Server: winetest\r\n"
-"\r\n";
-
static const char noauthmsg[] =
"HTTP/1.1 401 Unauthorized\r\n"
"Server: winetest\r\n"
@@ -1985,6 +1980,43 @@ static void test_no_headers(int port)
WinHttpCloseHandle(ses);
}
+static void test_bad_header( int port )
+{
+ static const WCHAR bad_headerW[] =
+ {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ',
+ 't','e','x','t','/','h','t','m','l','\n','\r',0};
+ static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
+ static const WCHAR content_typeW[] = {'C','o','n','t','e','n','t','-','T','y','p','e',0};
+ WCHAR buffer[32];
+ HINTERNET ses, con, req;
+ DWORD index, len;
+ BOOL ret;
+
+ ses = WinHttpOpen( test_useragent, 0, NULL, NULL, 0 );
+ ok( ses != NULL, "failed to open session %u\n", GetLastError() );
+
+ con = WinHttpConnect( ses, localhostW, port, 0 );
+ ok( con != NULL, "failed to open a connection %u\n", GetLastError() );
+
+ req = WinHttpOpenRequest( con, NULL, NULL, NULL, NULL, NULL, 0 );
+ ok( req != NULL, "failed to open a request %u\n", GetLastError() );
+
+ ret = WinHttpAddRequestHeaders( req, bad_headerW, ~0u, WINHTTP_ADDREQ_FLAG_ADD );
+ ok( ret, "failed to add header %u\n", GetLastError() );
+
+ index = 0;
+ buffer[0] = 0;
+ len = sizeof(buffer);
+ ret = WinHttpQueryHeaders( req, WINHTTP_QUERY_CUSTOM|WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
+ content_typeW, buffer, &len, &index );
+ ok( ret, "failed to query headers %u\n", GetLastError() );
+ ok( !lstrcmpW( buffer, text_htmlW ), "got %s\n", wine_dbgstr_w(buffer) );
+
+ WinHttpCloseHandle( req );
+ WinHttpCloseHandle( con );
+ WinHttpCloseHandle( ses );
+}
+
static void test_credentials(void)
{
static WCHAR userW[] = {'u','s','e','r',0};
@@ -2714,6 +2746,7 @@ START_TEST (winhttp)
test_basic_request(si.port, NULL, basicW);
test_no_headers(si.port);
test_basic_authentication(si.port);
+ test_bad_header(si.port);
/* send the basic request again to shutdown the server thread */
test_basic_request(si.port, NULL, quitW);
--
1.7.9.1
More information about the wine-patches
mailing list