QSslSocket in non-http protocol
-
Good morning,
I am trying - for the fun of it - connect and parse a page using the Gemini protocol. And I ran into an issue I can't solve, I keep running in circles. I blame my poor knowledge of socket programming.The problem:
I can connect to the host and get the content but only when using domain global address, i.e.somepage.org
Whenever I try to get particular document (think: webpage, just extension is.gmi
instead of.html
) I get an error from the server.The specification of a request is simple:
request = absolute-URI CRLF
My code:
oid GeminiProtocol::fetchPage(const QString &uri) { if (uri.isEmpty()) { qDebug() << "uri empty"; return; } QString query = uri; QString _uri = uri; QStringList parts = query.remove("gemini://").split('/',Qt::SkipEmptyParts); if (socket.state()==QSslSocket::ConnectedState||socket.state()==QSslSocket::ConnectingState) { socket.close(); } _uri.append(QChar::CarriageReturn).append(QChar::LineFeed); socket.connectToHostEncrypted(parts.at(0),_port); socket.write(QByteArray(_uri.toUtf8())); }
The question:
is this boilerplate code above more or less ok (I have slots connected to signals in case of an error etc) or have I missed something? -
@artwaw said in QSslSocket in non-http protocol:
I get an error from the server.
Which error do you get?
Do you get it only with gemini, or also with a normal http request? -
In that case, you may want to debug all the credentials used to connect (
_uri, parts, _port
). Maybe something goes wrong building those. That would explain the 51 coming up all the time. -
@Axel-Spoerl I did that and found nothing out of order. So I posted here, in hope there is something obvious about sockets that I missed - I don't use them very often and never for http related stuff (qnam is good enough).
I shall also download some other gemini client and verify the existence of resources I am trying to reach, it dawned on me that some of links might be out of date. I shall post my findings here and close the thread in due time.
Many thanks for the advice!
-
I can feel the pain. Trying the same requests with another toolset is always a good idea!
Getting curious about what caused the issue. -
@Axel-Spoerl small updates:
- I tried different Gemini browser, namely Sputnik (written in Swift) - works barely better than my prototype but it does work and I could verify the links - they do work, so the problem is within my code somewhere.
- there is a Qt5 multi browser named Kristall, written with Qt5 and long not updated at all. Porting it to Qt6 should not be much of a problem (some outdated classes, like QRegExp but not much of it), porting it to macOS is a bit more complex so I'll not attempt unless bored. BUT. They also use QSslSocket so now I'll have a read through their code and see where did I go wrong.
More updates once I do the read.