Unsolved Is there HTTP parser?
-
Hi, I didn't find any ways to parse HTTP request on my server. I use QNetworkRequest on client side, then it is sended to server. I get only QByteArray on server which I can only convert to QString. (Maybe I am wrong, but I didn't find more information) So how to parse QString? Also, I need to do it without using third-party libraries and frameworks! Check my code below.
//Client request
const QUrl url = QUrl("http://localhost:8080/"); QNetworkRequest request(url); request.setHeader(QNetworkRequest::UserAgentHeader, "Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0"); QNetworkReply *reply = manager->get(request);
// Server side
void Runnable::run() { if(!socketDescriptor) return; QTcpSocket socket; socket.setSocketDescriptor(socketDescriptor); socket.waitForReadyRead(); qDebug() << socket.readAll(); socket.close(); }
-
Hi,
Depending on what you want to do, the cutelyst project might be interesting.
-
@SGaist Unfortunately, I can't use third-party libraries and framewroks.
-
That is what the HTTP protocol does. You send it something it returns something else, or it returns an error. The client sent something to the server. You will need to determine what to send to the client based upon what the client sent. You will have to research the HTTP protocol to determine the appropriate responses to various data requests.
-
Does Qt-labs projects also count as third party ? If not then you should check https://code.qt.io/cgit/qt-labs/qthttpserver.git/
-
https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview
Edit: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
This page references the current standards governing HTTP protocol. It will give you a place to lookup what a message should look like and what a response should look like. It will also give you the codes needed for errors and such. I think implementing a small subset it probably what you are looking for.I am actually surprised there isn't an example in Qt Creator on how to make a server. I did see a note that the link @SGaist provided would eventually be included in Qt. You could learn from that project at the very least. To see how they structure the code.
-
@SGaist Yes, It is forbidden
-
Then at least you can get some inspiration from that module to implement yours.