Fix request args
Logic _should_ be correct now, need to fix tests FossilOrigin-Name: 5b9e408a73daa2cfa51a4402662c59cd5440ec3c284603043a2fc11cace89bca
This commit is contained in:
parent
dee19b7f24
commit
e3a211a6e7
5 changed files with 17 additions and 21 deletions
|
@ -28,6 +28,7 @@ target_compile_definitions(wormhole PRIVATE
|
|||
# Modules
|
||||
# Features that can be excluded can be added here
|
||||
add_module(WEBFINGER)
|
||||
add_module(ACTIVITYPUB)
|
||||
add_subdirectory(src/protocol)
|
||||
|
||||
# General includes
|
||||
|
|
|
@ -60,18 +60,16 @@ std::optional<RequestArgs_t> Request::match_get_args(Request& other)
|
|||
|
||||
// Peek next character to know where to stop (often a '/')
|
||||
curr += n - n_last;
|
||||
size_t next_char_dist = other_url.find(url[n], curr);
|
||||
size_t next_char_dist = other_url.find(url[n+1], curr);
|
||||
if (next_char_dist != std::string::npos)
|
||||
{
|
||||
// Push string
|
||||
args.push_back(other_url.substr(n, next_char_dist));
|
||||
// Push string at index
|
||||
args.push_back(other_url.substr(n, next_char_dist - n));
|
||||
// Seek n past next_char
|
||||
curr += next_char_dist;
|
||||
}
|
||||
else {
|
||||
// Argument is at end of string
|
||||
// Technically we could use std::string::npos (-1 on most systems), but
|
||||
// this is standard
|
||||
args.push_back(other_url.substr(n));
|
||||
}
|
||||
|
||||
|
|
|
@ -33,12 +33,18 @@
|
|||
#ifdef MODULE_WEBFINGER
|
||||
#include "protocol/webfinger/webfinger.h"
|
||||
#endif
|
||||
#ifdef MODULE_ACTIVITYPUB
|
||||
#include "protocol/activitypub/activitypub.h"
|
||||
#endif
|
||||
|
||||
void init_routes(const std::unique_ptr<HTTP::Server>& server)
|
||||
{
|
||||
#ifdef MODULE_WEBFINGER
|
||||
Protocol::Webfinger::init_webfinger(server.get());
|
||||
#endif
|
||||
#ifdef MODULE_ACTIVITYPUB
|
||||
Protocol::ActivityPub::init_activitypub(server.get());
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
if (MODULE_WEBFINGER)
|
||||
add_subdirectory(webfinger)
|
||||
endif()
|
||||
|
||||
if (MODULE_ACTIVITYPUB)
|
||||
add_subdirectory(activitypub)
|
||||
endif()
|
||||
|
|
|
@ -53,7 +53,6 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
// TODO a lot
|
||||
HTTP::Response Route::webfinger(std::any& args, const HTTP::Request& req, const HTTP::RequestArgs_t& arg)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
|
@ -86,25 +85,13 @@ HTTP::Response Route::webfinger(std::any& args, const HTTP::Request& req, const
|
|||
|
||||
// Standard "acct:" prefix check
|
||||
if (!resource.compare(0, acct_prefix.size(), acct_prefix))
|
||||
{
|
||||
// Get data after acct:
|
||||
acct_str = resource.substr(acct_prefix.size());
|
||||
}
|
||||
// Host prefix check
|
||||
else if (!resource.compare(0, local_host_prefix.size(), local_host_prefix))
|
||||
{
|
||||
// Get data after acct:
|
||||
else if (!resource.compare(0, local_host_prefix.size(), local_host_prefix)) // Instance host
|
||||
acct_str = resource.substr(local_host_prefix.size());
|
||||
}
|
||||
// At prefix check
|
||||
else if (!resource.compare(0, at_prefix.size(), at_prefix))
|
||||
{
|
||||
// Get data after acct:
|
||||
else if (!resource.compare(0, at_prefix.size(), at_prefix)) // At prefix
|
||||
acct_str = resource.substr(at_prefix.size());
|
||||
}
|
||||
else {
|
||||
else
|
||||
return HTTP::Error::make_json_error_response("Invalid prefix", HTTP::Code::METHOD_NOT_ALLOWED);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue