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
Implement NSHTTPURLResponse #287
Conversation
Note: This changes the type of |
That actually makes sense since the init method is It seems like that might just be an oversight for the property. I will follow up with that component owner to determine if it is actually the case that it can never be anything but strings. |
@phausler The same goes for |
@@ -167,9 +178,9 @@ public class NSHTTPURLResponse : NSURLResponse { | |||
@result A dictionary containing all the HTTP header fields of the | |||
receiver. | |||
*/ | |||
public var allHeaderFields: [NSObject : AnyObject] { NSUnimplemented() } | |||
public let allHeaderFields: [String : String] |
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.
This should have a comment on why the differential and identifying it as an "experimental" change; albeit that I agree that this should be the signature, I have not yet heard back from the component owner on a definitive reason on either why it should or should not be marked as string to string.
looks pretty good to me. |
Should this be assigned to @salgernon ? |
82a818e
to
8bb8ce7
Compare
I rebased against master and squashed the 3 commits into a single commit. |
The tests seem to have some failures when it is tested against the objective-c version for me:
|
The failure in |
I've addressed the difference to Objective-C Foundation with the 4 above commits. |
I tend to agree that probably the failure of |
@swift-ci Please test |
I’ll squash the commits into a single commit… |
9ad8740
to
12a1b4e
Compare
@swift-ci please test |
12a1b4e
to
e352c67
Compare
e352c67
to
d55f3fa
Compare
@swift-ci please test |
/// | ||
/// - Important: This is an *experimental* change from the | ||
/// `[NSObject: AnyObject]` type that Darwin Foundation uses. | ||
public let allHeaderFields: [String: String] |
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.
This doesn't match the behavior of the real Foundation. Specifically, allHeaderFields
uses a custom NSDictionary
subclass that's case-insensitive when looking up keys. That case-insensitive behavior is pretty important behavior when dealing with HTTP headers.
It also canonicalizes certain headers, e.g. Content-Length
, although it doesn't document which headers (besides Content-Length), and the canonicalization really only affects the case where you're displaying the header name so it's not really particularly important.
Given that Swift dictionaries are a value type and not a class, the only way we're going to get the same behavior while still using a dictionary type is to rely on bridging support and using an NSDictionary
subclass, like the real Foundation does.
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.
Also note that this has to handle the case where the same header is provided with different capitalizations to the initializer (in that event, the resulting allHeaderFields
dictionary should only contain one of the equivalent keys and its corresponding value, and the conflicts should be discarded).
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.
Good point. Can you open a bug on that and assign it to me? Thanks.
[test] Fix notification handler test when run in serial
This implements both the trivial attributes (
statusCode
andallHeaderFields
), and also parses the headers in order to set the following attributes:Added tests for these.
The
method on
NSHTTPURLResponse
is still unimplemented.