 
 resolve = (req) ->
   switch config.get 'proxy.use'
+    # HTTP Request via SOCKS5 proxy
     when 'socks5'
       return _.extend req,
         agentClass: SocksHttpAgent
         agentOptions:
           socksHost: config.get 'proxy.socks5.host', '127.0.0.1'
           socksPort: config.get 'proxy.socks5.port', 1080
+    # HTTP Request via Shadowsocks
+    when 'shadowsocks'
+      return _.extend req,
+        agentClass: SocksHttpAgent
+        agentOptions:
+          socksHost: '127.0.0.1'
+          socksPort: config.get 'proxy.shadowsocks.local.port', 1080
+    # HTTP Request via HTTP proxy
     when 'http'
       host = config.get 'proxy.http.host', '127.0.0.1'
       port = config.get 'proxy.http.port', 8118
       return _.extend req,
         proxy: "http://#{host}:#{port}"
+    # Directly
     else
       return req
 
 class Proxy extends EventEmitter
   constructor: ->
     super()
+    @startShadowsocks()
     @load()
+  # Start Shadowsocks local server
+  startShadowsocks: ->
+    return unless config.get('proxy.use') == 'shadowsocks'
+    host = config.get 'proxy.shadowsocks.server.host', '127.0.0.1'
+    port = config.get 'proxy.shadowsocks.server.port', 8388
+    local = config.get 'proxy.shadowsocks.local.port', 1080
+    password = config.get 'proxy.shadowsocks.password', 'PASSWORD'
+    method = config.get 'proxy.shadowsocks.method', 'aes-256-cfb'
+    timeout = config.get 'proxy.shadowsocks.timeout', 600000
+    @sslocal = shadowsocks.createServer host, port, local, password, method, timeout, '127.0.0.1'
   load: ->
     self = @
     # HTTP Requests
     @server = http.createServer (req, res) ->
       delete req.headers['proxy-connection']
+      # Disable HTTP Keep-Alive
       req.headers['connection'] = 'close'
       parsed = url.parse req.url
       isGameApi = parsed.pathname.startsWith '/kcsapi'
       reqBody = new Buffer(0)
+      # Get all request body
       req.on 'data', (data) ->
         reqBody = Buffer.concat [reqBody, data]
       req.on 'end', async ->

            remote.write head
            client.pipe remote
            remote.pipe client
        else
          remote = net.connect remoteUrl.port, remoteUrl.hostname, ->
            client.write "HTTP/1.1 200 Connection Established\r\nConnection: close\r\n\r\n"

            remote.write data
          remote.on 'data', (data) ->
            client.write data
        # Write data directly to Shadowsocks
        when 'shadowsocks'
          remote = socks.createConnection
            socksHost: config.get '127.0.0.1'
            socksPort: config.get 'proxy.shadowsocks.local.port', 1080
            host: remoteUrl.hostname
            port: remoteUrl.port
          remote.on 'connect', ->
            client.write "HTTP/1.1 200 Connection Established\r\nConnection: close\r\n\r\n"
            remote.write head
          client.on 'data', (data) ->
            remote.write data
          remote.on 'data', (data) ->
            client.write data
        # Write data directly to HTTP proxy
        when 'http'
          host = config.get 'proxy.http.host', '127.0.0.1'
          port = config.get 'proxy.http.port', 8118
          # Write header to http proxy
          msg = "CONNECT #{remoteUrl.hostname}:#{remoteUrl.port} HTTP/#{req.httpVersion}\r\n"
          for k, v of req.headers
            msg += "#{caseNormalizer(k)}: #{v}\r\n"
