def serve_one
      Kontena.logger.debug("LHWS") { "Waiting for connection on port #{port}.." }
      socket = server.accept

      content = socket.recvfrom(2048).first.split(/(?:\r)?\n/)

      request = content.shift

      headers = {}
      while line = content.shift
        break if line.nil?
        break if line == ''
        header, value = line.chomp.split(/:\s{0,}/, 2)
        headers[header] = value
      end

      body = content.join("\n")

      Kontena.logger.debug("LHWS") { "Got request: \"#{request.inspect}\n  Headers: #{headers.inspect}\n  Body: #{body}\"" }

      get_request = request[/GET (\/cb.+?) HTTP/, 1]
      if get_request
        if success_response
          socket.print [
            'HTTP/1.1 200 OK',
            'Content-Type: text/html',
            "Content-Length: #{success_response.bytesize}",
            "Connection: close",
            '',
            success_response
          ].join("\r\n")
        else
          socket.print [
            'HTTP/1.1 302 Found',
            "Location: #{SUCCESS_URL}",
            "Referrer-Policy: no-referrer",
            "Connection: close",
            ''
          ].join("\r\n")
        end

        socket.close
        server.close
        uri = URI.parse("http://localhost#{get_request}")
        Kontena.logger.debug("LHWS") { "  * Parsing params: \"#{uri.query}\"" }
        params = {}
        URI.decode_www_form(uri.query).each do |key, value|
          if value.to_s == ''
            next
          elsif value.to_s =~ /\A\d+\z/
            params[key] = value.to_i
          else
            params[key] = value
          end
        end
        params
      else
        # Unless it's a query to /cb, send an error message and keep listening,
        # it might have been something funny like fetching favicon.ico
        socket.print [
          'HTTP/1.1 400 Bad request',
          'Content-Type: text/plain',
          "Content-Length: #{error_response.bytesize}",
          'Connection: close',
          '',
          error_response
        ].join("\r\n")
        socket.close
        serve_one # serve more, this one was not proper.
      end
    end
def serve_one
      Kontena.logger.debug("LHWS") { "Waiting for connection on port #{port}.." }
      socket = server.accept

      content = socket.recvfrom(2048).first.split(/(?:\r)?\n/)

      request = content.shift

      headers = {}
      while line = content.shift
        break if line.nil?
        break if line == ''
        header, value = line.chomp.split(/:\s{0,}/, 2)
        headers[header] = value
      end

      body = content.join("\n")

      Kontena.logger.debug("LHWS") { "Got request: \"#{request.inspect}\n  Headers: #{headers.inspect}\n  Body: #{body}\"" }

      get_request = request[/GET (\/cb.+?) HTTP/, 1]
      if get_request
        if success_response
          socket.print [
            'HTTP/1.1 200 OK',
            'Content-Type: text/html',
            "Content-Length: #{success_response.bytesize}",
            "Connection: close",
            '',
            success_response
          ].join("\r\n")
        else
          socket.print [
            'HTTP/1.1 302 Found',
            "Location: #{SUCCESS_URL}",
            "Referrer-Policy: no-referrer",
            "Connection: close",
            ''
          ].join("\r\n")
        end

        socket.close
        server.close
        uri = URI.parse("http://localhost#{get_request}")
        Kontena.logger.debug("LHWS") { "  * Parsing params: \"#{uri.query}\"" }
        params = {}
        URI.decode_www_form(uri.query).each do |key, value|
          if value.to_s == ''
            next
          elsif value.to_s =~ /\A\d+\z/
            params[key] = value.to_i
          else
            params[key] = value
          end
        end
        params
      else
        # Unless it's a query to /cb, send an error message and keep listening,
        # it might have been something funny like fetching favicon.ico
        socket.print [
          'HTTP/1.1 400 Bad request',
          'Content-Type: text/plain',
          "Content-Length: #{error_response.bytesize}",
          'Connection: close',
          '',
          error_response
        ].join("\r\n")
        socket.close
        serve_one # serve more, this one was not proper.
      end
    end
Serve one request and return query params.

 @return [Hash] query_params