Author: rfm
Date: Tue Oct 25 11:55:51 2016
New Revision: 40176

URL: http://svn.gna.org/viewcvs/gnustep?rev=40176&view=rev
Log:
Add support for other HTTP methods

Modified:
    libs/webservices/trunk/ChangeLog
    libs/webservices/trunk/GWSService.h
    libs/webservices/trunk/GWSService.m

Modified: libs/webservices/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/webservices/trunk/ChangeLog?rev=40176&r1=40175&r2=40176&view=diff
==============================================================================
--- libs/webservices/trunk/ChangeLog    (original)
+++ libs/webservices/trunk/ChangeLog    Tue Oct 25 11:55:51 2016
@@ -1,3 +1,10 @@
+2016-10-25 Richard Frith-Macdonald  <r...@gnu.org>
+
+       * GWSService.h:
+       * GWSService.m:
+       Add -setHTTPMethod: to control what HTTP method is used by an RPC,
+       so we can use this class for RESTful APIs.
+
 2016-10-24 Niels Grewe <niels.gr...@halbordnung.de>
 
        * GWSCoder.[hm]: Allow XML coders to use the 'sloppy' XML parser.

Modified: libs/webservices/trunk/GWSService.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/webservices/trunk/GWSService.h?rev=40176&r1=40175&r2=40176&view=diff
==============================================================================
--- libs/webservices/trunk/GWSService.h (original)
+++ libs/webservices/trunk/GWSService.h Tue Oct 25 11:55:51 2016
@@ -106,6 +106,7 @@
   id                   _delegate;      // Not retained.
   NSTimeZone           *_tz;
   GWSCoder              *_coder;
+  NSString             *_HTTPMethod;
   NSString             *_SOAPAction;
   BOOL                 _compact;
   BOOL                 _debug;
@@ -350,6 +351,11 @@
  */
 - (void) setHeaders: (NSDictionary*)headers;
 
+/** Sets the value of the HTTP method to be used for a request.<br />
+ * Setting an nil string reverts to the default 'POST' method.<br />
+ */
+- (void) setHTTPMethod: (NSString*)method;
+
 /** Tags the service with entra information in the form of anObject
  * references by aKey.  if anObject is nil, this removes any previous
  * association for aKey.<br />
@@ -359,8 +365,7 @@
  */
 - (void) setObject: (id)anObject forKey: (NSString*)aKey;
 
-/**
- * Sets the value of the SOAPAction header to be sent with a request.<br />
+/** Sets the value of the SOAPAction header to be sent with a request.<br />
  * Setting an nil string value suppresses the sending of this header.<br />
  * Most servers expect two double quotes characters for this,
  * so you should probably set @&quot;\&quot;\&quot;&quot; as the action.<br />

Modified: libs/webservices/trunk/GWSService.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/webservices/trunk/GWSService.m?rev=40176&r1=40175&r2=40176&view=diff
==============================================================================
--- libs/webservices/trunk/GWSService.m (original)
+++ libs/webservices/trunk/GWSService.m Tue Oct 25 11:55:51 2016
@@ -889,6 +889,7 @@
 - (void) _start
 {
   NSData        *toSend;
+  NSString      *method;
 
   [_lock lock];
   if (YES == _cancelled)
@@ -900,6 +901,7 @@
     }
   _stage = RPCActive;
   toSend = [_request retain];
+  method = [_HTTPMethod retain];
   [_lock unlock];
 
   /* Now we initiate the asynchronous I/O process.
@@ -918,7 +920,7 @@
       request = [NSMutableURLRequest alloc];
       request = [request initWithURL: _connectionURL];
       [request setCachePolicy: NSURLRequestReloadIgnoringCacheData];
-      [request setHTTPMethod: @"POST"];  
+      [request setHTTPMethod: method];  
       [request setValue: @"GWSService/0.1.0" forHTTPHeaderField: 
@"User-Agent"];
       if (nil == _contentType)
         {
@@ -993,7 +995,7 @@
          [handle writeProperty: _SOAPAction forKey: @"SOAPAction"];
        }
       [handle addClient: (id<NSURLHandleClient>)self];
-      [handle writeProperty: @"POST" forKey: GSHTTPPropertyMethodKey];
+      [handle writeProperty: method forKey: GSHTTPPropertyMethodKey];
       [handle writeProperty: @"GWSService/0.1.0" forKey: @"User-Agent"];
       if (nil == _contentType)
         {
@@ -1020,6 +1022,7 @@
 #endif
     }
   NSAssert(nil != toSend, NSInternalInconsistencyException);
+  [method release];
   [toSend release];
 }
 
@@ -1393,6 +1396,7 @@
   [_documentation release];
   [_extensibility release];
   [_SOAPAction release];
+  [_HTTPMethod release];
   [_ports release];
   [_name release];
   [_headers release];
@@ -1656,6 +1660,18 @@
 
   [_headers release];
   _headers = tmp;
+}
+
+- (void) setHTTPMethod: (NSString*)method
+{
+  if (0 == [method length]) method = @"POST";
+  if (NO == [_HTTPMethod isEqual: method])
+    {
+      NSString *old = _HTTPMethod;
+
+      _HTTPMethod = [method copy];
+      [old release];
+    }
 }
 
 - (void) setObject: (id)anObject forKey: (NSString*)aKey


_______________________________________________
Gnustep-cvs mailing list
Gnustep-cvs@gna.org
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to