@@ -252,7 +252,7 @@ public class NSURLRequest : NSObject, NSSecureCoding, NSCopying, NSMutableCopyin
252
252
@abstract Returns the HTTP request method of the receiver.
253
253
@result the HTTP request method of the receiver.
254
254
*/
255
- public var HTTPMethod : String ? { get { return " GET " } }
255
+ public var HTTPMethod : String ? { get { return " GET " } }
256
256
257
257
/*!
258
258
@method allHTTPHeaderFields
@@ -308,15 +308,40 @@ public class NSURLRequest : NSObject, NSSecureCoding, NSCopying, NSMutableCopyin
308
308
*/
309
309
public class NSMutableURLRequest : NSURLRequest {
310
310
311
+ private var _HTTPMethod : String ? = " GET "
312
+
311
313
public required init ? ( coder aDecoder: NSCoder ) {
312
314
NSUnimplemented ( )
313
315
}
314
- /*!
316
+
317
+ /*!
318
+ @method initWithURL:
319
+ @abstract Initializes an NSMutableURLRequest with the given URL.
320
+ @discussion Default values are used for cache policy
321
+ (NSURLRequestUseProtocolCachePolicy) and timeout interval (60
322
+ seconds).
323
+ @param URL The URL for the request.
324
+ @result An initialized NSMutableURLRequest.
325
+ */
326
+ public init ( URL: NSURL ) {
327
+ super. init ( )
328
+ _URL = URL
329
+ }
330
+
331
+
332
+ /*!
315
333
@method URL
316
334
@abstract Sets the URL of the receiver.
317
335
@param URL The new URL for the receiver.
318
336
*/
319
- /*@NSCopying */ public override var URL : NSURL ? { get { NSUnimplemented ( ) } set { NSUnimplemented ( ) } }
337
+ /*@NSCopying */ public override var URL : NSURL ? {
338
+ get {
339
+ return _URL
340
+ }
341
+ set ( newURL) {
342
+ _URL = newURL
343
+ }
344
+ }
320
345
321
346
/*!
322
347
@method setMainDocumentURL:
@@ -329,14 +354,27 @@ public class NSMutableURLRequest : NSURLRequest {
329
354
"only from same domain as main document" policy, and possibly
330
355
other things in the future.
331
356
*/
332
- /*@NSCopying*/ public override var mainDocumentURL : NSURL ? { get { NSUnimplemented ( ) } set { NSUnimplemented ( ) } }
357
+ /*@NSCopying*/ public override var mainDocumentURL : NSURL ? {
358
+ get {
359
+ return _mainDocumentURL
360
+ } set ( newMainDocumentURL) {
361
+ _mainDocumentURL = newMainDocumentURL
362
+ }
363
+ }
364
+
333
365
334
366
/*!
335
367
@method HTTPMethod
336
368
@abstract Sets the HTTP request method of the receiver.
337
369
@result the HTTP request method of the receiver.
338
370
*/
339
- public override var HTTPMethod : String ? { get { NSUnimplemented ( ) } set { NSUnimplemented ( ) } }
371
+ public override var HTTPMethod : String ? {
372
+ get {
373
+ return _HTTPMethod
374
+ } set ( newHTTPMethod) {
375
+ _HTTPMethod = newHTTPMethod
376
+ }
377
+ }
340
378
341
379
/*!
342
380
@method setValue:forHTTPHeaderField:
@@ -348,7 +386,12 @@ public class NSMutableURLRequest : NSURLRequest {
348
386
@param value the header field value.
349
387
@param field the header field name (case-insensitive).
350
388
*/
351
- public func setValue( value: String ? , forHTTPHeaderField field: String ) { NSUnimplemented ( ) }
389
+ public func setValue( value: String ? , forHTTPHeaderField field: String ) {
390
+ if _httpHeaderFields == nil {
391
+ _httpHeaderFields = [ : ]
392
+ }
393
+ _httpHeaderFields ? [ field. lowercaseString] = value
394
+ }
352
395
353
396
/*!
354
397
@method addValue:forHTTPHeaderField:
@@ -364,7 +407,16 @@ public class NSMutableURLRequest : NSURLRequest {
364
407
@param value the header field value.
365
408
@param field the header field name (case-insensitive).
366
409
*/
367
- public func addValue( value: String , forHTTPHeaderField field: String ) { NSUnimplemented ( ) }
410
+ public func addValue( value: String , forHTTPHeaderField field: String ) {
411
+ if _httpHeaderFields == nil {
412
+ _httpHeaderFields = [ : ]
413
+ }
414
+ if let oldValue = _httpHeaderFields ? [ field. lowercaseString] {
415
+ _httpHeaderFields ? [ field. lowercaseString] = " \( oldValue) , \( value) "
416
+ } else {
417
+ _httpHeaderFields ? [ field. lowercaseString] = value
418
+ }
419
+ }
368
420
}
369
421
370
422
0 commit comments