RequestURI::RequestURI(const VirtualHost *vhost, Transport *transport, const std::string &pathTranslation, const std::string &sourceRoot) : m_rewritten(false), m_defaultDoc(false), m_done(false), m_forbidden(false), m_ext(nullptr) { if (!process(vhost, transport, sourceRoot, pathTranslation, transport->getServerObject()) || (m_forbidden && RuntimeOption::ForbiddenAs404)) { m_forbidden = false; // put down forbidden flag since we are redirecting if (!RuntimeOption::ErrorDocument404.empty()) { String redirectURL(RuntimeOption::ErrorDocument404); if (!m_queryString->empty()) { if (redirectURL.find('?') == -1) { redirectURL += "?"; } else { // has query in 404 string redirectURL += "&"; } redirectURL += m_queryString; } if (process(vhost, transport, sourceRoot, pathTranslation, redirectURL.data())) { // 404 redirection succeed return; } } transport->sendString("Not Found", 404); transport->onSendEnd(); m_done = true; } }
RequestURI::RequestURI(const VirtualHost *vhost, Transport *transport, const std::string &sourceRoot, const std::string &pathTranslation) : m_rewritten(false), m_defaultDoc(false), m_done(false) { if (!process(vhost, transport, sourceRoot, pathTranslation, transport->getUrl())) { if (!RuntimeOption::ErrorDocument404.empty()) { String redirectURL(RuntimeOption::ErrorDocument404); if (m_queryString != "") { if (redirectURL.find('?') == -1) { redirectURL += "?"; } else { // has query in 404 string redirectURL += "&"; } redirectURL += m_queryString; } if (process(vhost, transport, sourceRoot, pathTranslation, redirectURL.data())) { // 404 redirection succeed return; } } transport->sendString("Not Found", 404); m_done = true; } }
void ShoutCastIODevice::socketReadyRead(void) { // only read enough data to fill our buffer int available = DecoderIOFactory::DefaultBufferSize - m_buffer->readBufAvail(); QByteArray data = m_socket->read(available); m_bytesDownloaded += data.size(); m_buffer->write(data); // send buffer status event emit bufferStatus(m_buffer->readBufAvail(), DecoderIOFactory::DefaultBufferSize); if (!m_started && m_bytesDownloaded > DecoderIOFactory::DefaultPrebufferSize) { m_socket->setReadBufferSize(DecoderIOFactory::DefaultPrebufferSize); m_started = true; } // if we are waiting for the HEADER and we have enough data process that if (m_state == READING_HEADER) { if (parseHeader()) { if (m_response->getStatus() == 200) { switchToState(PLAYING); m_response_gotten = true; m_bytesTillNextMeta = m_response->getMetaint(); switchToState(STREAMING); } else if (m_response->getStatus() == 302 || m_response->getStatus() == 301) { if (++m_redirects > MAX_REDIRECTS) { LOG(VB_NETWORK, LOG_ERR, QString("Too many redirects")); switchToState(STOPPED); } else { LOG(VB_NETWORK, LOG_INFO, QString("Redirect to %1").arg(m_response->getLocation())); m_socket->close(); QUrl redirectURL(m_response->getLocation()); connectToUrl(redirectURL); return; } } else { LOG(VB_NETWORK, LOG_ERR, QString("Unknown response status %1") .arg(m_response->getStatus())); switchToState(STOPPED); } } } }
void registerRedirect(const WebString& fromURL, const WebString& toURL) { KURL redirectURL(ParsedURLString, fromURL); WebURLResponse redirectResponse; redirectResponse.setURL(redirectURL); redirectResponse.setHTTPStatusCode(301); redirectResponse.setHTTPHeaderField(HTTPNames::Location, toURL); redirectResponse.addToEncodedDataLength(kRedirectResponseOverheadBytes); Platform::current()->getURLLoaderMockFactory()->registerURL( redirectURL, redirectResponse, ""); }