Class: MiddleSquid::Adapters::Squid

Inherits:
MiddleSquid::Adapter show all
Defined in:
lib/middle_squid/adapters/squid.rb

Overview

Adapter for the Squid HTTP Proxy.

Options:

concurrency

Whether to expect a channel ID from Squid.

Enable this option if the concurrency option is set to > 0 in Squid’s / url_rewrite_children directive.

Extra data is configured in Squid with the / url_rewrite_extras directive.

Instance Attribute Summary

Attributes inherited from MiddleSquid::Adapter

#handler

Instance Method Summary collapse

Methods inherited from MiddleSquid::Adapter

#handle, #initialize

Constructor Details

This class inherits a constructor from MiddleSquid::Adapter

Instance Method Details

#input(line) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/middle_squid/adapters/squid.rb', line 22

def input(line)
  parts = line.split

  @chan_id = @options[:concurrency] ? parts.shift : nil
  url, *extras = parts

  extras.map! {|str| URI.unescape str }

  handle url, extras
end

#output(action, options) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/middle_squid/adapters/squid.rb', line 33

def output(action, options)
  case action
  when :accept
    reply 'ERR'
  when :redirect
    reply 'OK', status: options[:status], url: options[:url]
  when :replace
    reply 'OK', :'rewrite-url' => options[:url]
  else
    raise Error, "unsupported action: #{action}"
  end
end

#startObject



16
17
18
19
20
# File 'lib/middle_squid/adapters/squid.rb', line 16

def start
  warn 'WARNING: STDOUT is a terminal. This command should be launched from squid.' if STDOUT.tty?

  EM.open_keyboard Backends::Keyboard, method(:input)
end