-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Custom request types, websocket rewrite, client custom responses #28
Conversation
…o feat-custom-requests
…o feat-custom-requests
Just rebasing this now, so don't pull it :p |
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? |
Wow. |
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
|
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 |
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) |
Did you by any chance miss my other post on this PR regarding the coding style changes? :p |
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? |
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 What do you think? |
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 |
Agreed. |
spdlog::error(ec.message()); | ||
return EXIT_FAILURE; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary empty line(s)
.gitignore
Outdated
# End of https://www.toptal.com/developers/gitignore/api/clion+all | ||
/.vs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be part of this PR as it seems unrelated to the subject of this PR.
using ws_connection = std::shared_ptr<malloy::websocket::connection<isClient>>; | ||
|
||
|
||
template<bool isClient> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use some short comment describing it's functionality.
}); | ||
} | ||
|
||
template<bool isClient> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use some short comment describing it's functionality.
conn->accept(req, [msg, conn] { conn->send(malloy::buffer(*msg), [msg](auto, auto) {}); }); | ||
} | ||
|
||
template<bool isClient> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use some short comment describing it's functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should really be named confusing myself :p, it also accepts but still needs a renameoneshot_send
lib/malloy/http/filters/file.hpp
Outdated
|
||
namespace malloy::http::filters { | ||
|
||
template<bool isRequest> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing class/struct documentation.
lib/malloy/http/type_traits.hpp
Outdated
|
||
namespace malloy::http::concepts { | ||
|
||
template<typename B> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing indentation.
|
||
struct endpoint_http_files : | ||
endpoint_http | ||
class endpoint_http_files : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing class documentation.
test/test_suites/components/uri.cpp
Outdated
@@ -2,6 +2,8 @@ | |||
|
|||
#include <malloy/http/uri.hpp> | |||
|
|||
#include <iostream> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really necessary? This include was added to test.hpp
:
Line 12 in a20816b
#include <iostream> |
|
||
stop_token.wait(); | ||
CHECK(server_recieved); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of empty lines.
|
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
malloy
namespace.error.hpp
now holds a forwardedmalloy::error_code
Client
auto body_for(const header_type&) -> std::variant<...>
void setup_body(const header_type&, T&)
where T is one of the types in the variant returned bybody_for
(its a visitor)Filter::body_for
Filter
param to provide a custom filter for the responseresponse<T>...
whereT
is the bodies returned bysetup_body
for the filter (this means that with the default handler, it will always beresponse<string_body>
)Server
setup_body(const request_type::header_type&, request_type::body_type::value_type&)
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 astring_body
) that kicked it off, it is then up to the handler whether to callaccept
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 eitherread
orsend
.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