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.")
|
Logger.info("Processing client request.")
|
||||||
|
|
||||||
client_socket
|
client_socket
|
||||||
|> read_request
|
|> read_request
|
||||||
|> create_response()
|
|> create_response()
|
||||||
|> create_response_header()
|
|> create_response_header()
|
||||||
|> write_response(client_socket)
|
|> write_response(client_socket)
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_request(client_socket) do
|
def read_request(client_socket) do
|
||||||
|
@ -23,38 +23,44 @@ defmodule RlRepo.ClientHandler do
|
||||||
|
|
||||||
def create_response(request) do
|
def create_response(request) do
|
||||||
# TODO: Split off the info I need from the request body and I guess pass it around also
|
# 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.")
|
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, " ")
|
b = String.split(get_line, " ")
|
||||||
[request_type | rest] = b
|
[request_type | rest] = b
|
||||||
[path | rest] = rest
|
Logger.info "REQ_TYPE #{request_type}"
|
||||||
Logger.info("#{request_type} #{path}")
|
[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 = String.split(path, "/", trim: true)
|
||||||
|
|
||||||
split_path_length = length(split_path)
|
split_path_length = length(split_path)
|
||||||
|
|
||||||
case split_path_length do
|
# TODO: Handle routing here.
|
||||||
1 ->
|
case split_path_length do
|
||||||
RlRepo.Router.parse_1_segment_path(rest)
|
1 ->
|
||||||
|> RlRepo.Router.route_1(request_type)
|
RlRepo.Router.parse_1_segment_path(split_path)
|
||||||
|
|> RlRepo.Router.route_1(request_type)
|
||||||
|
|
||||||
3 ->
|
3 ->
|
||||||
RlRepo.Router.parse_3_segment_path(rest)
|
RlRepo.Router.parse_3_segment_path(split_path)
|
||||||
|> RlRepo.Router.route_3(request_type)
|
|> RlRepo.Router.route_3(request_type)
|
||||||
|
|
||||||
4 ->
|
4 ->
|
||||||
RlRepo.Router.parse_4_segment_path(rest)
|
RlRepo.Router.parse_4_segment_path(split_path)
|
||||||
|> RlRepo.Router.route_4(request_type)
|
|> RlRepo.Router.route_4(request_type)
|
||||||
|
|
||||||
# Note: Error handling.
|
# Note: Error handling.
|
||||||
_ ->
|
_ ->
|
||||||
RlRepo.Router.status_404()
|
RlRepo.Router.status_404()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_return_code_string(return_code) do
|
def create_return_code_string(return_code) do
|
||||||
|
@ -67,14 +73,13 @@ defmodule RlRepo.ClientHandler do
|
||||||
def create_response_header(body) do
|
def create_response_header(body) do
|
||||||
{return_code, content_type, body} = body
|
{return_code, content_type, body} = body
|
||||||
html_ver = "1.1"
|
html_ver = "1.1"
|
||||||
|
"""
|
||||||
"""
|
HTTP/#{html_ver} #{create_return_code_string(return_code)}\r
|
||||||
HTTP/#{html_ver} #{create_return_code_string(return_code)}\r
|
Content-Type: #{content_type}\r
|
||||||
Content-Type: #{content_type}\r
|
Content-Length: #{byte_size(body)}\r
|
||||||
Content-Length: #{byte_size(body)}\r
|
\r
|
||||||
\r
|
#{body}
|
||||||
#{body}
|
"""
|
||||||
"""
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_response(response, client_socket) do
|
def write_response(response, client_socket) do
|
||||||
|
|
|
@ -3,7 +3,9 @@ defmodule RlRepo.Json do
|
||||||
|
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
"""
|
"""
|
||||||
def fmt_json(a) do
|
def fmt_as_json(a) do
|
||||||
"{\"pkg_names\": 10}"
|
"{\"pkg_name\": \"abc\"," <>
|
||||||
|
"\"" <>
|
||||||
|
"}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,8 +37,8 @@ defmodule RlRepo.Router do
|
||||||
|
|
||||||
def route_4(path, request_type) do
|
def route_4(path, request_type) do
|
||||||
Logger.info("#{request_type}")
|
Logger.info("#{request_type}")
|
||||||
{repo_name, sub_repo_name, pkg_name, action} = path
|
# {repo_name, sub_repo_name, pkg_name, action} = path
|
||||||
{200, "text/html", "<p>Hi</p>"}
|
{200, "application/json", RlRepo.Json.fmt_as_json()}
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_1_segment_path(path) do
|
def parse_1_segment_path(path) do
|
||||||
|
|
|
@ -16,7 +16,7 @@ defmodule RlRepo.Template do
|
||||||
end
|
end
|
||||||
|
|
||||||
def template_step(replacements, body, steps_left) do
|
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
|
[remains | _] = rest
|
||||||
[placeholder_name | after_placeholder] = String.split(remains, ")", parts: 2)
|
[placeholder_name | after_placeholder] = String.split(remains, ")", parts: 2)
|
||||||
[after_placeholder | _] = after_placeholder
|
[after_placeholder | _] = after_placeholder
|
||||||
|
|
Loading…
Reference in a new issue