MISC: Varios changes

This commit is contained in:
Able 2025-02-21 09:22:09 -06:00
parent 70822b178e
commit 65d28b28d4
5 changed files with 46 additions and 37 deletions

2
assets/repos.txt Normal file
View file

@ -0,0 +1,2 @@
core
core/kernels

View file

@ -23,32 +23,38 @@ defmodule RlRepo.ClientHandler do
def create_response(request) do
# TODO: Split off the info I need from the request body and I guess pass it around also
Logger.info("REQUEST BODY #{request}")
Logger.info("REQUEST BODY\n#{request}")
Logger.info("Building response body.")
[get_line | rest] = String.split(request, "\n\r")
a = String.split(request, "\n\r")
[get_line | _rest] = a
Logger.info "get-line #{get_line}"
b = String.split(get_line, " ")
[request_type | rest] = b
[path | rest] = rest
Logger.info("#{request_type} #{path}")
Logger.info "REQ_TYPE #{request_type}"
[path | _rest] = rest
Logger.info("PATH #{path}")
# Parse path ignoring leading and trailing slash
# Parse path
split_path = String.split(path, "/", trim: true)
split_path_length = length(split_path)
# TODO: Handle routing here.
case split_path_length do
1 ->
RlRepo.Router.parse_1_segment_path(rest)
RlRepo.Router.parse_1_segment_path(split_path)
|> RlRepo.Router.route_1(request_type)
3 ->
RlRepo.Router.parse_3_segment_path(rest)
RlRepo.Router.parse_3_segment_path(split_path)
|> RlRepo.Router.route_3(request_type)
4 ->
RlRepo.Router.parse_4_segment_path(rest)
RlRepo.Router.parse_4_segment_path(split_path)
|> RlRepo.Router.route_4(request_type)
# Note: Error handling.
@ -67,7 +73,6 @@ defmodule RlRepo.ClientHandler do
def create_response_header(body) do
{return_code, content_type, body} = body
html_ver = "1.1"
"""
HTTP/#{html_ver} #{create_return_code_string(return_code)}\r
Content-Type: #{content_type}\r

View file

@ -3,7 +3,9 @@ defmodule RlRepo.Json do
@moduledoc """
"""
def fmt_json(a) do
"{\"pkg_names\": 10}"
def fmt_as_json(a) do
"{\"pkg_name\": \"abc\"," <>
"\"" <>
"}"
end
end

View file

@ -37,8 +37,8 @@ defmodule RlRepo.Router do
def route_4(path, request_type) do
Logger.info("#{request_type}")
{repo_name, sub_repo_name, pkg_name, action} = path
{200, "text/html", "<p>Hi</p>"}
# {repo_name, sub_repo_name, pkg_name, action} = path
{200, "application/json", RlRepo.Json.fmt_as_json()}
end
def parse_1_segment_path(path) do

View file

@ -16,7 +16,7 @@ defmodule RlRepo.Template do
end
def template_step(replacements, body, steps_left) do
[before_placeholder | rest] = split_path = String.split(body, "~(", parts: 2)
[before_placeholder | rest] = String.split(body, "~(", parts: 2)
[remains | _] = rest
[placeholder_name | after_placeholder] = String.split(remains, ")", parts: 2)
[after_placeholder | _] = after_placeholder