9 #include <QNetworkInterface>
50 d->m_server->listen(QHostAddress::Any, 11111);
61 const QString &url =
"http://%1:11111/music/";
62 const QString &value = prefix.left(prefix.lastIndexOf(
TTK_DOT));
64 for(
const QHostAddress &address : QNetworkInterface::allAddresses())
66 if(address.toString().contains(value))
68 return url.arg(address.toString());
71 return url.arg(
"0.0.0.0");
77 if(d->m_prefix.isEmpty())
80 response->
end(
"Music path prefix is empty");
84 const QRegExp regx(
"^/music/(.*)$");
85 if(regx.indexIn(request->
path()) != -1)
87 response->
setHeader(
"Content-Type",
"audio/mp3");
89 const QString &
name = regx.cap(1);
91 if(file.open(QIODevice::ReadOnly))
94 response->
end(file.readAll());
100 response->
end(
"Resource not found");
106 response->
end(
"You aren't allowed here");
The class of the http response.
QString localAddress(const QString &prefix) const
void close()
Stop the server and listening for new connections.
void end(const QByteArray &data="")
End/finish the response.
The class of the http request.
void setPrefixPath(const QString &path)
The class of the http server.
~QDlnaFileServerPrivate()
The class of the dlna file server private.
The class of the dlna file server.
QDlnaFileServer(QObject *parent=nullptr)
void handleRequest(QHttpRequest *request, QHttpResponse *response)
void setHeader(const QString &field, const QString &value)
Sets a response header field to value.
#define TTK_INIT_PRIVATE(Class)
The class of the ttk private base.
void writeHead(int statusCode)
Writes the header section of the response using status as the response status code.