Fixed -serverURL not taking into account GCDWebServerOption_BindToLocalhost

This commit is contained in:
Pierre-Olivier Latour
2015-04-13 13:02:52 -07:00
parent 0f0a9840e4
commit 0a9d3105fc
+4 -1
View File
@@ -171,6 +171,7 @@ static void _ExecuteMainThreadRunLoopSources() {
dispatch_source_t _source6;
CFNetServiceRef _registrationService;
CFNetServiceRef _resolutionService;
BOOL _bindToLocalhost;
#if TARGET_OS_IPHONE
BOOL _suspendInBackground;
UIBackgroundTaskIdentifier _backgroundTask;
@@ -554,6 +555,7 @@ static inline NSString* _EncodeBase64(NSString* string) {
_source4 = [self _createDispatchSourceWithListeningSocket:listeningSocket4 isIPv6:NO];
_source6 = [self _createDispatchSourceWithListeningSocket:listeningSocket6 isIPv6:YES];
_port = port;
_bindToLocalhost = bindToLocalhost;
NSString* bonjourName = _GetOption(_options, GCDWebServerOption_BonjourName, nil);
NSString* bonjourType = _GetOption(_options, GCDWebServerOption_BonjourType, @"_http._tcp");
@@ -619,6 +621,7 @@ static inline NSString* _EncodeBase64(NSString* string) {
#endif
_source4 = NULL;
_port = 0;
_bindToLocalhost = NO;
_serverName = nil;
_authenticationRealm = nil;
@@ -715,7 +718,7 @@ static inline NSString* _EncodeBase64(NSString* string) {
- (NSURL*)serverURL {
if (_source4) {
NSString* ipAddress = GCDWebServerGetPrimaryIPAddress(NO); // We can't really use IPv6 anyway as it doesn't work great with HTTP URLs in practice
NSString* ipAddress = _bindToLocalhost ? @"localhost" : GCDWebServerGetPrimaryIPAddress(NO); // We can't really use IPv6 anyway as it doesn't work great with HTTP URLs in practice
if (ipAddress) {
if (_port != 80) {
return [NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%i/", ipAddress, (int)_port]];