Skip to content

Commit

Permalink
Removed writing to stream (#3)
Browse files Browse the repository at this point in the history
* Removed writing to stream

Fixes #2 I hope, removed the writing of a comment. It was a small security issue aswell

* Easy on the queries

We dont want to hit the db every request
  • Loading branch information
davidakachaos committed Nov 2, 2016
1 parent f41ee37 commit 41e852a
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions lib/workless/middleware/workless_checker.rb
Expand Up @@ -7,14 +7,9 @@ def call(env)
status, headers, response = @app.call(env)
return [status, headers, response] if file?(headers) || empty?(response)

Delayed::Job.scaler.up if Delayed::Job.scaler.jobs.size > 0
response_body = nil
if status == 200 && !response.body.frozen? && html_request?(headers, response)
response_body = response.body << "\n<!-- workless jobs: #{Delayed::Job.scaler.jobs.size} -->"
headers['Content-Length'] = response_body.bytesize.to_s
end
Delayed::Job.scaler.up unless Delayed::Job.scaler.jobs.empty?

[status, headers, response_body ? [response_body] : response]
[status, headers, response]
end

# fix issue if response's body is a Proc
Expand All @@ -30,8 +25,4 @@ def empty?(response)
def file?(headers)
headers['Content-Transfer-Encoding'] == 'binary'
end

def html_request?(headers, response)
headers['Content-Type'] && headers['Content-Type'].include?('text/html') && response.body.include?('<html')
end
end

0 comments on commit 41e852a

Please sign in to comment.