MCPcopy Create free account
hub / github.com/awawa-dev/HyperHDR / onRequestNeedsReply

Method onRequestNeedsReply

sources/webserver/FileServer.cpp:135–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135void FileServer::onRequestNeedsReply(QtHttpRequest* request, QtHttpReply* reply)
136{
137 QString command = request->getCommand();
138 if (command == QStringLiteral("GET"))
139 {
140 QString path = request->getUrl().path();
141 QStringList uri_parts = path.split('/', Qt::SkipEmptyParts);
142 // special uri handling for server commands
143 if (!uri_parts.empty())
144 {
145 if (uri_parts.at(0) == "hyperhdr_heart_beat")
146 {
147 reply->addHeader("Content-Type", "text/plain");
148 reply->appendRawData("alive");
149 return;
150 }
151 else if (uri_parts.at(0) == "description.xml" && !_ssdpXmlDesc.isEmpty())
152 {
153 reply->addHeader("Content-Type", "text/xml");
154 reply->appendRawData(_ssdpXmlDesc.toLocal8Bit());
155 return;
156 }
157 }
158
159 QFileInfo info(_baseUrl % "/" % path);
160 if (path == "/" || path.isEmpty())
161 {
162 path = "index.html";
163 }
164 else if (info.isDir() && path.endsWith("/"))
165 {
166 path += "index.html";
167 }
168 else if (info.isDir() && !path.endsWith("/"))
169 {
170 path += "/index.html";
171 }
172
173 // get static files
174 QFile file(_baseUrl % "/" % path);
175 if (file.exists())
176 {
177 QString mimeName = getMimeName(file.fileName());
178 if (file.open(QFile::ReadOnly)) {
179 QByteArray data = file.readAll();
180 reply->addHeader("Content-Type", mimeName.toLocal8Bit());
181 reply->addHeader(QtHttpHeader::AccessControlAllow, "*");
182 reply->appendRawData(data);
183 file.close();
184 }
185 else
186 {
187 printErrorToReply(reply, QtHttpReply::Forbidden, "Requested file: " % path);
188 }
189 }
190 else
191 {
192 printErrorToReply(reply, QtHttpReply::NotFound, "Requested file: " % path);

Callers 1

Calls 7

isEmptyMethod · 0.80
getCommandMethod · 0.45
getUrlMethod · 0.45
addHeaderMethod · 0.45
appendRawDataMethod · 0.45
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected