FMT: mix fmt
This commit is contained in:
parent
dcc753a106
commit
70822b178e
|
@ -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
|
||||||
|
@ -24,47 +24,37 @@ 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 #{request}")
|
||||||
|
|
||||||
Logger.info("Building response body.")
|
Logger.info("Building response body.")
|
||||||
|
|
||||||
|
[get_line | rest] = String.split(request, "\n\r")
|
||||||
# TODO: Handle routing here.
|
|
||||||
a = String.split(request, "\n\r")
|
|
||||||
# Logger.info a
|
|
||||||
[get_line | rest] = a
|
|
||||||
|
|
||||||
b = String.split(get_line, " ")
|
b = String.split(get_line, " ")
|
||||||
[request_type | rest] = b
|
[request_type | rest] = b
|
||||||
[path | rest] = rest
|
[path | rest] = rest
|
||||||
Logger.info("#{request_type} #{path}")
|
Logger.info("#{request_type} #{path}")
|
||||||
|
|
||||||
# Parse path
|
# Parse path ignoring leading and trailing slash
|
||||||
split_path = String.split(path, "/", trim: true)
|
split_path = String.split(path, "/", trim: true)
|
||||||
# Ignore the first slash.
|
|
||||||
# [_ | rest ] = split_path
|
|
||||||
|
|
||||||
split_path_length = length(split_path)
|
split_path_length = length(split_path)
|
||||||
|
|
||||||
ret =
|
case split_path_length do
|
||||||
case split_path_length do
|
1 ->
|
||||||
1 ->
|
RlRepo.Router.parse_1_segment_path(rest)
|
||||||
RlRepo.Router.parse_1_segment_path(rest)
|
|> RlRepo.Router.route_1(request_type)
|
||||||
|> RlRepo.Router.route_1(request_type)
|
|
||||||
|
|
||||||
3 ->
|
3 ->
|
||||||
RlRepo.Router.parse_3_segment_path(rest)
|
RlRepo.Router.parse_3_segment_path(rest)
|
||||||
|> 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(rest)
|
||||||
|> 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
|
||||||
|
|
||||||
ret
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_return_code_string(return_code) do
|
def create_return_code_string(return_code) do
|
||||||
|
|
|
@ -10,12 +10,8 @@ defmodule RlRepo.Template do
|
||||||
|
|
||||||
def inner_template(body, replacements) do
|
def inner_template(body, replacements) do
|
||||||
# TODO: Check if there is any actual placeholders
|
# TODO: Check if there is any actual placeholders
|
||||||
v = String.contains?(body, "~(")
|
# v = String.contains?(body, "~(")
|
||||||
# Logger.info(v)
|
|
||||||
|
|
||||||
len = body |> String.split("~(") |> length()
|
len = body |> String.split("~(") |> length()
|
||||||
# Logger.info(body)
|
|
||||||
|
|
||||||
template_step(replacements, body, len)
|
template_step(replacements, body, len)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,10 @@ defmodule RlRepoTest do
|
||||||
assert RlRepo.Template.inner_template(body, placeholders) == "DONE"
|
assert RlRepo.Template.inner_template(body, placeholders) == "DONE"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test "multi template replace" do
|
test "multi template replace" do
|
||||||
body = "~(replace)abc~(replace)"
|
body = "~(replace)abc~(replace)"
|
||||||
placeholders = %{"replace" => "DONE"}
|
placeholders = %{"replace" => "DONE"}
|
||||||
|
|
||||||
assert RlRepo.Template.inner_template(body, placeholders) == "DONEabcDONE"
|
assert RlRepo.Template.inner_template(body, placeholders) == "DONEabcDONE"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue