Skip to content

Commit

Permalink
Add header-param handling in output formats
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Aug 18, 2023
1 parent c9cedbc commit d6af521
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/models/noir.cr
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class NoirRunner
def bake_endpoint(url : String, params : Array(Param))
final_url = url
final_body = ""
final_headers = [] of String
is_json = false
first_query = true
first_form = true
Expand All @@ -132,6 +133,10 @@ class NoirRunner
end
end

if param.param_type == "header"
final_headers << "#{param.name}: #{param.value}"
end

if param.param_type == "json"
is_json = true
end
Expand All @@ -153,6 +158,7 @@ class NoirRunner
{
url: final_url,
body: final_body,
header: final_headers,
body_type: is_json ? "json" : "form",
}
end
Expand Down Expand Up @@ -186,6 +192,9 @@ class NoirRunner
if baked[:body_type] == "json"
cmd += " \"Content-Type:application/json\""
end
baked[:header].each do |header|
cmd += " \"#{header}\""
end
end

puts cmd
Expand All @@ -200,6 +209,10 @@ class NoirRunner
if baked[:body_type] == "json"
cmd += " -H \"Content-Type:application/json\""
end

Check notice on line 212 in src/models/noir.cr

View workflow job for this annotation

GitHub Actions / Ameba

Layout/TrailingWhitespace

Trailing whitespace detected
baked[:header].each do |header|
cmd += " -H \"#{header}\""
end
end

puts cmd
Expand All @@ -210,16 +223,18 @@ class NoirRunner

r_method = endpoint.method.colorize(:light_blue).toggle(@is_color)
r_url = baked[:url].colorize(:light_yellow).toggle(@is_color)
r_headers = baked[:header].join(" ").colorize(:light_green).toggle(@is_color)

r_ws = ""
if endpoint.protocol == "ws"
r_ws = "[WEBSOCKET]".colorize(:light_red).toggle(@is_color)
end

if baked[:body] != ""
r_body = baked[:body].colorize(:cyan).toggle(@is_color)
puts "#{r_method} #{r_url} #{r_body} #{r_ws}"
puts "#{r_method} #{r_url} #{r_body} #{r_headers} #{r_ws}"
else
puts "#{r_method} #{r_url} #{r_ws}"
puts "#{r_method} #{r_url} #{r_headers} #{r_ws}"
end
end
end
Expand Down

0 comments on commit d6af521

Please sign in to comment.