-
Notifications
You must be signed in to change notification settings - Fork 467
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
🙌 - Added option for custom extra headers in Websocket Transport #484
Conversation
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.
I'm not involved in MQTT-Client-Framework at all, but I'm leaving a few comments as my team was in the process of making similar changes.
MQTTClient.podspec
Outdated
mqttc.summary = "iOS, macOS and tvOS native ObjectiveC MQTT Client Framework" | ||
mqttc.homepage = "https://github.com/novastone-media/MQTT-Client-Framework" | ||
mqttc.license = { :type => "EPLv1", :file => "LICENSE" } | ||
mqttc.author = { "novastonemedia" => "ios@novastonemedia.com" } | ||
mqttc.source = { | ||
:git => "https://github.com/novastone-media/MQTT-Client-Framework.git", | ||
:tag => "0.14.0", | ||
:git => "https://github.com/ment-mx/MQTT-Client-Framework.git", |
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.
I'm guessing this change should not go in
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.
I agree to Mike!
MQTTClient.podspec
Outdated
@@ -75,15 +75,15 @@ Pod::Spec.new do |mqttc| | |||
end | |||
|
|||
mqttc.subspec 'Manager' do |manager| | |||
manager.source_files = "MQTTClient/MQTTClient/MQTTSessionManager.{h,m}", | |||
manager.source_files = "MQTTClient/MQTTClient/MQTTSessionManager.{h,m}", |
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.
Probably best to keep these whitespace-only changes out of this diff
/** customHeaders an NSMutableDictionary containing extra headers sent when stablishing the websocket connection. Useful for custom authorization protocols. e.g. AWS IoT Custom Auth. | ||
* defaults to an empty dictionary | ||
*/ | ||
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSString*> *extraHeaders; |
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.
It may be better to just make this a regular NSDictionary *
with copy
semantics, rather than have clients dive into a mutable data type and add/remove items. Although I don't see any existing threading/synchronization code, it makes things a little easier to reason about from a concurrency point of view. It will also bridge into Swift better: the property as is will currently bridge into Swift as an NSMutableDictionary
reference type, whereas using copy
and NSDictionary
it will bridge as [String: String]
which would be better IMO.
Then again if this is made copy
I would also want to change the other array and string properties here copy
which is generally good practice anyway to avoid people setting an instance of a mutable type and changing it from underneath us. But that probably doesn't make sense as part of this review.
/** customHeaders an NSMutableDictionary containing extra headers sent when stablishing the websocket connection. Useful for custom authorization protocols. e.g. AWS IoT Custom Auth. | ||
* defaults to an empty dictionary | ||
*/ | ||
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSString*> *extraHeaders; |
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 a slight inconsistency with the property name and the doc comment here. I would probably name this additionalHeaders
which resembles the httpAdditionalHeaders
on URLSessionConfiguration
(just to pick an example of something similar from Apple themselves), or maybe even more explicitly additionalConnectHeaders
.
Also stablishing
should be establishing
MQTTClient.podspec
Outdated
@@ -1,13 +1,13 @@ | |||
Pod::Spec.new do |mqttc| | |||
mqttc.name = "MQTTClient" | |||
mqttc.version = "0.14.0" | |||
mqttc.version = "0.14.1" |
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.
I'm guessing this should be an increment of the minor version, i.e. bump to 0.15.0 (or maybe that would be another PR for a release) since this is a feature enhancement rather than a bug fix.
I have fixed all the problems now, what do you think? ready to merge? |
By the way. For some reason if I use the pod like this locally, it crashes with: |
@Adrxx can you just merge master to your branch? I think that should fix it. |
@@ -49,6 +49,12 @@ | |||
* defaults to nil | |||
*/ | |||
@property (strong, nonatomic) NSArray *pinnedCertificates; | |||
|
|||
/** additionalHeaders an NSMutableDictionary containing extra headers sent when stablishing the websocket connection. Useful for custom authorization protocols. e.g. AWS IoT Custom Auth. |
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 be NSDictionary
to reflect actual type.
Done! @jcavar Also now everything is merged to master, I think I have finally fixed everything 😄 |
@@ -44,6 +44,12 @@ | |||
* defaults to nil | |||
*/ | |||
@property (strong, nonatomic) NSArray *pinnedCertificates; | |||
|
|||
/** additionalHeaders an NSDictionary containing extra headers sent when stablishing the websocket connection. Useful for custom authorization protocols. e.g. AWS IoT Custom Auth. |
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.
I think another typo here: "stablishing"
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.
But that is fine, I am merging this!
Thank you @Adrxx! |
You're welcome @jcavar! Sorry, I missed that one. Are you gonna make the correction of the typo? do you have final control of what gets merged? Let me know If I can help. By the way, I did this because the AWS IoT sampled lacked this functionality, then I realized their code https://github.com/awslabs/aws-sdk-ios-samples/tree/master/IoT-Sample/Swift is kind of a copy-paste of yours. Did you already know that? |
No, don't worry I will do it. Which part is copy paste? |
@jcavar Ok so turns out the copy-paste is actually from SocketRocket. Apparently AWS made its own NSAssert(self.readyState != SR_CONNECTING, @"Invalid State: Cannot call send: until connection is open");
// TODO: maybe not copy this for performance
data = [data copy]; I mean, I just thought it was interesting. I don't think there's anything wrong with it. |
No description provided.