From 3e2e0e63cdb9945167228e7a5ea43d96988a57a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 13 Feb 2014 12:27:33 +0100 Subject: [PATCH] BHttpRequest: Improve cookie string building loop... ... to avoid some checks. Does it make the code more readable? Not that it was hard to follow before. --- src/kits/network/libnetapi/HttpRequest.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/kits/network/libnetapi/HttpRequest.cpp b/src/kits/network/libnetapi/HttpRequest.cpp index d1ea31c9c5..46d94f4a0d 100644 --- a/src/kits/network/libnetapi/HttpRequest.cpp +++ b/src/kits/network/libnetapi/HttpRequest.cpp @@ -931,19 +931,22 @@ BHttpRequest::_SendHeaders() // Context cookies if (fOptSetCookies && fContext != NULL) { - BNetworkCookie* cookie; BString cookieString; - for (BNetworkCookieJar::UrlIterator it - = fContext->GetCookieJar().GetUrlIterator(fUrl); - (cookie = it.Next()) != NULL;) { - if (cookieString.Length() > 0) + BNetworkCookieJar::UrlIterator iterator + = fContext->GetCookieJar().GetUrlIterator(fUrl); + BNetworkCookie* cookie = iterator.Next(); + if (cookie != NULL) { + while (true) { + cookieString << cookie->RawCookie(false); + cookie = iterator.Next(); + if (cookie == NULL) + break; cookieString << "; "; - cookieString << cookie->RawCookie(false); - } - - if (cookieString.Length() > 0) + } + fOutputHeaders.AddHeader("Cookie", cookieString); + } } // Write output headers to output stream