Request class: Add methods to send data in chunks
The Request class in the network-refactorisation1 branch doesn't have methods to send request data in chunks.
Methods to do this shall be added, working in "reverse" compared to the methods that allow reading response data in chunks.
Implementation can start as soon as #9 is finished.
This is already part of #9
No it isn't. The send method can only send a header, but no body. HTTP GET works, but HTTP POST or PUT will not work with the current code.
- Add a DataSource interface that defines methods for a data source that can deliver data to a Request object.
- Add a DummyDataSource implementation of the RequestDataSource that can be used to send raw data over the network when used with the base Request class or the request class of another protocol that allows raw data.
- Add a HTTPFormDataSource implementation that can be configured to output provided data in several formats used by HTTP forms (multipart/form-data, application/x-www-form-urlencoded, ...). The HTTPFormDataSource class shall allow selecting the format to be used.
- Add the method Request::setDataSource that accepts a DataSource instance.
Add the method Request::sendData which reads a chunk of data from the DataSource instance. Add a new variant of NetworkHandler::request that does not have the data parameter and instead uses Request::sendData to get the data to be sent.
- Add a new parameter to NetworkHandler::request that allows passing a DataSource instance to it.
- Rename the data parameter in NetworkHandler::request to request_header.
- Extend the test for the Request class.
- ... and the HTTPRequest class.
- ... and the tests for the NetworkHander classes (in regard to the new request method)
- Write a test for the DummyDataSource
- ... and the HTTPFormDataSource class.
TODO changed: RequestDataSource is now a base class for raw request data instead of just defining the interface.
RequestDataSource should not be a base class for raw data sources since the implementation of the data source defines where the data will come from. That can be a HTTP form, a file, a data stream (microphone, webcam or another device) or something else.
Another edit: One more method for the request class and one more variant for NetworkHandler implementations.
Variant of NetworkHandler::request that accepts a Request instance instead of data is dropped, since the Request instance is responsible for producing the data that is then sent by the NetworkHandler.
Furthermore Request::sendData is also not necessary, since the Request instance itself knows best when to send a body.
What is necessary is that NetworkHandler::request can get a DataSource instance as additional parameter. After it has opened the connection and send the initial data (data parameter), it then uses the DataSource instance to send more data. The DataSource instance is responsible for providing data in the correct format so it should not be a problem when its data is "passed through" to the NetworkHandler directly.
Deleting a branch is permanent. It CANNOT be undone. Continue?