SFML community forums

General => Feature requests => Topic started by: jankowalski25 on July 17, 2014, 11:12:29 am

Title: Better controlled HTTP connections
Post by: jankowalski25 on July 17, 2014, 11:12:29 am
Quote
Quote
I want to move Http::Request and Http::Response classes outside the Http.hpp file
But why?
Quote
My next task is creating Http::Client
How will it differ from the current sf::Http class?
Quote
and Http::Server
Are you really going to implement an HTTP server? Why?
Before submitting code without explaining anything, why don't you come on the forum to discuss your plans?
I need better control, so I am trying to create something like this:
Http (base class for HTTP client and server)
Client (inherited from Http)
Server (inherited from Http)
Request (friends: Client,Server)
Response (friends: Client,Server)
Title: Re: Better controlled HTTP connections
Post by: Nexus on July 17, 2014, 11:55:35 am
First, you should mention that this discussion continues the pull request #663 (https://github.com/SFML/SFML/pull/663).

You are still not explaining anything, just listing some classes without telling why you need them. Implementation details are completely irrelevant if you don't explain the semantics. "Better control" is a really too vague in this context -- what exactly cannot be achieved with the current API?

And what's the point in inheriting Client and Server from Http if they don't add anything?
Title: Re: Better controlled HTTP connections
Post by: jankowalski25 on August 05, 2014, 10:27:57 am
Let's use packets!

I agree that my first plans are complicated to understand and implement. However, now I have second idea. Maybe it will be easier to manage HTTP requests and responses via packets? I am talking about sf::Http::Request and sf::Http::Response inherited from sf::Packet and prepared to manage data as other packets.
Quote
what exactly cannot be achieved with the current API?
I can do what I want by using raw bytes, but I need something higher-level than this and lower-level than current code for HTTP.
Title: Re: Better controlled HTTP connections
Post by: Laurent on August 05, 2014, 10:44:06 am
Quote
Maybe it will be easier to manage HTTP requests and responses via packets? I am talking about sf::Http::Request and sf::Http::Response inherited from sf::Packet and prepared to manage data as other packets.
HTTP requests and responses are text based. sf::Packet deals with binary data. So it doesn't look like we could get something interesting by mixing both :P
Title: Re: Better controlled HTTP connections
Post by: jankowalski25 on August 07, 2014, 03:40:46 pm
Streams instead packets?

Quote
HTTP requests and responses are text based. sf::Packet deals with binary data.
Both are streams based, so it should be possible to access requests and responses by streams (of course higher-level than raw bytes streams and not binary data).
Title: Re: Better controlled HTTP connections
Post by: Laurent on August 07, 2014, 03:48:37 pm
Can you be more specific about what you suggest? "Stream" is a very vague word, it doesn't mean much outside a specific context.
Title: Re: Better controlled HTTP connections
Post by: jankowalski25 on August 07, 2014, 08:57:24 pm
Quote
what you suggest? "Stream" is a very vague word
Current sf::Http class uses HTTP requests and responses instead of raw bytes. I am trying to create general code to replace raw bytes by requests and responses (it may be useful not only for HTTP connections).
Title: Re: Better controlled HTTP connections
Post by: Laurent on August 07, 2014, 09:57:09 pm
I still don't get it. Maybe some pseudo-code or examples would help.
Title: Re: Better controlled HTTP connections
Post by: jankowalski25 on August 08, 2014, 07:47:31 pm
Example for client and server (not only for HTTP connections):
//client
client.connect(host,port);
while(running)
{
    prepare(request);
    client.send(request);
    client.receive(response);
    doSomethingWith(response);
}
//server
server.listen(port);
server.accept(client);
while(running)
{
    server.receive(client,request);
    doSomethingWith(request);
    prepare(response);
    server.send(client,response);
}
Now I am writing a new code to make it work.
Title: Re: Better controlled HTTP connections
Post by: jankowalski25 on August 11, 2014, 09:33:54 pm
Now I can describe how I am trying to implement mentioned features. I have not finished my code yet, I am just showing my current plans. All suggestions are welcome.
Classes
Description
These classes allow other classes inherited from them sending and receiving plain text (std::string). Data are placed in sf::Request and sf::Response classes.
Base class for all requests and responses. It contains plain text (std::string). It allows only to read it (const std::string&), changing it is protected - only other classes inherited from this class can do it.
They contain functions for changing data between plain text and formatted text.
They are using TCP and UDP protocols to send and receive data.
Contain data used in both, HTTP requests and responses.
They contain only their own data, not stored in sf::Http. These classes can do more than in current version. They allow to read all fields, also these with unknown names. I also changed methods' names (for example getField() to findField()). Case sensivity is an option - you do not have to use it if you do not need it.
I am not sure, but only implementation and inheritation diagram for this class should be different. New features are placed in other classes.
Only basic HTTP server, not something like apache. Not much more advanced than client.
Title: Re: Better controlled HTTP connections
Post by: Nexus on August 11, 2014, 09:41:45 pm
You are designing a massive class hierarchy, but still don't explain where the additional value compared to the status quo lies. I have the feeling that you're over-abstracting functionality -- inheritance should be used with care in C++, we're not in Java. Please show an example of what your code can do that is not possible with the current API.

