bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/4] Add cookies to outgoing requests


From: Lubomir Rintel
Subject: [PATCH 3/4] Add cookies to outgoing requests
Date: Mon, 6 Feb 2012 14:39:18 +0100

* Source/NSURLConnection.m (initWithRequest:delegate:):
Add cookies to outgoing requests.
---
 Source/NSURLConnection.m |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/Source/NSURLConnection.m b/Source/NSURLConnection.m
index 914d1b1..36a8553 100644
--- a/Source/NSURLConnection.m
+++ b/Source/NSURLConnection.m
@@ -118,7 +118,7 @@
 
 typedef struct
 {
-  NSURLRequest                 *_request;
+  NSMutableURLRequest          *_request;
   NSURLProtocol                        *_protocol;
   id                           _delegate;      // Not retained
   BOOL                         _debug;
@@ -190,7 +190,26 @@ typedef struct
 {
   if ((self = [super init]) != nil)
     {
-      this->_request = [request copy];
+      this->_request = [request mutableCopyWithZone:NULL];
+
+      /* Enrich the request with appropriate HTTP cookies,
+       * if desired.
+       */
+      if ([this->_request HTTPShouldHandleCookies] == YES)
+       {
+         NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] 
cookiesForURL: [this->_request URL]];
+         if ([cookies count] > 0)
+           {
+             NSDictionary *headers = [NSHTTPCookie 
requestHeaderFieldsWithCookies:cookies];
+             NSEnumerator *enumerator = [headers keyEnumerator];
+             NSString *header;
+             while ((header = [enumerator nextObject]))
+               {
+                 [this->_request addValue:[headers valueForKey:header] 
forHTTPHeaderField:header];
+               }
+           }
+       }
+
       this->_delegate = delegate;
       this->_protocol = [[NSURLProtocol alloc]
        initWithRequest: this->_request
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]