Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 5565423

Browse files
committed
cleaned up URL schemas and their usage
1 parent 54b2289 commit 5565423

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

SocketIO.m

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@
3737
#define DEBUGLOG(...)
3838
#endif
3939

40-
static NSString* kInsecureHandshakeURL = @"http://%@/socket.io/1/?t=%d%@";
41-
static NSString* kInsecureHandshakePortURL = @"http://%@:%d/socket.io/1/?t=%d%@";
42-
static NSString* kSecureHandshakePortURL = @"https://%@:%d/socket.io/1/?t=%d%@";
43-
static NSString* kSecureHandshakeURL = @"https://%@/socket.io/1/?t=%d%@";
44-
static NSString* kForceDisconnectURL = @"%@://%@%@/socket.io/1/xhr-polling/%@?disconnect";
40+
static NSString* kResourceName = @"socket.io";
41+
static NSString* kHandshakeURL = @"%@://%@%@/%@/1/?t=%d%@";
42+
static NSString* kForceDisconnectURL = @"%@://%@%@/%@/1/xhr-polling/%@?disconnect";
4543

4644
float const defaultConnectionTimeout = 10.0f;
4745

@@ -135,29 +133,22 @@ - (void) connectToHost:(NSString *)host
135133
}];
136134

137135
// do handshake via HTTP request
138-
NSString *s;
139-
NSString *format;
140-
if (_port) {
141-
format = _useSecure ? kSecureHandshakePortURL : kInsecureHandshakePortURL;
142-
s = [NSString stringWithFormat:format, _host, _port, rand(), query];
143-
}
144-
else {
145-
format = _useSecure ? kSecureHandshakeURL : kInsecureHandshakeURL;
146-
s = [NSString stringWithFormat:format, _host, rand(), query];
147-
}
148-
DEBUGLOG(@"Connecting to socket with URL: %@", s);
149-
NSURL *url = [NSURL URLWithString:s];
150-
query = nil;
136+
NSString *protocol = _useSecure ? @"https" : @"http";
137+
NSString *port = _port ? [NSString stringWithFormat:@":%d", _port] : @"";
138+
NSString *handshakeUrl = [NSString stringWithFormat:kHandshakeURL, protocol, _host, port, kResourceName, rand(), query];
151139

140+
DEBUGLOG(@"Connecting to socket with URL: %@", handshakeUrl);
141+
query = nil;
152142

153143
// make a request
154-
NSURLRequest *request = [NSURLRequest requestWithURL:url
144+
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:handshakeUrl]
155145
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
156146
timeoutInterval:connectionTimeout];
157147

158148
_handshake = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
159149
[_handshake scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
160150
[_handshake start];
151+
161152
if (_handshake) {
162153
_httpRequestData = [NSMutableData data];
163154
}
@@ -183,7 +174,7 @@ - (void) disconnectForced
183174
{
184175
NSString *protocol = [self useSecure] ? @"https" : @"http";
185176
NSString *port = _port ? [NSString stringWithFormat:@":%d", _port] : @"";
186-
NSString *urlString = [NSString stringWithFormat:kForceDisconnectURL, protocol, _host, port, _sid];
177+
NSString *urlString = [NSString stringWithFormat:kForceDisconnectURL, protocol, _host, port, kResourceName, _sid];
187178
NSURL *url = [NSURL URLWithString:urlString];
188179
DEBUGLOG(@"Force disconnect at: %@", urlString);
189180

0 commit comments

Comments
 (0)