37
37
#define DEBUGLOG (...)
38
38
#endif
39
39
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" ;
45
43
46
44
float const defaultConnectionTimeout = 10 .0f ;
47
45
@@ -135,29 +133,22 @@ - (void) connectToHost:(NSString *)host
135
133
}];
136
134
137
135
// 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];
151
139
140
+ DEBUGLOG (@" Connecting to socket with URL: %@ " , handshakeUrl);
141
+ query = nil ;
152
142
153
143
// make a request
154
- NSURLRequest *request = [NSURLRequest requestWithURL: url
144
+ NSURLRequest *request = [NSURLRequest requestWithURL: [ NSURL URLWithString: handshakeUrl]
155
145
cachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData
156
146
timeoutInterval: connectionTimeout];
157
147
158
148
_handshake = [[NSURLConnection alloc ] initWithRequest: request delegate: self startImmediately: NO ];
159
149
[_handshake scheduleInRunLoop: [NSRunLoop mainRunLoop ] forMode: NSDefaultRunLoopMode ];
160
150
[_handshake start ];
151
+
161
152
if (_handshake) {
162
153
_httpRequestData = [NSMutableData data ];
163
154
}
@@ -183,7 +174,7 @@ - (void) disconnectForced
183
174
{
184
175
NSString *protocol = [self useSecure ] ? @" https" : @" http" ;
185
176
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];
187
178
NSURL *url = [NSURL URLWithString: urlString];
188
179
DEBUGLOG (@" Force disconnect at: %@ " , urlString);
189
180
0 commit comments