Everywhere: Make session->send() callable

This commit is contained in:
Alec Murphy 2025-02-20 08:24:04 -05:00
parent 40b3fceab1
commit c6f74cfa84
26 changed files with 87 additions and 48 deletions

View file

@ -64,6 +64,7 @@ class SlonHttpSession {
U8* actor_for_key_id;
U8* (*header)(U8* key, U8* value = NULL);
U0 (*send)(U64 payload, I64 size = NULL);
I64 (*status)(I64 code = NULL);
};
@ -209,7 +210,7 @@ U0 @slon_http_send_file(SlonHttpSession* session, U8* path)
return;
I64 size = 0;
U8* data = FileRead(path, &size);
@slon_http_send(session, data, size);
session->send(data, size);
Free(data);
}
@ -278,3 +279,20 @@ U8* @slon_session_header_wrapper_function(U8* key, U8* value = NULL)
@slon_http_set_header(session, key, value);
return value;
}
U0 @slon_session_send_wrapper_function(U64 payload, I64 size = NULL)
{
SlonHttpSession* session = SLON_WRAPPER_MAGIC_NUMBER;
if (!payload) {
return;
}
if (*payload(U32*) == JSON_SIG) {
@slon_http_send_json(session, payload);
return;
}
if (!size) {
@slon_http_send_string(session, payload);
} else {
@slon_http_send(session, payload, size);
}
}

View file

@ -5,5 +5,5 @@ U0 @slon_host_meta(SlonHttpSession* session)
StrPrint(scratch_buffer, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><XRD xmlns=\"http://docs.oasis-open.org/ns/xri/xrd-1.0\"><Link rel=\"lrdd\" template=\"https://%s/.well-known/webfinger?resource={uri}\"/></XRD>", db->o("instance")->@("uri"));
@slon_http_set_content_type(session, "application/xrd+xml; charset=utf-8");
@slon_http_send_string(session, scratch_buffer);
session->send(scratch_buffer);
}

View file

@ -8,7 +8,7 @@ U0 @slon_oauth_well_known(SlonHttpSession* session)
StrPrint(scratch_buffer, "{\"issuer\":\"https://%s\",\"authorization_endpoint\":\"https://%s/oauth/authorize\",\"response_types_supported\":[\"code\"],\"app_registration_endpoint\":\"https://%s/api/v1/apps\"}",
db->o("instance")->@("uri"), db->o("instance")->@("uri"), db->o("instance")->@("uri"));
@slon_http_set_content_type(session, "application/json; charset=utf-8");
@slon_http_send_string(session, scratch_buffer);
session->send(scratch_buffer);
}
U0 @slon_oauth_fetch_token(U8* client_id)
@ -132,7 +132,7 @@ U0 @slon_oauth_verify_access_get(SlonHttpSession* session)
StrPrint(scratch_buffer, "%s?code=%s", redirect_uri, authorization_code);
JsonObject* redirect_uri_object = Json.CreateObject();
redirect_uri_object->set("redirect_uri", scratch_buffer, JSON_STRING);
@slon_http_send_json(session, redirect_uri_object);
session->send(redirect_uri_object);
Json.Delete(redirect_uri_object);
@slon_free(session, authorization_code);
@ -178,7 +178,7 @@ U0 @slon_oauth_token_post(SlonHttpSession* session)
if (!StrCmp(client_id, code_object->@("client_id")) && !StrCmp(client_secret, code_object->@("client_secret"))) {
JsonObject* token = db->o("oauth")->o("tokens")->@(access_token);
if (token) {
@slon_http_send_json(session, token);
session->send(token);
} else {
// If the token doesn't exist, Page Expired?
session->status(419);

View file

@ -26,7 +26,7 @@ U0 @slon_web_user_get(SlonHttpSession* session)
String.Append(html_data, user_file_data);
String.Append(html_data, ");</script>");
@slon_http_set_content_type(session, "text/html");
@slon_http_send(session, html_data, StrLen(html_data));
session->send(html_data, StrLen(html_data));
Free(html_file_data);
Free(user_file_data);

View file

@ -28,7 +28,7 @@ U0 @slon_webfinger(SlonHttpSession* session)
links->append(Json.CreateItem(link_object, JSON_OBJECT));
webfinger_object->set("links", links, JSON_ARRAY);
@slon_http_send_json(session, webfinger_object);
session->send(webfinger_object);
Json.Delete(webfinger_object);
} else {
session->status(404);