Skip to content

Commit

Permalink
Merge pull request huginn#3456 from huginn/add_line_break_is_lf_optio…
Browse files Browse the repository at this point in the history
…n_to_liquid_output_agent

Add a new option "line_break_is_lf" to LiquidOutputAgent
  • Loading branch information
knu authored Oct 26, 2024
2 parents e669485 + 6a9c845 commit 05bb517
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/models/agents/liquid_output_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class LiquidOutputAgent < Agent
* `secret` - A token that the requestor must provide for light-weight authentication.
* `expected_receive_period_in_days` - How often you expect data to be received by this Agent from other Agents.
* `content` - The content to display when someone requests this page.
* `line_break_is_lf` - Use LF as line breaks instead of CRLF.
* `mime_type` - The mime type to use when someone requests this page.
* `response_headers` - An object with any custom response headers. (example: `{"Access-Control-Allow-Origin": "*"}`)
* `mode` - The behavior that determines what data is passed to the Liquid template.
Expand Down Expand Up @@ -98,6 +99,7 @@ def default_options
form_configurable :secret
form_configurable :expected_receive_period_in_days
form_configurable :content, type: :text
form_configurable :line_break_is_lf, type: :boolean
form_configurable :mime_type
form_configurable :mode, type: :array, values: ['Last event in', 'Merge events', 'Last X events']
form_configurable :event_limit
Expand Down Expand Up @@ -195,7 +197,9 @@ def mime_type
end

def liquified_content
interpolated(data_for_liquid_template)['content']
content = interpolated(data_for_liquid_template)['content']
content.gsub!(/\r(?=\n)/, '') if boolify(options['line_break_is_lf'])
content
end

def data_for_liquid_template
Expand Down
17 changes: 16 additions & 1 deletion spec/models/agents/liquid_output_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
end
end

describe "#receive_web_request?" do
describe "#receive_web_request" do
let(:secret) { SecureRandom.uuid }

let(:headers) { {} }
Expand Down Expand Up @@ -233,6 +233,21 @@
agents(:bob_website_agent).events.destroy_all
end

it "should output LF-terminated lines if line_break_is_lf is true" do
agent.options["content"] = "hello\r\nworld\r\n"

result = agent.receive_web_request request
expect(result[0]).to eq "hello\r\nworld\r\n"

agent.options["line_break_is_lf"] = "true"
result = agent.receive_web_request request
expect(result[0]).to eq "hello\nworld\n"

agent.options["line_break_is_lf"] = "false"
result = agent.receive_web_request request
expect(result[0]).to eq "hello\r\nworld\r\n"
end

it 'should respond with custom response header if configured with `response_headers` option' do
agent.options['response_headers'] = { "X-My-Custom-Header" => 'hello' }
result = agent.receive_web_request request
Expand Down

0 comments on commit 05bb517

Please sign in to comment.