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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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!

* defaults to an empty dictionary
*/
@property (nonatomic, strong) NSDictionary<NSString *, NSString*> *additionalHeaders;



@end
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ - (instancetype)init {
self.tls = false;
self.allowUntrustedCertificates = false;
self.pinnedCertificates = nil;
self.additionalHeaders = @{};
return self;
}

Expand All @@ -37,6 +38,11 @@ - (void)open {

NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[self endpointURL]];
urlRequest.SR_SSLPinnedCertificates = self.pinnedCertificates;

[self.additionalHeaders enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString * _Nonnull obj, BOOL * _Nonnull stop) {
[urlRequest addValue:obj forHTTPHeaderField:key];
}];

NSArray <NSString *> *protocols = @[@"mqtt"];

self.websocket = [[SRWebSocket alloc] initWithURLRequest:urlRequest
Expand Down