IniConfigT::Iterator::Iterator(const FieldMap &container, ConstStrA section, ConstStrA prefix) :innerIter(container.seek(SectionField(section,ConstStrA()))) { if (innerIter.hasItems()) { const FieldMap::Entity &e = innerIter.peek(); if (e.key.section == section) { this->section = e.key.section; if (e.key.field.head(prefix.length()) == prefix) { prefix = e.key.field.head(prefix.length()); } } } }
SeqFileInput HttpClient::send(ConstStrA body) { if (request == null) { try { sendRequest(body.length(), psoAvoid100); request->writeAll(body.data(), body.length()); request->closeOutput(); loadResponse(); return SeqFileInput(response.get()); } catch (NetworkException &) { if (connectionReused) { closeConnection(); return send(body); } throw; } } else { return send(); } }
void HttpClient::createRequest(ConstStrA url, Method method) { connectionReused = false; TextParser<char, SmallAlloc<1024> > parser; if (parser("http%(?)[s]1://%(*)*2%%[a-zA-Z0-9-_.:]3/%(*)4",url)) { ConstStrA s = parser[1].str(); ConstStrA auth = parser[2].str(); ConstStrA domain_port = parser[3].str(); ConstStrA path = parser[4].str(); path = url.tail(path.length()+1); if (!s.empty() && s != "s") throw InvalidUrlException(THISLOCATION,url,"unknown protocol"); if (!auth.empty() && s.tail(1)[0] != '@') throw InvalidUrlException(THISLOCATION,url,"auth need '@' as separator"); if (domain_port.tail(1)[0] == ':') throw InvalidUrlException(THISLOCATION,url,"missing port number"); bool tls = !s.empty(); IHttpProxyProvider::Result proxyInfo; if (proxyProvider) { proxyInfo = proxyProvider->getProxy(domain_port); } if (canReuseConnection(domain_port, tls)) { try { response->skipRemainBody(); connectionReused = true; } catch (const NetworkException &) { response = nil; nstream = nil; } } if (!connectionReused) { if (tls) { if (httpsProvider == 0) { throw InvalidUrlException(THISLOCATION,url,"Https is not configured"); } PNetworkStream stream; if (proxyInfo.defined) { stream = connectSite(proxyInfo.proxyAddr,8080); proxyConnect(stream, domain_port, proxyInfo.authorization); } else { stream = connectSite(domain_port, 443); } stream = httpsProvider->connectTLS(stream,domain_port); nstream = new BufferedNetworkStream(stream); currentDomain = domain_port; currentTls = true; } else { if (proxyInfo.defined) { PNetworkStream stream; stream = connectSite(proxyInfo.proxyAddr,8080); nstream = new BufferedNetworkStream(stream); path = url; currentDomain = proxyInfo.proxyAddr; } else { PNetworkStream stream; stream = connectSite(domain_port,80); nstream = new BufferedNetworkStream(stream); currentDomain = domain_port; } } } response = nil; request = new(pool) HttpRequest(nstream.get(),path,method,!useHTTP10); if (proxyInfo.defined && !tls && !proxyInfo.authorization.empty()) { request->setHeader(fldProxyAuthorization, proxyInfo.authorization); } request->setHeader(fldHost, domain_port); request->setHeader(fldUserAgent, userAgent); if (keepAlive == false) { request->setHeader(fldConnection,"close"); } else if (useHTTP10) { request->setHeader(fldConnection,"keep-alive"); } } else { throw InvalidUrlException(THISLOCATION,url,"Parser rejected"); } }
WordID getWordId(ConstStrA word) { Crc32 crc32; crc32.blockWrite(reinterpret_cast<const byte *>(word.data()), word.length()); return crc32.getCrc32(); }