@@ -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,27 @@ 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
- NSUnimplemented ( )
314
+ super . init ( )
313
315
}
314
- /*!
316
+
317
+ private override init ( ) { super. init ( ) }
318
+
319
+ /*!
315
320
@method URL
316
321
@abstract Sets the URL of the receiver.
317
322
@param URL The new URL for the receiver.
318
323
*/
319
- /*@NSCopying */ public override var URL : NSURL ? { get { NSUnimplemented ( ) } set { NSUnimplemented ( ) } }
324
+ /*@NSCopying */ public override var URL : NSURL ? {
325
+ get {
326
+ return _URL
327
+ }
328
+ set ( newURL) {
329
+ _URL = newURL
330
+ }
331
+ }
320
332
321
333
/*!
322
334
@method setMainDocumentURL:
@@ -329,14 +341,27 @@ public class NSMutableURLRequest : NSURLRequest {
329
341
"only from same domain as main document" policy, and possibly
330
342
other things in the future.
331
343
*/
332
- /*@NSCopying*/ public override var mainDocumentURL : NSURL ? { get { NSUnimplemented ( ) } set { NSUnimplemented ( ) } }
344
+ /*@NSCopying*/ public override var mainDocumentURL : NSURL ? {
345
+ get {
346
+ return _mainDocumentURL
347
+ } set ( newMainDocumentURL) {
348
+ _mainDocumentURL = newMainDocumentURL
349
+ }
350
+ }
351
+
333
352
334
353
/*!
335
354
@method HTTPMethod
336
355
@abstract Sets the HTTP request method of the receiver.
337
356
@result the HTTP request method of the receiver.
338
357
*/
339
- public override var HTTPMethod : String ? { get { NSUnimplemented ( ) } set { NSUnimplemented ( ) } }
358
+ public override var HTTPMethod : String ? {
359
+ get {
360
+ return _HTTPMethod
361
+ } set ( newHTTPMethod) {
362
+ _HTTPMethod = newHTTPMethod
363
+ }
364
+ }
340
365
341
366
/*!
342
367
@method setValue:forHTTPHeaderField:
@@ -348,7 +373,18 @@ public class NSMutableURLRequest : NSURLRequest {
348
373
@param value the header field value.
349
374
@param field the header field name (case-insensitive).
350
375
*/
351
- public func setValue( value: String ? , forHTTPHeaderField field: String ) { NSUnimplemented ( ) }
376
+ public func setValue( value: String ? , forHTTPHeaderField field: String ) {
377
+ if _httpHeaderFields == nil {
378
+ _httpHeaderFields = [ : ]
379
+ }
380
+ if let existingHeader = _httpHeaderFields? . filter ( { ( existingField, _) -> Bool in
381
+ return existingField. lowercaseString == field. lowercaseString
382
+ } ) . first {
383
+ let ( existingField, _) = existingHeader
384
+ _httpHeaderFields? . removeValueForKey ( existingField)
385
+ }
386
+ _httpHeaderFields ? [ field] = value
387
+ }
352
388
353
389
/*!
354
390
@method addValue:forHTTPHeaderField:
@@ -364,7 +400,19 @@ public class NSMutableURLRequest : NSURLRequest {
364
400
@param value the header field value.
365
401
@param field the header field name (case-insensitive).
366
402
*/
367
- public func addValue( value: String , forHTTPHeaderField field: String ) { NSUnimplemented ( ) }
403
+ public func addValue( value: String , forHTTPHeaderField field: String ) {
404
+ if _httpHeaderFields == nil {
405
+ _httpHeaderFields = [ : ]
406
+ }
407
+ if let existingHeader = _httpHeaderFields? . filter ( { ( existingField, _) -> Bool in
408
+ return existingField. lowercaseString == field. lowercaseString
409
+ } ) . first {
410
+ let ( existingField, existingValue) = existingHeader
411
+ _httpHeaderFields ? [ existingField] = " \( existingValue) , \( value) "
412
+ } else {
413
+ _httpHeaderFields ? [ field] = value
414
+ }
415
+ }
368
416
}
369
417
370
418
0 commit comments