1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 18:57:34 +00:00

ProtocolServer+LibProtocol: Introduce a server for handling downloads

This patch adds ProtocolServer, a server that handles network requests
on behalf of its clients. The first protocol implemented is HTTP.

The idea here is to use a plug-in architecture where any number of
protocols can be added and implemented without having to mess around
with each client program that wants to use the protocol.

A simple client API is provided through LibProtocol::Client. :^)
This commit is contained in:
Andreas Kling 2019-11-23 21:45:33 +01:00
parent 61f611bf3c
commit fd4349a9f2
21 changed files with 475 additions and 0 deletions

View file

@ -0,0 +1,35 @@
#pragma once
#include <AK/RefCounted.h>
#include <AK/URL.h>
#include <AK/WeakPtr.h>
class PSClientConnection;
class Download : public RefCounted<Download> {
public:
virtual ~Download();
static Download* find_by_id(i32);
i32 id() const { return m_id; }
URL url() const { return m_url; }
size_t total_size() const { return m_total_size; }
size_t downloaded_size() const { return m_downloaded_size; }
void stop();
protected:
explicit Download(PSClientConnection&);
void did_finish(bool success);
void did_progress(size_t total_size, size_t downloaded_size);
private:
i32 m_id;
URL m_url;
size_t m_total_size { 0 };
size_t m_downloaded_size { 0 };
WeakPtr<PSClientConnection> m_client;
};