Tectu / malloy

A cross-platform C++20 library providing embeddable server & client components for HTTP and WebSocket.
BSD 3-Clause "New" or "Revised" License
68 stars 8 forks source link

feat: Custom request types, websocket rewrite, client custom responses #28

Closed 0x00002a closed 3 years ago

0x00002a commented 3 years ago

So this one is a bit of a mess. The websocket rewrite should probably have been its own PR but I didn't realise that until I was almost done with it. Anyway, deep breath:


Changes

Core

Client

Server

Websockets

The websocket API has been redesigned. The server and client parts have been merged into a single class which uses a stream type that does the handling of tls vs plain (although I don't think websocket tls is implemented yet?). The interface is based around providing a connection object which represents the websocket session and can be used to manage said session. The API is entirely async (apart from stop). It uses callbacks although really I would like to use coroutines here (but I lack experience with them).

Server

On the server side, the new interface passes the connection object as a shared_ptr directly to the handler, along with the request (as a string_body) that kicked it off, it is then up to the handler whether to call accept on the connection object.

Client

The client side is similar except its callback takes in error_code instead of the request. If the error code is truthy then the connection object will be nullptr, else its safe to use. The handshake is done before the handler is invoked so the handler should call either read or send.


I've added examples for the new filters and fixed the examples for the websockets so check those out for, well, examples. I will sort out the merge conflicts if/when this is ready for merging, as I think its going to require quite a bit of manual sorting out. I don't think its ready for merge currently, I want feedback on it and it could do with some more testing. Also needs some documentation, I haven't updated the doxygen comments or added new ones for the most part.

Closes: #17

0x00002a commented 3 years ago

Just rebasing this now, so don't pull it :p

0x00002a commented 3 years ago

Alright nvm, trying to rebase this is a nightmare. I just merged the upstream changes, I guess its ok anyway since it will be squashed on merge?

Tectu commented 3 years ago

Wow. I eeeh... will need some time to process this PR :-D

Tectu commented 3 years ago

I started reviewing this. So far, most seems to be related to coding style, can you modify this PR accordingly?

coding style fixes (I'll update coding_style.md accordingly):

Tectu commented 3 years ago

It would also be great if you could add some Doxygen to document the new classes/interfaces. Doesn't need to be complete at the moment - I'll put some effort into documentation once v0.1 is ready to be released. But at least class/interface documentation would be great :)

0x00002a commented 3 years ago

I've added some doxygen comments. Let me know if it needs more, or there are any inaccuracies (I've checked the HTML output but checking your own work and all that :p)

Tectu commented 3 years ago

Did you by any chance miss my other post on this PR regarding the coding style changes? :p

0x00002a commented 3 years ago

Ah, yes I did 🤦. I would prefer to do it via clang-format, but that will affect everything not just changes from this PR. I could localise it to only the files affected by the PR though (although I think thats most of them). Is that acceptable?

Tectu commented 3 years ago

Works for me. Alternatively we can also ignore the coding style for this PR (as an exception - because it's you 😛), I will finish the review process ignoring coding style and after that I fix/improve the .clang-format and we add this to the workflow.

What do you think?

0x00002a commented 3 years ago

This PR is already quite messy, it would be cleaner to merge then run clang-format over the whole codebase imo, since not all of that follows the current standard (at least mine doesn't :p). Once the codebase is formatted according to the .clang-format file then we stop anything being merged that doesn't follow it, that way we keep the main clean and ensure formatting PRs doesn't cause a pile of conflicts.

Tectu commented 3 years ago

Agreed.

0x00002a commented 3 years ago

oneshot has been renamed to accept_and_send, I've removed filter_helper since its unused