Everywhere: Make session->content_type() callable
This commit is contained in:
parent
614e68194b
commit
ff5a07dc04
10 changed files with 43 additions and 26 deletions
|
@ -73,6 +73,7 @@ class SlonHttpSession {
|
|||
I64 (*path_count)();
|
||||
I64 (*status)(I64 code = NULL);
|
||||
I64 (*verb)(Bool return_str = FALSE);
|
||||
U0 (*content_type)(U8* value);
|
||||
};
|
||||
|
||||
U64 @slon_calloc(SlonHttpSession* session, I64 size)
|
||||
|
@ -173,7 +174,7 @@ U0 @slon_http_send_ap_json(SlonHttpSession* session, U64 json)
|
|||
{
|
||||
// a stringified copy of "json" is created, a strnew is sent, we clean up stringified copy, sender cleans up "json"
|
||||
session->status(200);
|
||||
@slon_http_set_content_type(session, "application/activity+json; charset=utf-8");
|
||||
session->content_type("application/activity+json; charset=utf-8");
|
||||
U8* json_string = Json.Stringify(json);
|
||||
session->response->data = @slon_strnew(session, json_string);
|
||||
session->response->size = StrLen(session->response->data);
|
||||
|
@ -184,7 +185,7 @@ U0 @slon_http_send_json(SlonHttpSession* session, U64 json)
|
|||
{
|
||||
// a stringified copy of "json" is created, a strnew is sent, we clean up stringified copy, sender cleans up "json"
|
||||
session->status(200);
|
||||
@slon_http_set_content_type(session, "application/json; charset=utf-8");
|
||||
session->content_type("application/json; charset=utf-8");
|
||||
U8* json_string = Json.Stringify(json);
|
||||
session->response->data = @slon_strnew(session, json_string);
|
||||
session->response->size = StrLen(session->response->data);
|
||||
|
@ -223,13 +224,13 @@ U0 @slon_http_send_file(SlonHttpSession* session, U8* path)
|
|||
|
||||
U0 @slon_http_send_html_file(SlonHttpSession* session, U8* path)
|
||||
{
|
||||
@slon_http_set_content_type(session, "text/html");
|
||||
session->content_type("text/html");
|
||||
@slon_http_send_file(session, path);
|
||||
}
|
||||
|
||||
U0 @slon_http_send_json_file(SlonHttpSession* session, U8* path, U8* content_type = "application/json; charset=utf-8")
|
||||
{
|
||||
@slon_http_set_content_type(session, content_type);
|
||||
session->content_type(content_type);
|
||||
@slon_http_send_file(session, path);
|
||||
}
|
||||
|
||||
|
@ -345,3 +346,9 @@ I64 @slon_session_path_count_wrapper_function()
|
|||
SlonHttpSession* session = SLON_WRAPPER_MAGIC_NUMBER;
|
||||
return session->request->path_segments_count;
|
||||
}
|
||||
|
||||
U0 @slon_session_content_type_wrapper_function(U8* value)
|
||||
{
|
||||
SlonHttpSession* session = SLON_WRAPPER_MAGIC_NUMBER;
|
||||
session->header("content-type", value);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,6 @@ U0 @slon_host_meta(SlonHttpSession* session)
|
|||
no_warn request_json;
|
||||
|
||||
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");
|
||||
session->content_type("application/xrd+xml; charset=utf-8");
|
||||
session->send(scratch_buffer);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ U0 @slon_nodeinfo(SlonHttpSession* session)
|
|||
no_warn request_json;
|
||||
|
||||
StrPrint(scratch_buffer, "{\"links\":[{\"rel\":\"http://nodeinfo.diaspora.software/ns/schema/2.0\",\"href\":\"https://%s/nodeinfo/2.0\"}]}", db->o("instance")->@("uri"));
|
||||
@slon_http_set_content_type(session, "application/json; charset=utf-8");
|
||||
session->content_type("application/json; charset=utf-8");
|
||||
session->send(scratch_buffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,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");
|
||||
session->content_type("application/json; charset=utf-8");
|
||||
session->send(scratch_buffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ U0 @slon_web_user_get(SlonHttpSession* session)
|
|||
String.Append(html_data, "<script>getStatuses(");
|
||||
String.Append(html_data, user_file_data);
|
||||
String.Append(html_data, ");</script>");
|
||||
@slon_http_set_content_type(session, "text/html");
|
||||
session->content_type("text/html");
|
||||
session->send(html_data, StrLen(html_data));
|
||||
|
||||
Free(html_file_data);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue