abs_uri *Connection::absolute_uri() { abs_uri *ret = new abs_uri; std::string r = req->uri(); std::string h = req->host(); // make sure that r doesn't begin with it's hostname, which can happen if // the server is proxying but accessing a frostbite-served file size_t pos; if ((pos = r.find(h)) != std::string::npos) r = r.substr(pos + h.length()); if (r.front() == '/') r.erase(0,1); URI *uri = new URI(location + r); if (uri->is_valid()) { if(uri->is_directory()) { // if there's no trailing slash then the browser is going to get // really confused. we need to responde with a 301 Moved Permanently // to tell the browser that the real location has a trailing slash if (uri->src().back() != '/') { ret->status = HTTP_301_MOVED; // here we'll add the slash so that Response will know what to // tell the browser to redirect to ret->contents = new URI(req->uri() + '/'); delete uri; return ret; } // otherwise lets iterate through our defaultFiles and see if we can // find an index file that exits for (int i = 0; i < defaultFiles.size(); i++) { if (Utils::exists(uri->src()+defaultFiles[i])) { uri->append(defaultFiles[i]); break; } } } else if(uri->is_file()) { // it's a file, uri is already the absolute uri } } else { ret->status = HTTP_404_NOT_FOUND; ret->contents = nullptr; delete uri; return ret; } ret->status = HTTP_200_OK; ret->contents = uri; return ret; }
// override Status initialize( const osgDB::Options* dbOptions ) { // add the security token to the URL if necessary: URI url = _options.url().value(); OE_DEBUG << LC << "Initial URL: " << url.full() << std::endl; // append token to url in query string is set if (_options.token().isSet()) { std::string token = _options.token().value(); if (!token.empty()) { std::string sep = url.full().find( "?" ) == std::string::npos ? "?" : "&"; url = url.append( sep + std::string("token=") + token ); } } else { OE_DEBUG << LC << "Token not set" << std::endl; } // append layers to url in query string is set .. format is show:1,2,3 if (_options.layers().isSet()) { std::string layers = _options.layers().value(); OE_DEBUG << LC << "_Layers: " << layers << std::endl; if (!layers.empty()) { std::string sep = url.full().find( "?" ) == std::string::npos ? "?" : "&"; url = url.append( sep + std::string("layers=show:") + layers ); } } else { OE_DEBUG << LC << "Layer options not set" << std::endl; } OE_DEBUG << LC << "_map_service URL: " << url.full() << std::endl; // read map service metadata from the server if ( !_map_service.init(url, dbOptions) ) { OE_INFO << LC << "_map_service.init failed: " << _map_service.getError() << std::endl; return Status::Error( Stringify() << "[osgearth] [ArcGIS] map service initialization failed: " << _map_service.getError() ); } _dbOptions = Registry::instance()->cloneOrCreateOptions( dbOptions ); // establish a profile if we don't already have one: if ( !getProfile() ) { const Profile* profile = NULL; if ( _profileConf.isSet() ) { profile = Profile::create( _profileConf.get() ); } else if ( _map_service.getProfile() ) { profile = _map_service.getProfile(); } else { // finally, fall back on lat/long profile = osgEarth::Registry::instance()->getGlobalGeodeticProfile(); } setProfile( profile ); } return STATUS_OK; }