[Interest] Get the username:password part of a HTTP request from QTcpSocket

Konrad Rosenbaum konrad at silmor.de
Sun Dec 1 21:26:33 CET 2013


Hi,

On Sunday 01 December 2013, Lucas Betschart wrote:
> I have a HTTP-Server based on QTcpServer.
> 
> Do you have an idea how I could get the authority part of the HTTP
> request? (https://en.wikipedia.org/wiki/URI_scheme#Generic_syntax)
> A request might look like this:
> http://username:password@127.0.0.1:8462<http://127.0.0.1:8462/>
> /method?key=value

If you've got the HTTP-Server class from the outside it should provide you 
with "authority" information.

> From the incomming QTcpSocket I can only get the IP, the port number and
> the data (which includes the query string for HTTP but not the
> authentication part). How can I get the rest of the request?

On the other hand if you are trying to implement HTTP with only limited 
knowledge about the protocol: I strongly suggest you look for alternative 
options - HTTP is trickier than it looks at first.

To name just a few pitfalls that I have encountered with this:
* you have to support 2 radically different protocols: HTTP 0.9 and 1.x
* the latter has 2 dialects: HTTP 1.0 and 1.1 which differ in some key
  details
* there may be a radically different 3rd protocol soon: HTTP 2.0
* in HTTP 1.1 clients can state (POST) requests outright or they can ask
  nicely first - the 100-continue feature
* some clients use the streaming feature (chunked encoding) without reason
  or rhyme (Microsoft's SOAP implementations are particularly bad)


In short: if you do not have the need to access every bit directly use an 
existing server implementation and an easier way to communicate with it. For 
example Apache has modules for the FCGI and SCGI protocols. In this case 
Apache handles the complexities of HTTP while you just have to handle a 
significantly simpler protocol.




	Konrad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 588 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131201/26b38267/attachment.sig>


More information about the Interest mailing list