Skip to content
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

Merged
merged 2 commits into from
Jul 27, 2018

Conversation

Adrxx
Copy link
Contributor

@Adrxx Adrxx commented Jul 7, 2018

No description provided.

Copy link

@MikeWeller MikeWeller left a 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.

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",

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree to Mike!

@@ -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}",

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;

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;

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

@@ -1,13 +1,13 @@
Pod::Spec.new do |mqttc|
mqttc.name = "MQTTClient"
mqttc.version = "0.14.0"
mqttc.version = "0.14.1"

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.

@Adrxx
Copy link
Contributor Author

Adrxx commented Jul 12, 2018

I have fixed all the problems now, what do you think? ready to merge?

@Adrxx
Copy link
Contributor Author

Adrxx commented Jul 12, 2018

By the way. For some reason if I use the pod like this locally, it crashes with:
-[MQTTWebsocketTransport setUrl:]: unrecognized selector sent to instance I assume it has something to do with another commit #461. What happens in this case? should I go back to tag 0.14.0 and commit my changes there to another branch? Sorry, I'm really new to pull requests hahaha.

@jcavar
Copy link
Contributor

jcavar commented Jul 18, 2018

@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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be NSDictionaryto reflect actual type.

@Adrxx
Copy link
Contributor Author

Adrxx commented Jul 26, 2018

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.
Copy link
Contributor

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"

Copy link
Contributor

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!

@jcavar
Copy link
Contributor

jcavar commented Jul 27, 2018

Thank you @Adrxx!

@jcavar jcavar merged commit bc34a9f into novastone-media:master Jul 27, 2018
@Adrxx
Copy link
Contributor Author

Adrxx commented Jul 27, 2018

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?

@jcavar
Copy link
Contributor

jcavar commented Jul 30, 2018

No, don't worry I will do it.

Which part is copy paste?

@Adrxx
Copy link
Contributor Author

Adrxx commented Aug 1, 2018

@jcavar Ok so turns out the copy-paste is actually from SocketRocket. Apparently AWS made its own SRWebSocket Class called AWSSRWebSocket. You can see it's copy-pasted because the comments are all the same. Comments like:

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants