MISC: Varios changes
This commit is contained in:
parent
70822b178e
commit
65d28b28d4
2
assets/repos.txt
Normal file
2
assets/repos.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
core
|
||||
core/kernels
|
|
@ -8,10 +8,10 @@ defmodule RlRepo.ClientHandler do
|
|||
Logger.info("Processing client request.")
|
||||
|
||||
client_socket
|
||||
|> read_request
|
||||
|> create_response()
|
||||
|> create_response_header()
|
||||
|> write_response(client_socket)
|
||||
|> read_request
|
||||
|> create_response()
|
||||
|> create_response_header()
|
||||
|> write_response(client_socket)
|
||||
end
|
||||
|
||||
def read_request(client_socket) do
|
||||
|
@ -23,38 +23,44 @@ 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)
|
||||
|
||||
case split_path_length do
|
||||
1 ->
|
||||
RlRepo.Router.parse_1_segment_path(rest)
|
||||
|> RlRepo.Router.route_1(request_type)
|
||||
# TODO: Handle routing here.
|
||||
case split_path_length do
|
||||
1 ->
|
||||
RlRepo.Router.parse_1_segment_path(split_path)
|
||||
|> RlRepo.Router.route_1(request_type)
|
||||
|
||||
3 ->
|
||||
RlRepo.Router.parse_3_segment_path(rest)
|
||||
|> RlRepo.Router.route_3(request_type)
|
||||
3 ->
|
||||
RlRepo.Router.parse_3_segment_path(split_path)
|
||||
|> RlRepo.Router.route_3(request_type)
|
||||
|
||||
4 ->
|
||||
RlRepo.Router.parse_4_segment_path(rest)
|
||||
|> RlRepo.Router.route_4(request_type)
|
||||
4 ->
|
||||
RlRepo.Router.parse_4_segment_path(split_path)
|
||||
|> RlRepo.Router.route_4(request_type)
|
||||
|
||||
# Note: Error handling.
|
||||
_ ->
|
||||
RlRepo.Router.status_404()
|
||||
end
|
||||
# Note: Error handling.
|
||||
_ ->
|
||||
RlRepo.Router.status_404()
|
||||
end
|
||||
end
|
||||
|
||||
def create_return_code_string(return_code) do
|
||||
|
@ -67,14 +73,13 @@ 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
|
||||
Content-Length: #{byte_size(body)}\r
|
||||
\r
|
||||
#{body}
|
||||
"""
|
||||
"""
|
||||
HTTP/#{html_ver} #{create_return_code_string(return_code)}\r
|
||||
Content-Type: #{content_type}\r
|
||||
Content-Length: #{byte_size(body)}\r
|
||||
\r
|
||||
#{body}
|
||||
"""
|
||||
end
|
||||
|
||||
def write_response(response, client_socket) do
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue