@@ -76,27 +76,27 @@ static size_t SRDefaultBufferSize(void) {
7676static inline int32_t validate_dispatch_data_partial_string (NSData *data);
7777static inline void SRFastLog (NSString *format, ...);
7878
79+ static uint8_t const SRWebSocketProtocolVersion = 13 ;
80+
7981NSString *const SRWebSocketErrorDomain = @" SRWebSocketErrorDomain" ;
8082NSString *const SRHTTPResponseErrorKey = @" HTTPResponseStatusCode" ;
8183
8284@interface SRWebSocket () <NSStreamDelegate >
8385
84- @property (nonatomic ) SRReadyState readyState;
86+ @property (nonatomic , assign , readwrite ) SRReadyState readyState;
8587
8688// Specifies whether SSL trust chain should NOT be evaluated.
8789// By default this flag is set to NO, meaning only secure SSL connections are allowed.
8890// For DEBUG builds this flag is ignored, and SSL connections are allowed regardless
8991// of the certificate trust configuration
90- @property (nonatomic , readwrite ) BOOL allowsUntrustedSSLCertificates;
92+ @property (nonatomic , assign , readwrite ) BOOL allowsUntrustedSSLCertificates;
9193
9294@property (nonatomic , strong , readonly ) SRDelegateController *delegateController;
9395
9496@end
9597
9698
9799@implementation SRWebSocket {
98- NSInteger _webSocketVersion;
99-
100100 dispatch_queue_t _workQueue;
101101 NSMutableArray <SRIOConsumer *> *_consumers;
102102
@@ -118,14 +118,11 @@ @implementation SRWebSocket {
118118 NSString *_closeReason;
119119
120120 NSString *_secKey;
121- NSString *_basicAuthorizationString;
122121
123122 BOOL _pinnedCertFound;
124123
125124 uint8_t _currentReadMaskKey[4 ];
126125 size_t _currentReadMaskOffset;
127-
128- BOOL _consumerStopped;
129126
130127 BOOL _closeWhenFinishedWriting;
131128 BOOL _failed;
@@ -149,11 +146,6 @@ @implementation SRWebSocket {
149146 SRIOConsumerPool *_consumerPool;
150147}
151148
152- @synthesize delegate = _delegate;
153- @synthesize url = _url;
154- @synthesize readyState = _readyState;
155- @synthesize protocol = _protocol;
156-
157149- (instancetype )initWithURLRequest : (NSURLRequest *)request protocols : (NSArray <NSString *> *)protocols allowsUntrustedSSLCertificates : (BOOL )allowsUntrustedSSLCertificates
158150{
159151 self = [super init ];
@@ -174,8 +166,6 @@ - (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray<NS
174166 }
175167
176168 _readyState = SR_CONNECTING;
177- _consumerStopped = YES ;
178- _webSocketVersion = 13 ;
179169
180170 _workQueue = dispatch_queue_create (NULL , DISPATCH_QUEUE_SERIAL);
181171
@@ -383,25 +373,15 @@ - (void)didConnect;
383373 }];
384374
385375 // set header for http basic auth
386- if (_url.user .length && _url.password .length ) {
387- NSData *userAndPassword = [[NSString stringWithFormat: @" %@ :%@ " , _url.user, _url.password] dataUsingEncoding: NSUTF8StringEncoding];
388- NSString *userAndPasswordBase64Encoded;
389- if ([keyBytes respondsToSelector: @selector (base64EncodedStringWithOptions: )]) {
390- userAndPasswordBase64Encoded = [userAndPassword base64EncodedStringWithOptions: 0 ];
391- } else {
392- #pragma clang diagnostic push
393- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
394- userAndPasswordBase64Encoded = [userAndPassword base64Encoding ];
395- #pragma clang diagnostic pop
396- }
397- _basicAuthorizationString = [NSString stringWithFormat: @" Basic %@ " , userAndPasswordBase64Encoded];
398- CFHTTPMessageSetHeaderFieldValue (request, CFSTR (" Authorization" ), (__bridge CFStringRef)_basicAuthorizationString);
376+ NSString *basicAuthorizationString = SRBasicAuthorizationHeaderFromURL (_url);
377+ if (basicAuthorizationString) {
378+ CFHTTPMessageSetHeaderFieldValue (request, CFSTR (" Authorization" ), (__bridge CFStringRef)basicAuthorizationString);
399379 }
400380
401381 CFHTTPMessageSetHeaderFieldValue (request, CFSTR (" Upgrade" ), CFSTR (" websocket" ));
402382 CFHTTPMessageSetHeaderFieldValue (request, CFSTR (" Connection" ), CFSTR (" Upgrade" ));
403383 CFHTTPMessageSetHeaderFieldValue (request, CFSTR (" Sec-WebSocket-Key" ), (__bridge CFStringRef)_secKey);
404- CFHTTPMessageSetHeaderFieldValue (request, CFSTR (" Sec-WebSocket-Version" ), (__bridge CFStringRef)[ NSString stringWithFormat: @" %ld " , ( long )_webSocketVersion] );
384+ CFHTTPMessageSetHeaderFieldValue (request, CFSTR (" Sec-WebSocket-Version" ), (__bridge CFStringRef)@(SRWebSocketProtocolVersion). stringValue );
405385
406386 CFHTTPMessageSetHeaderFieldValue (request, CFSTR (" Origin" ), (__bridge CFStringRef)SRURLOrigin (_url));
407387
0 commit comments