-
Notifications
You must be signed in to change notification settings - Fork 1.2k
NSMutableURLRequest implementation #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f876e47
NSMutableURLRequest initialization and getters
ChrisChares 45e1bd8
NSMutableURLRequest tests
ChrisChares 370af15
NSMutableURLRequest HTTPHeaderFields are now stored case sensitive bu…
ChrisChares e1fd867
Override NSURLRequest's private initializer so as to inherit NSURLReq…
ChrisChares File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,7 +252,7 @@ public class NSURLRequest : NSObject, NSSecureCoding, NSCopying, NSMutableCopyin | |
@abstract Returns the HTTP request method of the receiver. | ||
@result the HTTP request method of the receiver. | ||
*/ | ||
public var HTTPMethod: String? { get { return "GET" }} | ||
public var HTTPMethod: String? { get { return "GET" } } | ||
|
||
/*! | ||
@method allHTTPHeaderFields | ||
|
@@ -308,15 +308,39 @@ public class NSURLRequest : NSObject, NSSecureCoding, NSCopying, NSMutableCopyin | |
*/ | ||
public class NSMutableURLRequest : NSURLRequest { | ||
|
||
private var _HTTPMethod: String? = "GET" | ||
|
||
public required init?(coder aDecoder: NSCoder) { | ||
NSUnimplemented() | ||
} | ||
/*! | ||
|
||
/*! | ||
@method initWithURL: | ||
@abstract Initializes an NSMutableURLRequest with the given URL. | ||
@discussion Default values are used for cache policy | ||
(NSURLRequestUseProtocolCachePolicy) and timeout interval (60 | ||
seconds). | ||
@param URL The URL for the request. | ||
@result An initialized NSMutableURLRequest. | ||
*/ | ||
public init(URL: NSURL) { | ||
super.init() | ||
_URL = URL | ||
} | ||
|
||
/*! | ||
@method URL | ||
@abstract Sets the URL of the receiver. | ||
@param URL The new URL for the receiver. | ||
*/ | ||
/*@NSCopying */ public override var URL: NSURL? { get { NSUnimplemented() } set { NSUnimplemented() } } | ||
/*@NSCopying */ public override var URL: NSURL? { | ||
get { | ||
return _URL | ||
} | ||
set(newURL) { | ||
_URL = newURL | ||
} | ||
} | ||
|
||
/*! | ||
@method setMainDocumentURL: | ||
|
@@ -329,14 +353,27 @@ public class NSMutableURLRequest : NSURLRequest { | |
"only from same domain as main document" policy, and possibly | ||
other things in the future. | ||
*/ | ||
/*@NSCopying*/ public override var mainDocumentURL: NSURL? { get { NSUnimplemented() } set { NSUnimplemented() } } | ||
/*@NSCopying*/ public override var mainDocumentURL: NSURL? { | ||
get { | ||
return _mainDocumentURL | ||
} set(newMainDocumentURL) { | ||
_mainDocumentURL = newMainDocumentURL | ||
} | ||
} | ||
|
||
|
||
/*! | ||
@method HTTPMethod | ||
@abstract Sets the HTTP request method of the receiver. | ||
@result the HTTP request method of the receiver. | ||
*/ | ||
public override var HTTPMethod: String? { get { NSUnimplemented() } set { NSUnimplemented() } } | ||
public override var HTTPMethod: String? { | ||
get { | ||
return _HTTPMethod | ||
} set(newHTTPMethod) { | ||
_HTTPMethod = newHTTPMethod | ||
} | ||
} | ||
|
||
/*! | ||
@method setValue:forHTTPHeaderField: | ||
|
@@ -348,7 +385,12 @@ public class NSMutableURLRequest : NSURLRequest { | |
@param value the header field value. | ||
@param field the header field name (case-insensitive). | ||
*/ | ||
public func setValue(value: String?, forHTTPHeaderField field: String) { NSUnimplemented() } | ||
public func setValue(value: String?, forHTTPHeaderField field: String) { | ||
if _httpHeaderFields == nil { | ||
_httpHeaderFields = [:] | ||
} | ||
_httpHeaderFields?[field.lowercaseString] = value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Obj-C Foundation framework preserves the capitalization as entered (as seen in what is returned from |
||
} | ||
|
||
/*! | ||
@method addValue:forHTTPHeaderField: | ||
|
@@ -364,7 +406,16 @@ public class NSMutableURLRequest : NSURLRequest { | |
@param value the header field value. | ||
@param field the header field name (case-insensitive). | ||
*/ | ||
public func addValue(value: String, forHTTPHeaderField field: String) { NSUnimplemented() } | ||
public func addValue(value: String, forHTTPHeaderField field: String) { | ||
if _httpHeaderFields == nil { | ||
_httpHeaderFields = [:] | ||
} | ||
if let oldValue = _httpHeaderFields?[field.lowercaseString] { | ||
_httpHeaderFields?[field.lowercaseString] = "\(oldValue),\(value)" | ||
} else { | ||
_httpHeaderFields?[field.lowercaseString] = value | ||
} | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the superclass handle this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL: yea interesting - it does not seem to have the funnel behavior i would have guessed either. In short this seems fine to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey sorry I think I deleted that comment too quick, didn't know you'd get to it that fast. NSMutableURLRequest wasn't overriding NSURLRequest's private blank initializer, so the convenience initializers weren't being passed down