Keep in mind that SFML doesn't aim to implement a ready-to-use client/server framework, it only provides the basic building blocks to interact with different network protocols. Further abstractions can be written on top of it -- so the idea. In places where it's not possible to write such abstractions because of an API limitation, there is need for improvement. However, all the possible abstractions themselves do not need to be part of SFML.
Title: Re: Better controlled HTTP connections
Post by: jankowalski25 on August 12, 2014, 07:49:49 am
Quote
Please show an example of what your code can do that is not possible with the current API.
If you are sending raw bytes, current API can do everything, but current HTTP Client cannot:
Also if you want to implement something new, you must start from implementing communication. Creating new classes which will change data between plain text and formatted data is not enough to do it.
Title: Re: Better controlled HTTP connections
Post by: binary1248 on August 12, 2014, 09:12:33 am
Just to provide the connection: What you are suggesting for the HTTP side of things is the topic of the discussion here (https://github.com/SFML/SFML/issues/134) as well.
use case sensitive fields
http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
Quote
Field names are case-insensitive.
Field values are already treated in a case-sensitive manner by SFML, so I do not understand this point.

The rest of what you suggest, all those additional classes/interfaces, are for me superfluous as well. It can be done in your own code and SFML doesn't have to provide empty interfaces just so you can feel good by inheriting from them. They would serve no real purpose inside SFML or as part of its public API.

You don't need sf::Server to create a server.
You don't need sf::Http::Server to create a HTTP server.
You don't need sf::*****Server or sf::*****Client to create servers or clients, whether you create a server or client depends on the behaviour of your code, and not what you inherit from.

Have you made extensive use of the SFML network module before suggesting all of this? Because if you have, I'm sorry, but I don't see the reasoning behind most of what you said. These suggestions don't solve any real problems, and that is what is important when suggesting features. There are already many client and server applications that have been made with SFML even without these additions.
Title: Re: Better controlled HTTP connections
Post by: jankowalski25 on August 12, 2014, 12:20:58 pm
Quote
Just to provide the connection: What you are suggesting for the HTTP side of things is the topic of the discussion here as well.
Yes, I am trying to provide the connection. Thanks for link, I have not read this topic before.
Quote
Field names are case-insensitive.
OK, I agree. Thanks for link, I thought they are case sensitive.
Quote
It can be done in your own code and SFML doesn't have to provide empty interfaces
If SFML will support more than simple HTTP and FTP clients, I think some code will be the same for each client (for example it may be connecting). Then, a new classes doing this will be necessary to avoid repeating code.
Quote
Have you made extensive use of the SFML network module before suggesting all of this?
I was using sf::Http::Client as long as I could. Later, when I had some problems with fields, I started to use sf::TcpSocket. Then, I had problems with receiving data. Now I am trying to implement communication (one send == one receive, something like in packets, but text-based and suitable for all TCP connections).
Quote
There are already many client and server applications that have been made with SFML even without these additions.
I hope I will find something useful during reading their source.

//edit: Should I continue discussion about communication in the given topic (https://github.com/SFML/SFML/issues/134) or here?