text:
import React from 'react';
import { shallow } from 'enzyme';
import { Person } from './Person';

describe('Person', () => {
  describe('view model', () => {
    let person;
    beforeEach(() => {
      person = new Person();
    });

    describe('firstName', () => {
      it('defaults to empty', () => {
        expect(person.firstName()).toBe('');
      });

      it("is invalid with ''", () => {
        expect(person.firstName.valid()).toBe(false);
      });

      it("is valid with 'A'", () => {
        person.firstName('A');
        expect(person.firstName.valid()).toBe(true);
      });
    });

    describe('lastName', () => {
      it('defaults to empty', () => {
        expect(person.lastName()).toBe('');
      });

      it("is invalid with ''", () => {
        expect(person.lastName.valid()).toBe(false);
      });

      it("is valid with 'A'", () => {
        person.lastName('A');
        expect(person.lastName.valid()).toBe(true);
      });
    });

    describe('fullName', () => {
      it('returns first + last', () => {
        person.firstName('A');
        person.lastName('B');
        expect(person.fullName()).toBe('A B');
      });
    });

  });

  describe('bindings', ()=>{
    const rendered = shallow(<Person />);

    it('binds first name', ()=>{
      const elements = rendered.find('input[data-bind="value: firstName"]');
      expect(elements.length).toBe(1);
    });

    it('binds last name', ()=>{
      const elements = rendered.find('input[data-bind="value: lastName"]');
      expect(elements.length).toBe(1);
    });

    it('binds reset button', ()=>{
      const elements = rendered.find('button[data-bind="click: reset, enable: valid"]');
      expect(elements.length).toBe(1);
    })
  })

});


text:
CScreen v1.3 by CodeNMore
A simple way to make resolution-independent Love2D games
Tested for LOVE 0.10.1
See: https://github.com/CodeNMore/CScreen

Zlib License:
Copyright (c) 2016 CodeNMore

This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from
the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software in
a product, an acknowledgment in the product documentation would be appreciated
but is not required.

2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source distribution.

--]]

local CScreen = {}
local rx, ry, ctr = 800, 600, true
local rxv, ryv, fsv, fsvr = 800, 600, 1.0, 1.0
local tx, ty, rwf, rhf = 0, 0, 800, 600
local cr, cg, cb, ca = 0, 0, 0, 255

-- Initializes CScreen with the initial size values
function CScreen.init(tw, th, cntr)
	rx = tw or 800
	ry = th or 600
	ctr = cntr or false
	CScreen.update(love.graphics.getWidth(), love.graphics.getHeight())
end

-- Draws letterbox borders
function CScreen.cease()
	if ctr then
		local pr, pg, pb, pa = love.graphics.getColor()
		love.graphics.setColor(cr, cg, cb, ca)
		love.graphics.scale(fsvr, fsvr)

		if tx ~= 0 then
			love.graphics.rectangle("fill", -tx, 0, tx, rhf)
			love.graphics.rectangle("fill", rxv, 0, tx, rhf)
		elseif ty ~= 0 then
			love.graphics.rectangle("fill", 0, -ty, rwf, ty)
			love.graphics.rectangle("fill", 0, ryv, rwf, ty)
		end

		love.graphics.setColor(pr, pg, pb, pa)
	end
end

-- Scales and centers all graphics properly
function CScreen.apply()
	if ctr then
		love.graphics.translate(tx, ty)
	end
	love.graphics.scale(fsv, fsv)
end

-- Updates CScreen when the window size changes
function CScreen.update(w, h)
	local sx = w / rx
	local sy = h / ry
	fsv = math.min(sx, sy)
	fsvr = 1 / fsv
	-- Centering
	if ctr and fsv == sx then -- Vertically
		tx = 0
		ty = (h / 2) - (ry * fsv / 2)
	elseif ctr and fsv == sy then -- Horizontally
		ty = 0
		tx = (w / 2) - (rx * fsv / 2)
	end
	-- Variable sets
	rwf = w
	rhf = h
	rxv = rx * fsv
	ryv = ry * fsv
end

-- Convert from window coordinates to target coordinates
function CScreen.project(x, y)
	return math.floor((x - tx) / fsv), math.floor((y - ty) / fsv)
end

-- Change letterbox color
function CScreen.setColor(r, g, b, a)
	cr = r
	cg = g
	cb = b
	ca = a
end

-- Return the table for use
return CScreen

redpajama_set_name: RedPajamaGithub


text:
#include "ChMklEngine.h"
#include <algorithm>

namespace chrono
{
	enum phase_t
	{
		COMPLETE = 13,
		ANALYSIS = 11,
		ANALYSIS_NUMFACTORIZATION = 12,
		NUMFACTORIZATION = 22,
		NUMFACTORIZATION_SOLVE = 23,
		SOLVE = 33,
		SOLVE_FORWARD = 331,
		SOLVE_DIAGONAL = 332,
		SOLVE_BACKWARD = 333,
		RELEASE_FACTORS = 0,
		RELEASE_ALL = -1
	};

	ChMklEngine::ChMklEngine(int problem_size, int matrix_type):
		a(nullptr), ia(nullptr), ja(nullptr), b(nullptr), x(nullptr), last_phase_called(-1),
		/*Currently only one rhs is supported*/
		nrhs(1), //< Number of KnownVectors
		maxfct(1), //< Maximum number of factors with identical sparsity structure that must be kept in memory at the same time [def: 1]
		mnum(1)  //< Actual matrix for the solution phase (1 ≤ mnum ≤ maxfct) [def: 1]
	{
		SetProblemSize(problem_size);
		ResetSolver(matrix_type);
	}

	ChMklEngine::~ChMklEngine()
	{
		int phase = RELEASE_ALL;
		int msglvl = 1;
		int error;
		PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, perm.data() , &nrhs, iparm, &msglvl, b, x, &error);
		if (error)
			printf("Error while releasing memory: %d",error);
	}

	void ChMklEngine::SetMatrix(double* Z_values, int* Z_colIndex, int* Z_rowIndex)
	{
		a = Z_values;
		ja = Z_colIndex;
		ia = Z_rowIndex;
	}

	void ChMklEngine::SetMatrix(ChCSR3Matrix& Z){
		a = Z.GetValuesAddress();
		ja = Z.GetColIndexAddress();
		ia = Z.GetRowIndexAddress();
		if (Z.GetSymmetry() != mtype)
			ResetSolver(Z.GetSymmetry());
		SetProblemSize(Z.GetRows());
	}

	void ChMklEngine::SetSolutionVector(ChMatrix<>& insx)
	{
		x = insx.GetAddress();
	}

	void ChMklEngine::SetSolutionVector(double* insx)
	{
		x = insx;
	}

	void ChMklEngine::SetKnownVector(ChMatrix<>& insf_chrono, ChMatrix<>& insb_chrono, ChMatrix<>& bdest){
		// assures that the destination vector has the correct dimension
		if (insb_chrono.GetRows() + insf_chrono.GetRows() != bdest.GetRows())
			bdest.Resize((insb_chrono.GetRows() + insf_chrono.GetRows()), 1);

		// pastes values of insf and insb in fdest
		for (int i = 0; i < insf_chrono.GetRows(); i++)
			bdest.SetElement(i, 0, insf_chrono.GetElement(i, 0));
		for (int i = 0; i < insb_chrono.GetRows(); i++)
			bdest.SetElement(i + insf_chrono.GetRows(), 0, insb_chrono.GetElement(i, 0));

		// takes the fdest as known term of the problem
		SetKnownVector(bdest);
	}

	void ChMklEngine::SetProblem(ChCSR3Matrix& Z, ChMatrix<>& insb, ChMatrix<>& insx){
		SetMatrix(Z);
		SetSolutionVector(insx);
		SetKnownVector(insb);
	}

	/// Tells the solver to store the permutation vector \c perm and use it in the next calls.
	void ChMklEngine::UsePermutationVector(bool on_off)
	{
		// The perm array is not set yet; it is built by Pardiso during the next factorization phase.
		// IPARM(5)=2 (perm as output) says to Pardiso to output the perm vector used by the factorization;
		// PardisoCall() will then switch IPARM(5) to 1 (perm as input)
		IPARM(5) = (on_off) ? 2 : 0;

		if (on_off == true)
		{
			resetIparmElement(31);
			resetIparmElement(36);

			perm.resize(n);
		}

	}

	/// Warns if a incompatible parameter has been previously set
	void ChMklEngine::resetIparmElement(int iparm_num, int reset_value)
	{
		if (IPARM(iparm_num) != reset_value)
		{
			IPARM(iparm_num) = reset_value;

			switch (iparm_num)
			{
			case 4:
				printf("Preconditioned CGS has been disabled. IPARM(4) = 0"); break;
			case 5:
				printf("Permutation vector has been disabled.IPARM(5) = 0"); break;
			case 8:
				printf("Iterative refinement steps has been disabled. IPARM(8) = 0"); break;
			case 31:
				printf("Partial solution has been disabled. IPARM(31) = 0"); break;
			case 36:
				printf("Schur computation has been disabled. IPARM(36) = 0"); break;
			case 60:
				printf("Mkl is now running in-core. IPARM(60) = 0"); break;
			default:
				printf("WARN: IparmReset not handled");
			}
		}
	}

	void ChMklEngine::UsePartialSolution(int option, int start_row, int end_row)
	{
		assert(option == 0 || option == 1 || option == 2 || option == 3);

		IPARM(31) = option;

		if (option)
		{
			resetIparmElement(4);
			resetIparmElement(5);
			resetIparmElement(8);
			resetIparmElement(36);
			resetIparmElement(60);

			perm.resize(n);

			if (option == 1 || option == 2)
			{
				for (int row_sel = 0; row_sel < n; row_sel++)
					perm[row_sel] = (b[row_sel] == 0) ? 0 : 1;
			}
			else if (option == 3)
			{
				for (int row_sel = 0; row_sel < n; row_sel++)
					perm[row_sel] = (row_sel < start_row || row_sel > end_row) ? 0 : 1;
			}
		}

	}

	/// The Schur complement is output on the solution vector \c x that has to be resized to \c n x \c n size;
	/// The next call to Pardiso must not involve a solution phase. So no phase 33, 331, 332, 333, 23, 13 ecc...
	/// Any solution phase in fact would ouput the solution on the solution vector \c x.
	/// The element (\param[start_row],\param[start_row] must be the top-left element of the matrix on which the Schur complement will be computed;
	/// The element (\param[end_row],\param[end_row] must be the bottom-right element of the matrix on which the Schur complement will be computed;
	void ChMklEngine::OutputSchurComplement(int option, int start_row, int end_row)
	{
		IPARM(36) = option;

		if (option)
		{
			resetIparmElement(5);
			resetIparmElement(31);

			perm.resize(n);

			assert(!(start_row == 0) && (end_row == 0));

			if (end_row == 0)
				end_row = n-1;

			for (int row_sel = 0; row_sel < n; row_sel++)
				perm[row_sel] = (row_sel < start_row || row_sel > end_row) ? 0 : 1;

		}
	}

	void ChMklEngine::SetPreconditionedCGS(bool on_off, int L)
	{
		if (on_off)
		{
			int iparm4_value = 0;
			int K = 0;
			K = (mtype == 11 || mtype == 1) ? 1 : 2;
			IPARM(4) = 10 * L + K;
		}
		else
			IPARM(4) = 0;
	}

	int ChMklEngine::PardisoCall(int set_phase, int message_level){

		int error;
		last_phase_called = set_phase;
		int phase_now = set_phase;
		PARDISO(pt, &maxfct, &mnum, &mtype, &phase_now, &n, a, ia, ja, perm.data() , &nrhs, iparm, &message_level, b, x, &error);

		if (IPARM(5) == 2)
			IPARM(5) = 1;

		return error;

	}

	void ChMklEngine::ResetSolver(int new_mat_type)
	{
		// After the first call to pardiso do not directly modify "pt", as that could cause a serious memory leak.
		if (new_mat_type)
			mtype = new_mat_type;
		pardisoinit(pt, &mtype, iparm);

		/*
		* NOTE: for highly indefinite symmetric matrices (e.g. interior point optimizations or saddle point problems)
		* use IPARM(11) = 1 (scaling) and IPARM(13) = 1 (matchings);
		*/

		/*IPARM easy settings*/
		IPARM(1) = 1;				/* No default values for solver */
		IPARM(6) = 0;				/* Write solution on u */
		IPARM(12) = 0;				/* Solve with transposed/conjugate transposed matrix [def: 0, solve simply A*x=b]*/
		IPARM(18) = -1;				/* Report number of nonzeros */
		IPARM(19) = -1;				/* Report number of floating point operations */
		IPARM(35) = 1;				/* Zero based indexing */
		IPARM(27) = 0;				/* Matrix checker */
		IPARM(28) = 0;				/* Double precision */
		IPARM(36) = 0;				/* Schur complement matrix computation control [def:0, do not compute Schur] */
		IPARM(56) = 0;				/* Diagonal and pivoting control [def:0, disabled] */
		IPARM(60) = 0;				/* In-Core (OC) / Out-Of-Core (OOC) switch [def:0, IC mode] */

		/* IPARM fine settings */
		IPARM(2) = 2;				/* Fill-in reducing ordering [def:2] */
		IPARM(4) = 0;				/* Preconditioned CGS/CG [def:0] - HIGHLY RECOMMENDED */
		IPARM(5) = 0;				/* User fill-in reducing permutation [def:0, default filling]*/
		IPARM(8) = 10;				/* Maximum number of iterative refinement steps */

	}

	void ChMklEngine::GetResidual(double* res) {
		mkl_cspblas_dcsrgemv("N", &n, a, ia, ja, x, res); // performs Matrix*Solution
		for (int i = 0; i < n; i++){
			res[i] = b[i] - res[i];	// performs: rhs - Matrix*Solution
		};
	};

	double ChMklEngine::GetResidualNorm(double* res) const{
		double norm = 0;
		for (int i = 0; i < n; i++){
			norm += res[i] * res[i];
		};
		norm = sqrt(norm);
		return norm;
	};

	void ChMklEngine::PrintIparmOutput() const
	{
		printf("\n[7] Number of iterative refinement steps performed: %d", IPARM(7));
		if (mtype == 11 || mtype == 13 || mtype == -2 || mtype == -4 || mtype == -6)
			printf("\n[14] Number of perturbed pivots: %d", IPARM(14));
		if (last_phase_called == 11 || last_phase_called == 12 || last_phase_called == 13)
		{
			printf("\n[15] Peak memory on symbolic factorization (kB): %d", IPARM(15));
			printf("\n[16] Permanent memory on symbolic factorization (kB): %d", IPARM(16));
			printf("\n[17] Peak memory on numerical factorization and solution (kB): %d", IPARM(17));
			printf("\nTotal peak memory consumed (kB): %d", std::max(IPARM(15), IPARM(16) + IPARM(17)));
		}

		printf("\n[18] Number of non-zero elements in the factors: %d", IPARM(18));
		printf("\n[19] Number of floating point operations necessary to factor the matrix (^6): %d", IPARM(19));
		printf("\n[20] Number of completed CG/CGS iterations: %d", IPARM(20));
		if (mtype == -2)
		{
			printf("\n[22] Number of positive eigenvalues: %d", IPARM(22));
			printf("\n[23] Number of negative eigenvalues: %d\n", IPARM(23));
		}
		if (mtype == 2 || mtype == 4)
			printf("\n[30] Number of zero or negative pivots: %d", IPARM(30));
	}

}


text:
local admin_api = require "spec.fixtures.admin_api"
local helpers = require "spec.helpers"
local cjson   = require "cjson"
local path_handling_tests = require "spec.fixtures.router_path_handling_tests"

local tonumber = tonumber

local enable_buffering
local enable_buffering_plugin
local stream_tls_listen_port = 9020

local function insert_routes(bp, routes)
  if type(bp) ~= "table" then
    return error("expected arg #1 to be a table", 2)
  end
  if type(routes) ~= "table" then
    return error("expected arg #2 to be a table", 2)
  end

  if not bp.done then -- strategy ~= "off"
    bp = admin_api
  end

  enable_buffering_plugin = bp.plugins:insert({
    name = "enable-buffering",
    protocols = { "http", "https", "grpc", "grpcs" },
    service = ngx.null,
    consumer = ngx.null,
    route = ngx.null,
  })

  for i = 1, #routes do
    local route = routes[i]

    local service
    if route.service == ngx.null then
      service = route.service

    else
      service = route.service or {}

      if not service.host then
        service.host = helpers.mock_upstream_host
      end

      if not service.port then
        service.port = helpers.mock_upstream_port
      end

      if not service.protocol then
        service.protocol = helpers.mock_upstream_protocol
      end

      service = bp.named_services:insert(service)
    end
    route.service = service

    if not route.protocols then
      route.protocols = { "http" }
    end

    route.service = service
    route = bp.routes:insert(route)
    route.service = service

    routes[i] = route
  end

  if bp.done then
    local declarative = require "kong.db.declarative"

    local cfg = bp.done()
    local yaml = declarative.to_yaml_string(cfg)
    local admin_client = helpers.admin_client()

    local res = assert(admin_client:send {
      method  = "POST",
      path    = "/config",
      body    = {
        config = yaml,
      },
      headers = {
        ["Content-Type"] = "multipart/form-data",
      }
    })
    assert.res_status(201, res)
    admin_client:close()

  end

  ngx.sleep(0.5)  -- temporary wait for worker events and timers

  return routes
end

local function remove_routes(strategy, routes)
  if strategy == "off" or not routes then
    return
  end

  local services = {}

  for _, route in ipairs(routes) do
    if route.service ~= ngx.null then
      local sid = route.service.id
      if not services[sid] then
        services[sid] = route.service
        table.insert(services, services[sid])
      end
    end
  end

  for _, route in ipairs(routes) do
    admin_api.routes:remove({ id = route.id })
  end

  for _, service in ipairs(services) do
    admin_api.services:remove(service)
  end

  admin_api.plugins:remove(enable_buffering_plugin)
end

--for _, flavor in ipairs({ "traditional", "traditional_compatible" }) do
for _, flavor in ipairs({ "traditional", "traditional_compatible" }) do
for _, b in ipairs({ false, true }) do enable_buffering = b
for _, strategy in helpers.each_strategy() do
  describe("Router [#" .. strategy .. ", flavor = " .. flavor .. "] with buffering [" .. (b and "on]" or "off]") , function()
    local proxy_client
    local proxy_ssl_client
    local bp
    local it_trad_only = (flavor == "traditional") and it or pending

    lazy_setup(function()
      local fixtures = {
        dns_mock = helpers.dns_mock.new()
      }
      fixtures.dns_mock:A {
        name = "grpcs_1.test",
        address = "127.0.0.1",
      }
      fixtures.dns_mock:A {
        name = "grpcs_2.test",
        address = "127.0.0.1",
      }

      bp = helpers.get_db_utils(strategy, {
        "routes",
        "services",
        "plugins",
      }, {
        "enable-buffering",
      })

      assert(helpers.start_kong({
        router_flavor = flavor,
        database = strategy,
        plugins = "bundled,enable-buffering",
        nginx_conf = "spec/fixtures/custom_nginx.template",
        stream_listen = string.format("127.0.0.1:%d ssl", stream_tls_listen_port),
      }, nil, nil, fixtures))
    end)

    lazy_teardown(function()
      helpers.stop_kong()
    end)

    before_each(function()
      proxy_client = helpers.proxy_client()
      proxy_ssl_client = helpers.proxy_ssl_client()
    end)

    after_each(function()
      if proxy_client then
        proxy_client:close()
      end
      if proxy_ssl_client then
        proxy_ssl_client:close()
      end
    end)

    describe("no routes match", function()

      it("responds 404 if no route matches", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          headers = {
            host  = "inexistent.com"
          }
        })

        local body = assert.response(res).has_status(404)
        local json = cjson.decode(body)
        assert.matches("^kong/", res.headers.server)
        assert.equal("no Route matched with those values", json.message)
      end)
    end)

    describe("use-cases", function()
      local routes
      local first_service_name

      lazy_setup(function()
        routes = insert_routes(bp, {
          {
            methods    = { "GET" },
            protocols  = { "http" },
            strip_path = false,
          },
          {
            methods    = { "POST", "PUT" },
            paths      = { "/post", "/put" },
            protocols  = { "http" },
            strip_path = false,
          },
          {
            paths      = { "/mock_upstream" },
            protocols  = { "http" },
            strip_path = true,
            service    = {
              path     = "/status",
            },
          },
          {
            paths      = { "/private" },
            protocols  = { "http" },
            strip_path = false,
            service    = {
              path     = "/basic-auth/",
            },
          },
          {
            paths      = { [[~/users/\d+/profile]] },
            protocols  = { "http" },
            strip_path = true,
            service    = {
              path     = "/anything",
            },
          },
          {
            protocols = { "http", "https" },
            hosts     = { "serviceless-route-http.test" },
            service   = ngx.null,
          },
          {
            paths      = { "/disabled-service1" },
            protocols  = { "http" },
            strip_path = false,
            service    = {
              path     = "/disabled-service-path/",
              enabled  = false,
            },
          },
          {
            paths      = { [[~/enabled-service/\w+]] },
            protocols  = { "http" },
            strip_path = true,
            service    = {
              path     = "/anything/",
              enabled  = true,
              name     = "enabled-service",
            },
          },
          {
            paths     = { "/enabled-service/disabled" },
            protocols  = { "http" },
            strip_path = true,
            service    = {
              path     = "/some-path/",
              enabled  = false,
            },
          },
        })
        first_service_name = routes[1].service.name
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      it("responds 503 if no service found", function()
        local res, body
        helpers.wait_until(function()
          res = assert(proxy_client:get("/", {
            headers = {
              Host = "serviceless-route-http.test",
            },
          }))
          return pcall(function()
            body = assert.response(res).has_status(503)
          end)
        end, 10)

        local json = cjson.decode(body)
        assert.equal("no Service found with those values", json.message)

        local res = assert(proxy_ssl_client:get("/", {
          headers = {
            Host = "serviceless-route-http.test",
          },
        }))
        local body = assert.response(res).has_status(503)
        local json = cjson.decode(body)

        assert.equal("no Service found with those values", json.message)
      end)

      it("restricts an route to its methods if specified", function()
        -- < HTTP/1.1 POST /post
        -- > 200 OK
        local res = assert(proxy_client:send {
          method  = "POST",
          path    = "/post",
          headers = { ["kong-debug"] = 1 },
        })

        assert.response(res).has_status(200)
        assert.equal(routes[2].id,           res.headers["kong-route-id"])
        assert.equal(routes[2].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[2].service.name, res.headers["kong-service-name"])

        -- < HTTP/1.1 DELETE /post
        -- > 404 NOT FOUND
        res = assert(proxy_client:send {
          method  = "DELETE",
          path    = "/post",
          headers = { ["kong-debug"] = 1 },
        })

        assert.response(res).has_status(404)
        assert.is_nil(res.headers["kong-route-id"])
        assert.is_nil(res.headers["kong-service-id"])
        assert.is_nil(res.headers["kong-service-name"])
      end)

      it("routes by method-only if no other match is found", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/get",
          headers = { ["kong-debug"] = 1 },
        })

        assert.response(res).has_status(200)

        assert.equal(routes[1].id,           res.headers["kong-route-id"])
        assert.equal(routes[1].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[1].service.name, res.headers["kong-service-name"])
      end)

      describe("requests without Host header", function()
        it("HTTP/1.0 routes normally", function()
          -- a very limited HTTP client for sending requests without Host
          -- header
          local sock = ngx.socket.tcp()

          finally(function()
            sock:close()
          end)

          assert(sock:connect(helpers.get_proxy_ip(),
                              helpers.get_proxy_port()))

          local req = "GET /get HTTP/1.0\r\nKong-Debug: 1\r\n\r\n"
          assert(sock:send(req))

          local line = assert(sock:receive("*l"))

          local status = tonumber(string.sub(line, 10, 12))
          assert.equal(200, status)

          -- TEST: we matched an API that had no Host header defined
          local remainder = assert(sock:receive("*a"))
          assert.matches("kong-service-name: " .. first_service_name,
                         string.lower(remainder), nil, true)
        end)

        it("HTTP/1.1 is rejected by NGINX", function()
          local sock = ngx.socket.tcp()

          finally(function()
            sock:close()
          end)

          assert(sock:connect(helpers.get_proxy_ip(),
                              helpers.get_proxy_port()))

          local req = "GET /get HTTP/1.1\r\nKong-Debug: 1\r\n\r\n"
          assert(sock:send(req))

          -- TEST: NGINX rejected this request
          local line = assert(sock:receive("*l"))
          local status = tonumber(string.sub(line, 10, 12))
          assert.equal(400, status)

          -- TEST: we ensure that Kong catches this error and
          -- produces the response from its own error handler
          local remainder = assert(sock:receive("*a"))
          assert.matches("Bad request", remainder, nil, true)
          assert.matches("Server: kong/", remainder, nil, true)
        end)
      end)

      describe("route with a path component in its upstream_url", function()
        it("with strip_path = true", function()
          local res = assert(proxy_client:send {
            method  = "GET",
            path    = "/mock_upstream/201",
            headers = { ["kong-debug"] = 1 },
          })

          assert.res_status(201, res)

          assert.equal(routes[3].id,           res.headers["kong-route-id"])
          assert.equal(routes[3].service.id,   res.headers["kong-service-id"])
          assert.equal(routes[3].service.name, res.headers["kong-service-name"])
        end)
      end)

      it("route with a path component in its upstream_url and strip_path = false", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/private/passwd",
          headers = { ["kong-debug"] = 1 },
        })

        assert.res_status(401, res)

        assert.equal(routes[4].id,           res.headers["kong-route-id"])
        assert.equal(routes[4].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[4].service.name, res.headers["kong-service-name"])
      end)

      it("route with a path component in its upstream_url and [uri] with a regex", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/users/foo/profile",
          headers = { ["kong-debug"] = 1 },
        })

        assert.res_status(404, res)

        res = assert(proxy_client:send {
          method  = "GET",
          path    = "/users/123/profile",
          headers = { ["kong-debug"] = 1 },
        })

        assert.res_status(200, res)

        assert.equal(routes[5].id,           res.headers["kong-route-id"])
        assert.equal(routes[5].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[5].service.name, res.headers["kong-service-name"])
      end)

      describe('handles not enabled services', function()
        it('ignores route where service enabled=false', function()
          local res = assert(proxy_client:send {
            method  = "GET",
            path    = "/disabled-service1",
            headers = { ["kong-debug"] = 1 },
          })

          assert.res_status(404, res)
        end)

        it('routes to regex path when longer path service enabled=false', function()
          local res = assert(proxy_client:send {
            method  = "GET",
            path    = "/enabled-service/disabled",
            headers = { ["kong-debug"] = 1 },
          })

          assert.res_status(200, res)
          assert.equal(routes[8].id,           res.headers["kong-route-id"])
          assert.equal(routes[8].service.id,   res.headers["kong-service-id"])
          assert.equal("enabled-service",      res.headers["kong-service-name"])
        end)
      end)
    end)

    if not enable_buffering then
    describe("use cases #grpc", function()
      local routes
      local service = {
        url = helpers.grpcbin_url,
      }

      local proxy_client_grpc
      local proxy_client_grpcs

      lazy_setup(function()
        routes = insert_routes(bp, {
          {
            protocols = { "grpc", "grpcs" },
            hosts = {
              "grpc1",
              "grpc1:" .. helpers.get_proxy_port(false, true),
              "grpc1:" .. helpers.get_proxy_port(true, true),
            },
            service = service,
          },
          {
            protocols = { "grpc", "grpcs" },
            hosts = {
              "grpc2",
              "grpc2:" .. helpers.get_proxy_port(false, true),
              "grpc2:" .. helpers.get_proxy_port(true, true),
            },
            service = service,
          },
          {
            protocols = { "grpc", "grpcs" },
            paths = { "/hello.HelloService/SayHello" },
            service = service,
          },
          {
            protocols = { "grpc", "grpcs" },
            paths = { "/hello.HelloService/LotsOfReplies" },
            service = service,
          },
          {
            protocols = { "grpc", "grpcs" },
            hosts = { "*.grpc.com" },
            service = service,
          },
          {
            protocols = { "grpc", "grpcs" },
            hosts     = { "serviceless-route-grpc.test" },
            service   = ngx.null,
          }
        })

        proxy_client_grpc = helpers.proxy_client_grpc()
        proxy_client_grpcs = helpers.proxy_client_grpcs()
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      it("responds 503 if no service found", function()
        local ok, resp = proxy_client_grpc({
          service = "hello.HelloService.SayHello",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-v"] = true,
            ["-H"] = "'kong-debug: 1'",
            ["-authority"] = "serviceless-route-grpc.test",
          }
        })

        assert.falsy(ok)
        assert.equal("ERROR:\n  Code: Unavailable\n  Message: no Service found with those values\n", resp)

        local ok, resp = proxy_client_grpcs({
          service = "hello.HelloService.SayHello",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-v"] = true,
            ["-H"] = "'kong-debug: 1'",
            ["-authority"] = "serviceless-route-grpc.test",
          }
        })

        assert.falsy(ok)
        assert.equal("ERROR:\n  Code: Unavailable\n  Message: no Service found with those values\n", resp)
      end)

      it("restricts a route to its 'hosts' if specified", function()
        local ok, resp = proxy_client_grpc({
          service = "hello.HelloService.SayHello",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-v"] = true,
            ["-H"] = "'kong-debug: 1'",
            ["-authority"] = "grpc1",
          }
        })
        assert.truthy(ok)
        assert.truthy(resp)
        assert.matches("kong-route-id: " .. routes[1].id, resp, nil, true)

        ok, resp = proxy_client_grpc({
          service = "hello.HelloService.SayHello",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-v"] = true,
            ["-H"] = "'kong-debug: 1'",
            ["-authority"] = "grpc2",
          }
        })
        assert.truthy(ok)
        assert.truthy(resp)
        assert.matches("kong-route-id: " .. routes[2].id, resp, nil, true)
      end)

      it("restricts a route to its 'hosts' if specified (grpcs)", function()
        local ok, resp = proxy_client_grpcs({
          service = "hello.HelloService.SayHello",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-v"] = true,
            ["-H"] = "'kong-debug: 1'",
            ["-authority"] = "grpc1",
          }
        })
        assert.truthy(ok)
        assert.truthy(resp)
        assert.matches("kong-route-id: " .. routes[1].id, resp, nil, true)

        ok, resp = proxy_client_grpc({
          service = "hello.HelloService.SayHello",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-v"] = true,
            ["-H"] = "'kong-debug: 1'",
            ["-authority"] = "grpc2",
          }
        })
        assert.truthy(ok)
        assert.truthy(resp)
        assert.matches("kong-route-id: " .. routes[2].id, resp, nil, true)
      end)

      it("restricts a route to its wildcard 'hosts' if specified", function()
        local ok, resp = proxy_client_grpc({
          service = "hello.HelloService.SayHello",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-v"] = true,
            ["-H"] = "'kong-debug: 1'",
            ["-authority"] = "service1.grpc.com",
          }
        })
        assert.truthy(ok)
        assert.truthy(resp)
        assert.matches("kong-route-id: " .. routes[5].id, resp, nil, true)
      end)

      it("restricts a route to its wildcard 'hosts' if specified (grpcs)", function()
        local ok, resp = proxy_client_grpcs({
          service = "hello.HelloService.SayHello",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-v"] = true,
            ["-H"] = "'kong-debug: 1'",
            ["-authority"] = "service1.grpc.com",
          }
        })
        assert.truthy(ok)
        assert.truthy(resp)
        assert.matches("kong-route-id: " .. routes[5].id, resp, nil, true)
      end)

      it("restricts a route to its 'paths' if specified", function()
        local ok, resp = proxy_client_grpc({
          service = "hello.HelloService.SayHello",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-v"] = true,
            ["-H"] = "'kong-debug: 1'",
          }
        })
        assert.truthy(ok)
        assert.truthy(resp)
        assert.matches("kong-route-id: " .. routes[3].id, resp, nil, true)

        ok, resp = proxy_client_grpcs({
          service = "hello.HelloService.LotsOfReplies",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-v"] = true,
            ["-H"] = "'kong-debug: 1'",
          }
        })
        assert.truthy(ok)
        assert.truthy(resp)
        assert.matches("kong-route-id: " .. routes[4].id, resp, nil, true)
      end)

      it("restricts a route to its 'paths' if specified (grpcs)", function()
        local ok, resp = proxy_client_grpcs({
          service = "hello.HelloService.SayHello",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-v"] = true,
            ["-H"] = "'kong-debug: 1'",
          }
        })
        assert.truthy(ok)
        assert.truthy(resp)
        assert.matches("kong-route-id: " .. routes[3].id, resp, nil, true)

        ok, resp = proxy_client_grpcs({
          service = "hello.HelloService.LotsOfReplies",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-v"] = true,
            ["-H"] = "'kong-debug: 1'",
          }
        })
        assert.truthy(ok)
        assert.truthy(resp)
        assert.matches("kong-route-id: " .. routes[4].id, resp, nil, true)
      end)
    end)
    end -- not enable_buffering

    describe("URI regexes order of evaluation with created_at", function()
      local routes

      lazy_setup(function()
        routes = insert_routes(bp, {
          {
            created_at = 1234567890,
            strip_path = true,
            paths      = { "~/status/(re)" },
            service    = {
              name     = "regex_1",
              path     = "/status/200",
            },
          },
          {
            created_at = 1234567891,
            strip_path = true,
            paths      = { "~/status/(r)" },
            service    = {
              name     = "regex_2",
              path     = "/status/200",
            },
          },
          {
            created_at = 1234567892,
            strip_path = true,
            paths      = { "/status" },
            service    = {
              name     = "regex_3",
              path     = "/status/200",
            },
          }
        })
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      it_trad_only("depends on created_at field", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/status/r",
          headers = { ["kong-debug"] = 1 },
        })
        assert.res_status(200, res)

        assert.equal(routes[2].id,           res.headers["kong-route-id"])
        assert.equal(routes[2].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[2].service.name, res.headers["kong-service-name"])

        res = assert(proxy_client:send {
          method  = "GET",
          path    = "/status/re",
          headers = { ["kong-debug"] = 1 },
        })
        assert.res_status(200, res)

        assert.equal(routes[1].id,           res.headers["kong-route-id"])
        assert.equal(routes[1].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[1].service.name, res.headers["kong-service-name"])
      end)
    end)

    describe("URI regexes order of evaluation with regex_priority", function()
      local routes

      lazy_setup(function()
        routes = insert_routes(bp, {

          -- TEST 1 (regex_priority)

          {
            strip_path = true,
            paths      = { "~/status/(?P<foo>re)" },
            service    = {
              name     = "regex_1",
              path     = "/status/200",
            },
            regex_priority = 0,
          },
          {
            strip_path = true,
            paths      = { "~/status/(re)" },
            service    = {
              name     = "regex_2",
              path     = "/status/200",
            },
            regex_priority = 4, -- shadows service which is created before and is shorter
          },

          -- TEST 2 (tie breaker by created_at)

          {
            created_at = 1234567890,
            strip_path = true,
            paths      = { "~/status/(ab)" },
            service    = {
              name     = "regex_3",
              path     = "/status/200",
            },
            regex_priority = 0,
          },
          {
            created_at = 1234567891,
            strip_path = true,
            paths      = { "~/status/(ab)c?" },
            service    = {
              name     = "regex_4",
              path     = "/status/200",
            },
            regex_priority = 0,
          },
        })
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      it("depends on the regex_priority field", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/status/re",
          headers = { ["kong-debug"] = 1 },
        })
        assert.res_status(200, res)
        assert.equal("regex_2", res.headers["kong-service-name"])
      end)

      it_trad_only("depends on created_at if regex_priority is tie", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/status/ab",
          headers = { ["kong-debug"] = 1 },
        })
        assert.res_status(200, res)
        assert.equal("regex_3", res.headers["kong-service-name"])
      end)
    end)

    describe("URI arguments (querystring)", function()
      local routes

      lazy_setup(function()
        routes = insert_routes(bp, {
          {
            hosts = { "mock_upstream" },
          },
        })
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      it("preserves URI arguments", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/get",
          query   = {
            foo   = "bar",
            hello = "world",
          },
          headers = {
            ["Host"] = "mock_upstream",
          },
        })

        local body = assert.res_status(200, res)
        local json = cjson.decode(body)
        assert.equal("bar", json.uri_args.foo)
        assert.equal("world", json.uri_args.hello)
      end)

      it("does proxy an empty querystring if URI does not contain arguments", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/request?",
          headers = {
            ["Host"] = "mock_upstream",
          },
        })

        local body = assert.res_status(200, res)
        local json = cjson.decode(body)
        assert.matches("/request%?$", json.vars.request_uri)
      end)

      it("does proxy a querystring with an empty value", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/get?hello",
          headers = {
            ["Host"] = "mock_upstream",
          },
        })

        local body = assert.res_status(200, res)
        local json = cjson.decode(body)
        assert.matches("/get%?hello$", json.url)
      end)
    end)

    describe("URI normalization", function()
      local routes

      lazy_setup(function()
        routes = insert_routes(bp, {
          {
            strip_path = true,
            paths      = { "/foo/bar" },
          },
          {
            strip_path = true,
            paths      = { "/hello" },
          },
          {
            strip_path = false,
            paths      = { "/anything/world" },
          },
        })
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      it("matches against normalized URI with \"..\"", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/foo/a/../bar",
          headers = { ["kong-debug"] = 1 },
        })

        local body = assert.res_status(200, res)
        body = cjson.decode(body)

        assert.equal(routes[1].id,           res.headers["kong-route-id"])
        assert.equal(routes[1].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[1].service.name, res.headers["kong-service-name"])
        assert.equal("/foo/a/../bar", body.headers["x-forwarded-path"])
      end)

      it("matches against normalized URI with \"//\"", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/foo//bar",
          headers = { ["kong-debug"] = 1 },
        })

        local body = assert.res_status(200, res)
        body = cjson.decode(body)

        assert.equal(routes[1].id,           res.headers["kong-route-id"])
        assert.equal(routes[1].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[1].service.name, res.headers["kong-service-name"])
        assert.equal("/foo//bar", body.headers["x-forwarded-path"])
      end)

      it("matches against normalized URI with \"/./\"", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/foo/./bar",
          headers = { ["kong-debug"] = 1 },
        })

        local body = assert.res_status(200, res)
        body = cjson.decode(body)

        assert.equal(routes[1].id,           res.headers["kong-route-id"])
        assert.equal(routes[1].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[1].service.name, res.headers["kong-service-name"])
        assert.equal("/foo/./bar", body.headers["x-forwarded-path"])
      end)

      it("matches against normalized URI with percent-encoded characters", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/h%65llo",
          headers = { ["kong-debug"] = 1 },
        })

        local body = assert.res_status(200, res)
        body = cjson.decode(body)

        assert.equal(routes[2].id,           res.headers["kong-route-id"])
        assert.equal(routes[2].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[2].service.name, res.headers["kong-service-name"])
        assert.equal("/h%65llo", body.headers["x-forwarded-path"])
      end)

      it("proxies normalized URI to upstream with strip_path = true", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/h%65llo/anything/a/../b",
          headers = { ["kong-debug"] = 1 },
        })

        local body = assert.res_status(200, res)
        body = cjson.decode(body)

        assert.equal(routes[2].id,           res.headers["kong-route-id"])
        assert.equal(routes[2].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[2].service.name, res.headers["kong-service-name"])
        assert.equal("/anything/b", body.vars.request_uri)
      end)

      it("proxies normalized URI to upstream with strip_path = false", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/anything/./a/../wor%6cd/a/../b",
          headers = { ["kong-debug"] = 1 },
        })

        local body = assert.res_status(200, res)
        body = cjson.decode(body)

        assert.equal(routes[3].id,           res.headers["kong-route-id"])
        assert.equal(routes[3].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[3].service.name, res.headers["kong-service-name"])
        assert.equal("/anything/world/b", body.vars.request_uri)
      end)

      it("re-encode special characters in request uri when proxying to the upstream", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/anything/world/cat%20and%20dog",
          headers = { ["kong-debug"] = 1 },
        })

        local body = assert.res_status(200, res)
        body = cjson.decode(body)

        assert.equal(routes[3].id,           res.headers["kong-route-id"])
        assert.equal(routes[3].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[3].service.name, res.headers["kong-service-name"])
        assert.equal("/anything/world/cat%20and%20dog", body.vars.request_uri)
      end)
    end)

    describe("strip_path", function()
      local routes

      lazy_setup(function()
        routes = insert_routes(bp, {
          {
            paths      = { "/x/y/z", "/z/y/x" },
            strip_path = true,
          },
        })
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      describe("= true", function()
        it("strips subsequent calls to an route with different [paths]", function()
          local res_uri_1 = assert(proxy_client:send {
            method = "GET",
            path   = "/x/y/z/get",
          })

          local body = assert.res_status(200, res_uri_1)
          local json = cjson.decode(body)
          assert.matches("/get", json.url, nil, true)
          assert.not_matches("/x/y/z/get", json.url, nil, true)

          local res_uri_2 = assert(proxy_client:send {
            method = "GET",
            path   = "/z/y/x/get",
          })

          body = assert.res_status(200, res_uri_2)
          json = cjson.decode(body)
          assert.matches("/get", json.url, nil, true)
          assert.not_matches("/z/y/x/get", json.url, nil, true)

          local res_2_uri_1 = assert(proxy_client:send {
            method = "GET",
            path   = "/x/y/z/get",
          })

          body = assert.res_status(200, res_2_uri_1)
          json = cjson.decode(body)
          assert.matches("/get", json.url, nil, true)
          assert.not_matches("/x/y/z/get", json.url, nil, true)

          local res_2_uri_2 = assert(proxy_client:send {
            method = "GET",
            path   = "/x/y/z/get",
          })

          body = assert.res_status(200, res_2_uri_2)
          json = cjson.decode(body)
          assert.matches("/get", json.url, nil, true)
          assert.not_matches("/x/y/z/get", json.url, nil, true)
        end)
      end)
    end)

    describe("preserve_host", function()
      local routes

      lazy_setup(function()
        routes = insert_routes(bp, {
          {
            preserve_host = true,
            hosts         = { "preserved.com", "preserved.com:123" },
            service       = {
              path        = "/request"
            },
          },
          {
            preserve_host = false,
            hosts         = { "discarded.com" },
            service       = {
              path        = "/request"
            },
          },
          {
            strip_path    = false,
            preserve_host = true,
            paths         = { "/request" },
          }
        })

      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      describe("x = false (default)", function()
        it("uses hostname from upstream_url", function()
          local res = assert(proxy_client:send {
            method  = "GET",
            path    = "/get",
            headers = { ["Host"] = "discarded.com" },
          })

          local body = assert.res_status(200, res)
          local json = cjson.decode(body)
          assert.matches(helpers.mock_upstream_host,
                         json.headers.host, nil, true) -- not testing :port
        end)

        it("uses port value from upstream_url if not default", function()
          local res = assert(proxy_client:send {
            method  = "GET",
            path    = "/get",
            headers = { ["Host"] = "discarded.com" },
          })

          local body = assert.res_status(200, res)
          local json = cjson.decode(body)
          assert.matches(":" .. helpers.mock_upstream_port,
                          json.headers.host, nil, true) -- not testing hostname
        end)
      end)

      describe("= true", function()
        it("forwards request Host", function()
          local res = assert(proxy_client:send {
            method  = "GET",
            path    = "/",
            headers = { ["Host"] = "preserved.com" },
          })

          local body = assert.res_status(200, res)
          local json = cjson.decode(body)
          assert.equal("preserved.com", json.headers.host)
        end)

        it_trad_only("forwards request Host:Port even if port is default", function()
          local res = assert(proxy_client:send {
            method  = "GET",
            path    = "/get",
            headers = { ["Host"] = "preserved.com:80" },
          })

          local body = assert.res_status(200, res)
          local json = cjson.decode(body)
          assert.equal("preserved.com:80", json.headers.host)
        end)

        it("forwards request Host:Port if port isn't default", function()
          local res = assert(proxy_client:send {
            method  = "GET",
            path    = "/get",
            headers = { ["Host"] = "preserved.com:123" },
          })

          local body = assert.res_status(200, res)
          local json = cjson.decode(body)
          assert.equal("preserved.com:123", json.headers.host)
        end)

        it("forwards request Host even if not matched by [hosts]", function()
          local res = assert(proxy_client:send {
            method  = "GET",
            path    = "/get",
            headers = { ["Host"] = "preserved.com" },
          })

          local body = assert.res_status(200, res)
          local json = cjson.decode(body)
          assert.equal("preserved.com", json.headers.host)
        end)
      end)
    end)

    describe("edge-cases", function()
      local routes

      lazy_setup(function()
        routes = insert_routes(bp, {
          {
            strip_path = true,
            paths      = { "/" },
          },
          {
            strip_path = true,
            paths      = { "/foobar" },
          },
        })
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      it("root / [uri] for a catch-all rule", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/get",
          headers = { ["kong-debug"] = 1 }
        })

        assert.response(res).has_status(200)

        assert.equal(routes[1].id,           res.headers["kong-route-id"])
        assert.equal(routes[1].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[1].service.name, res.headers["kong-service-name"])

        res = assert(proxy_client:send {
          method  = "GET",
          path    = "/foobar/get",
          headers = { ["kong-debug"] = 1 }
        })

        assert.response(res).has_status(200)

        assert.equal(routes[2].id,           res.headers["kong-route-id"])
        assert.equal(routes[2].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[2].service.name, res.headers["kong-service-name"])
      end)
    end)

    describe("[snis] for HTTPs connections", function()
      local routes
      local proxy_ssl_client

      lazy_setup(function()
        routes = insert_routes(bp, {
          {
            protocols = { "https" },
            snis = { "www.example.org" },
            service = {
              name = "service_behind_www.example.org"
            },
          },
          {
            protocols = { "https" },
            snis = { "example.org" },
            service = {
              name = "service_behind_example.org"
            },
          },
        })
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      after_each(function()
        if proxy_ssl_client then
          proxy_ssl_client:close()
        end
      end)

      it("matches a Route based on its 'snis' attribute", function()
        proxy_ssl_client = helpers.proxy_ssl_client(nil, "www.example.org")

        local res = assert(proxy_ssl_client:send {
          method  = "GET",
          path    = "/status/200",
          headers = { ["kong-debug"] = 1 },
        })
        assert.res_status(200, res)
        assert.equal("service_behind_www.example.org",
                     res.headers["kong-service-name"])

        res = assert(proxy_ssl_client:send {
          method  = "GET",
          path    = "/status/201",
          headers = { ["kong-debug"] = 1 },
        })
        assert.res_status(201, res)
        assert.equal("service_behind_www.example.org",
                     res.headers["kong-service-name"])

        proxy_ssl_client:close()

        proxy_ssl_client = helpers.proxy_ssl_client(nil, "example.org")

        local res = assert(proxy_ssl_client:send {
          method  = "GET",
          path    = "/status/200",
          headers = { ["kong-debug"] = 1 },
        })
        assert.res_status(200, res)
        assert.equal("service_behind_example.org",
                     res.headers["kong-service-name"])

        res = assert(proxy_ssl_client:send {
          method  = "GET",
          path    = "/status/201",
          headers = { ["kong-debug"] = 1 },
        })
        assert.res_status(201, res)
        assert.equal("service_behind_example.org",
                     res.headers["kong-service-name"])
      end)
    end)

    describe("tls_passthrough", function()
      local routes
      local proxy_ssl_client

      lazy_setup(function()
        routes = insert_routes(bp, {
          {
            protocols = { "tls_passthrough" },
            snis = { "www.example.org" },
            service = {
              name = "service_behind_www.example.org",
              host = helpers.mock_upstream_ssl_host,
              port = helpers.mock_upstream_ssl_port,
              protocol = "tcp",
            },
          },
          {
            protocols = { "tls_passthrough" },
            snis = { "example.org" },
            service = {
              name = "service_behind_example.org",
              host = helpers.mock_upstream_ssl_host,
              port = helpers.mock_upstream_ssl_port,
              protocol = "tcp",
            },
          },
        })
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      after_each(function()
        if proxy_ssl_client then
          proxy_ssl_client:close()
        end
      end)

      it_trad_only("matches a Route based on its 'snis' attribute", function()
        -- config propogates to stream subsystems not instantly
        -- try up to 10 seconds with step of 2 seconds
        -- in vagrant it takes around 6 seconds
        helpers.wait_until(function()
          proxy_ssl_client = helpers.http_client("127.0.0.1", stream_tls_listen_port)
          local ok = proxy_ssl_client:ssl_handshake(nil, "www.example.org", false) -- explicit no-verify
          if not ok then
            proxy_ssl_client:close()
            return false
          end
          return true
        end, 10, 2)

        local res = assert(proxy_ssl_client:send {
          method  = "GET",
          path    = "/status/200",
          headers = { ["kong-debug"] = 1 },
        })
        assert.res_status(200, res)

        res = assert(proxy_ssl_client:send {
          method  = "GET",
          path    = "/status/201",
          headers = { ["kong-debug"] = 1 },
        })
        assert.res_status(201, res)

        proxy_ssl_client:close()

        proxy_ssl_client = helpers.http_client("127.0.0.1", stream_tls_listen_port)
        assert(proxy_ssl_client:ssl_handshake(nil, "example.org", false)) -- explicit no-verify

        local res = assert(proxy_ssl_client:send {
          method  = "GET",
          path    = "/status/200",
          headers = { ["kong-debug"] = 1 },
        })
        assert.res_status(200, res)

        res = assert(proxy_ssl_client:send {
          method  = "GET",
          path    = "/status/201",
          headers = { ["kong-debug"] = 1 },
        })
        assert.res_status(201, res)

        proxy_ssl_client:close()
      end)
    end)

    describe("[#headers]", function()
      local routes

      after_each(function()
        remove_routes(strategy, routes)
      end)

      it("matches by header", function()
        routes = insert_routes(bp, {
          {
            headers = { version = { "v1", "v2" } },
          },
          {
            headers = { version = { "v3" } },
          },
        })

        local res
        helpers.wait_until(function()
          res = assert(proxy_client:send {
            method  = "GET",
            path    = "/",
            headers = {
              ["Host"]       = "domain.org",
              ["version"]    = "v1",
              ["kong-debug"] = 1,
            }
          })
          return pcall(function()
            assert.res_status(200, res)
          end)
        end, 10)

        assert.equal(routes[1].id,           res.headers["kong-route-id"])
        assert.equal(routes[1].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[1].service.name, res.headers["kong-service-name"])

        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/",
          headers = {
            ["Host"]       = "domain.org",
            ["version"]    = "v3",
            ["kong-debug"] = 1,
          }
        })

        assert.res_status(200, res)

        assert.equal(routes[2].id,           res.headers["kong-route-id"])
        assert.equal(routes[2].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[2].service.name, res.headers["kong-service-name"])
      end)

      it("matches headers in a case-insensitive way", function()
        routes = insert_routes(bp, {
          {
            headers = { Version = { "v1", "v2" } },
          },
          {
            headers = { version = { "V3" } },
          },
        })

        local res
        helpers.wait_until(function()
          res = assert(proxy_client:send {
            method  = "GET",
            path    = "/",
            headers = {
              ["Host"]       = "domain.org",
              ["version"]    = "v1",
              ["kong-debug"] = 1,
            }
          })

          return pcall(function()
            assert.res_status(200, res)
            assert.equal(routes[1].id, res.headers["kong-route-id"])
          end)
        end, 10)

        assert.res_status(200, res)

        assert.equal(routes[1].id,           res.headers["kong-route-id"])
        assert.equal(routes[1].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[1].service.name, res.headers["kong-service-name"])

        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/",
          headers = {
            ["Host"]       = "domain.org",
            ["Version"]    = "v3",
            ["kong-debug"] = 1,
          }
        })

        assert.res_status(200, res)

        assert.equal(routes[2].id,           res.headers["kong-route-id"])
        assert.equal(routes[2].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[2].service.name, res.headers["kong-service-name"])
      end)

      it("prioritizes Routes with more headers", function()
        routes = insert_routes(bp, {
          {
            headers = {
              version = { "v1", "v2" },
            },
          },
          {
            headers = {
              version = { "v3" },
              location = { "us-east" },
            },
          },
          {
            headers = {
              version = { "v3" },
            },
          },
        })

        local res
        helpers.wait_until(function()
          res = assert(proxy_client:send {
            method  = "GET",
            path    = "/",
            headers = {
              ["Host"]       = "domain.org",
              ["version"]    = "v3",
              ["location"]   = "us-east",
              ["kong-debug"] = 1,
            }
          })
          return res.headers["kong-route-id"] == routes[2].id
        end, 5)

        assert.res_status(200, res)

        assert.equal(routes[2].id,           res.headers["kong-route-id"])
        assert.equal(routes[2].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[2].service.name, res.headers["kong-service-name"])

        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/",
          headers = {
            ["Host"]       = "domain.org",
            ["version"]    = "v3",
            ["kong-debug"] = 1,
          }
        })

        assert.res_status(200, res)

        assert.equal(routes[3].id,           res.headers["kong-route-id"])
        assert.equal(routes[3].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[3].service.name, res.headers["kong-service-name"])
      end)

      it("caching do not ignore headers (regression)", function()
        routes = insert_routes(bp, {
          {
            service    = {
              name     = "first",
            },
            hosts      = { "example.test" },
            paths      = { "/test" },
            headers    = { headertest = { "itsatest" } },
          },
          {
            service    = {
              name     = "second",
            },
            hosts      = { "example.test" },
            paths      = { "/test" },
          },
        })

        local res
        helpers.wait_until(function()
          res = assert(proxy_client:send {
            method  = "GET",
            path    = routes[1].paths[1],
            headers = {
              ["Host"]       = routes[1].hosts[1],
              ["headertest"] = "itsatest",
              ["kong-debug"] = 1,
            }
          })
          return pcall(function()
            assert.res_status(200, res)
          end)
        end, 10)

        assert.equal(routes[1].id,           res.headers["kong-route-id"])
        assert.equal(routes[1].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[1].service.name, res.headers["kong-service-name"])

        local res = assert(proxy_client:send {
          method  = "GET",
          path    = routes[2].paths[1],
          headers = {
            ["Host"]       = routes[2].hosts[1],
            ["kong-debug"] = 1,
          }
        })

        assert.res_status(200, res)
        assert.equal(routes[2].id,           res.headers["kong-route-id"])
        assert.equal(routes[2].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[2].service.name, res.headers["kong-service-name"])

        local res = assert(proxy_client:send {
          method  = "GET",
          path    = routes[1].paths[1],
          headers = {
            ["Host"]       = routes[1].hosts[1],
            ["headertest"] = "itsatest",
            ["kong-debug"] = 1,
          }
        })

        assert.res_status(200, res)
        assert.equal(routes[1].id,           res.headers["kong-route-id"])
        assert.equal(routes[1].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[1].service.name, res.headers["kong-service-name"])

      end)
    end)

    describe("[paths] + [#headers]", function()
      local routes

      lazy_setup(function()
        routes = insert_routes(bp, {
          {
            strip_path = true,
            headers = {
              version = { "v1", "v2" },
            },
            paths = { "/root" },
          },
          {
            strip_path = true,
            headers = {
              version = { "v1", "v2" },
            },
            paths = { "/root/fixture" },
          },
          {
            strip_path = true,
            headers = {
              version = { "v1", "v2" },
              location = { "us-east" },
            },
            paths = { "/root" },
          },
        })
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      it("prioritizes Routes with more headers", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/root/fixture/get",
          headers = {
            ["version"]    = "v2",
            ["location"]   = "us-east",
            ["kong-debug"] = 1,
          }
        })

        assert.res_status(404, res)

        assert.equal(routes[3].id,           res.headers["kong-route-id"])
        assert.equal(routes[3].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[3].service.name, res.headers["kong-service-name"])
      end)

      it("prioritizes longer paths if same number of headers", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/root/fixture/get",
          headers = {
            ["version"]    = "v2",
            ["kong-debug"] = 1,
          }
        })

        assert.res_status(200, res)

        assert.equal(routes[2].id,           res.headers["kong-route-id"])
        assert.equal(routes[2].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[2].service.name, res.headers["kong-service-name"])
      end)
    end)

    if not enable_buffering then
    describe("[snis] for #grpcs connections", function()
      local routes
      local grpcs_proxy_ssl_client

      lazy_setup(function()
        routes = insert_routes(bp, {
          {
            protocols = { "grpcs" },
            snis = { "grpcs_1.test" },
            service = {
              name = "grpcs_1",
              url = helpers.grpcbin_ssl_url,
            },
          },
          {
            protocols = { "grpcs" },
            snis = { "grpcs_2.test" },
            service = {
              name = "grpcs_2",
              url = helpers.grpcbin_ssl_url,
            },
          },
        })
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      it("matches a Route based on its 'snis' attribute", function()
        grpcs_proxy_ssl_client = helpers.proxy_client_grpcs("grpcs_1.test")

        local ok, resp = assert(grpcs_proxy_ssl_client({
          service = "hello.HelloService.SayHello",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-H"] = "'kong-debug: 1'",
            ["-v"] = true, -- verbose so we get response headers
          }
        }))
        assert.truthy(ok)
        assert.truthy(resp)
        assert.matches("kong-service-name: grpcs_1", resp, nil, true)

        grpcs_proxy_ssl_client = helpers.proxy_client_grpcs("grpcs_2.test")
        local ok, resp = assert(grpcs_proxy_ssl_client({
          service = "hello.HelloService.SayHello",
          body = {
            greeting = "world!"
          },
          opts = {
            ["-H"] = "'kong-debug: 1'",
            ["-v"] = true, -- verbose so we get response headers
          }
        }))
        assert.truthy(ok)
        assert.truthy(resp)
        assert.matches("kong-service-name: grpcs_2", resp, nil, true)
      end)
    end)
    end -- not enable_buffering

    describe("[paths] + [methods]", function()
      local routes

      lazy_setup(function()
        routes = insert_routes(bp, {
          [1] = {
            strip_path = true,
            methods    = { "GET" },
            paths      = { "/unrelated/longer/uri/that/should/not/match", "/root/fixture" },
            hosts      = { "ahost.test" },
            service    = { path = "/status/201" },
          },
          [2] = {
            strip_path = true,
            methods    = { "GET" },
            paths      = { "/root/fixture/get" },
            hosts      = { "ahost.test" },
            service    = { path = "/status/202" },
          },
          [3] = {
            strip_path = true,
            methods    = { "GET" },
            paths      = { "/root/fixture/get" },
            hosts      = { "anotherhost.test" },
            service    = { path = "/status/203" },
          },
          [4] = {
            strip_path = true,
            methods    = { "GET" },
            paths      = { "/root/fixture/get" },
            hosts      = { "onemorehost.test" },
            service    = { path = "/status/204" },
          },

          [5] = {
            strip_path = true,
            name       = "public-apiv1",
            paths      = { "/rest/devportal/api/v1", "/rest/devportal" },
            hosts      = { "api.local" },
            service    = { path = "/status/205" },
          },
          [6] = {
            strip_path = true,
            name       = "aux",
            paths      = { "/rest/devportal/aux" },
            hosts      = { "api.local" },
            service    = { path = "/status/206" },
          },
          [7] = {
            strip_path = true,
            name       = "aux-host",
            paths      = { "/rest/devportal/aux" },
            hosts      = { "test-api.local" },
            service    = { path = "/status/207" },
          },
          [8] = {
            strip_path = true,
            name       = "aux-host2",
            paths      = { "/rest/devportal/aux" },
            hosts      = { "atest-api.local" },
            service    = { path = "/status/208" },
          },
          [9] = {
            strip_path = true,
            name       = "devportal-route-2",
            paths      = { "/rest/devportal" },
            hosts      = { "atest-api.local" },
            service    = { path = "/status/209" },
          },

          [10] = {
            strip_path = true,
            name       = "concat_test-public-apiv1",
            paths      = { "/concat_test/devportal/api/v1", "/concat_test/devportal" },
            hosts      = { "api.local" },
          },
          [11] = {
            strip_path = true,
            name       = "concat_test-aux",
            paths      = { "/concat_test/devportal/aux" },
            hosts      = { "api.local" },
          },
          [12] = {
            strip_path = true,
            name       = "concat_test-aux-host",
            paths      = { "/concat_test/devportal/aux" },
            hosts      = { "test-api.local" },
          },
          [13] = {
            strip_path = true,
            name       = "concat_test-aux-host2",
            paths      = { "/concat_test/devportal/aux" },
            hosts      = { "atest-api.local" },
          },
          [14] = {
            strip_path = true,
            name       = "concat_test-devportal-route-2",
            paths      = { "/concat_test/devportal" },
            hosts      = { "atest-api.local" },
          },

        })
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      it_trad_only("regression test for #5438", function()
        for i = 1, 9 do
          for j = 1, #routes[i].paths do
            local res = assert(proxy_client:send {
              method  = "GET",
              path    = routes[i].paths[j],
              headers = {
                ["kong-debug"] = 1,
                ["host"] = routes[i].hosts[1],
              }
            })

            assert.res_status(200 + i, res)

            assert.equal(routes[i].id,           res.headers["kong-route-id"])
            assert.equal(routes[i].service.id,   res.headers["kong-service-id"])
            assert.equal(routes[i].service.name, res.headers["kong-service-name"])

          end
        end
      end)

      it_trad_only("regression test for #5438 concatenating paths", function()
        for i = 10, 14 do
          for j = 1, #routes[i].paths do
            local res = assert(proxy_client:send {
              method  = "GET",
              path    = routes[i].paths[j] .. "/status/418",
              headers = {
                ["kong-debug"] = 1,
                ["host"] = routes[i].hosts[1],
              }
            })

            assert.res_status(418, res)

            assert.equal(routes[i].id,           res.headers["kong-route-id"])
            assert.equal(routes[i].service.id,   res.headers["kong-service-id"])
            assert.equal(routes[i].service.name, res.headers["kong-service-name"])

          end
        end
      end)

      it_trad_only("regression test for #5438 part 2", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/rest/devportal",
          headers = {
            ["kong-debug"] = 1,
            ["host"] = "atest-api.local",
          }
        })

        assert.res_status(209, res)

        assert.equal(routes[9].id,           res.headers["kong-route-id"])
        assert.equal(routes[9].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[9].service.name, res.headers["kong-service-name"])
      end)

      it_trad_only("prioritizes longer URIs", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/root/fixture/get",
          headers = {
            ["kong-debug"] = 1,
            ["host"] = "ahost.test",
          }
        })

        assert.res_status(202, res)

        assert.equal(routes[2].id,           res.headers["kong-route-id"])
        assert.equal(routes[2].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[2].service.name, res.headers["kong-service-name"])
      end)

      it("prioritizes host over longer URIs", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/root/fixture/get",
          headers = {
            ["kong-debug"] = 1,
            ["host"] = "anotherhost.test",
          }
        })

        assert.res_status(203, res)

        assert.equal(routes[3].id,           res.headers["kong-route-id"])
        assert.equal(routes[3].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[3].service.name, res.headers["kong-service-name"])
      end)

      it("do not match incomplete URIs", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/",
          headers = {
            ["kong-debug"] = 1,
            ["host"] = "ahost.test",
          }
        })

        assert.res_status(404, res)
      end)
    end)

    describe("[paths] + [hosts]", function()
      local routes

      lazy_setup(function()
        routes = insert_routes(bp, {
          {
            strip_path = true,
            hosts      = { "route.com" },
            paths      = { "/root/fixture", "/root/fixture/non-matching-but-longer" },
          },
          {
            strip_path = true,
            hosts      = { "route.com" },
            paths      = { "/root/fixture/get" },
          },
        })
      end)

      lazy_teardown(function()
        remove_routes(strategy, routes)
      end)

      it_trad_only("prioritizes longer URIs", function()
        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/root/fixture/get",
          headers = {
            ["Host"]       = "route.com",
            ["kong-debug"] = 1,
          }
        })

        assert.res_status(200, res)

        assert.equal(routes[2].id,           res.headers["kong-route-id"])
        assert.equal(routes[2].service.id,   res.headers["kong-service-id"])
        assert.equal(routes[2].service.name, res.headers["kong-service-name"])
      end)
    end)

    describe("slash handling", function()
      describe("(plain)", function()
        local routes

        lazy_setup(function()
          routes = {}

          for i, line in ipairs(path_handling_tests) do
            for j, test in ipairs(line:expand()) do
              if flavor == "traditional" or test.path_handling == "v0" then
                routes[#routes + 1] = {
                  strip_path   = test.strip_path,
                  path_handling = test.path_handling,
                  paths        = test.route_path and { test.route_path } or nil,
                  hosts        = { "localbin-" .. i .. "-" .. j .. ".com" },
                  service = {
                    name = "plain_" .. i .. "-" .. j,
                    path = test.service_path,
                  }
                }
              end
            end
          end

          routes = insert_routes(bp, routes)
        end)

        lazy_teardown(function()
          for _, r in ipairs(routes) do
            remove_routes(strategy, r)
          end
        end)

        for i, line in ipairs(path_handling_tests) do
          for j, test in ipairs(line:expand()) do
            if flavor == "traditional" or test.path_handling == "v0" then
              local strip = test.strip_path and "on" or "off"
              local route_uri_or_host
              if test.route_path then
                route_uri_or_host = "uri " .. test.route_path
              else
                route_uri_or_host = "host localbin-" .. i .. "-" .. j .. ".com"
              end

              local description = string.format("(%d-%d) %s with %s, strip = %s, %s when requesting %s",
                i, j, test.service_path, route_uri_or_host, strip, test.path_handling, test.request_path)

              it(description, function()
                helpers.wait_until(function()
                  local res = assert(proxy_client:get(test.request_path, {
                    headers = {
                      ["Host"] = "localbin-" .. i .. "-" .. j .. ".com",
                    }
                  }))

                  return pcall(function()
                    local data = assert.response(res).has.jsonbody()
                    assert.equal(test.expected_path, data.vars.request_uri)
                  end)
                end, 10)
              end)
            end
          end
        end
      end)

      describe("(regex)", function()
        local function make_a_regex(path)
          return "~/[0]?" .. path:sub(2, -1)
        end

        local routes

        lazy_setup(function()
          routes = {}

          for i, line in ipairs(path_handling_tests) do
            if line.route_path then  -- skip if hostbased match
              for j, test in ipairs(line:expand()) do
                if flavor == "traditional" or test.path_handling == "v0" then
                  routes[#routes + 1] = {
                    strip_path   = test.strip_path,
                    paths        = test.route_path and { make_a_regex(test.route_path) } or nil,
                    path_handling = test.path_handling,
                    hosts        = { "localbin-" .. i .. "-" .. j .. ".com" },
                    service = {
                      name = "make_regex_" .. i .. "-" .. j,
                      path = test.service_path,
                    }
                  }
                end
              end
            end
          end

          routes = insert_routes(bp, routes)
        end)

        lazy_teardown(function()
          remove_routes(strategy, routes)
        end)

        for i, line in ipairs(path_handling_tests) do
          if line.route_path then  -- skip if hostbased match
            for j, test in ipairs(line:expand()) do
              if flavor == "traditional" or test.path_handling == "v0" then
                local strip = test.strip_path and "on" or "off"

                local description = string.format("(%d-%d) %s with uri %s, strip = %s, %s when requesting %s",
                  i, j, test.service_path, make_a_regex(test.route_path), strip, test.path_handling, test.request_path)

                it(description, function()
                  local res = assert(proxy_client:get(test.request_path, {
                    headers = { Host = "localbin-" .. i .. "-" .. j .. ".com" },
                  }))

                  local data = assert.response(res).has.jsonbody()
                  assert.truthy(data.vars)
                  assert.equal(test.expected_path, data.vars.request_uri)
                end)
              end
            end
          end
        end
      end)

      describe("router rebuilds", function()
        local routes

        lazy_teardown(function()
          remove_routes(routes)
        end)

        it("when Routes have 'regex_priority = nil'", function()
          -- Regression test for issue:
          -- https://github.com/Kong/kong/issues/4254
          routes = insert_routes(bp, {
            {
              methods = { "GET" },
              regex_priority = 1,
            },
            {
              methods = { "POST", "PUT" },
              regex_priority = ngx.null,
            },
          })

          local res = assert(proxy_client:send {
            method  = "GET",
          })

          assert.response(res).has_status(200)
        end)
      end)
    end)
  end)

  for _, consistency in ipairs({ "strict", "eventual" }) do
    describe("Router [#" .. strategy .. ", flavor = " .. flavor ..
      ", consistency = " .. consistency .. "] at startup" , function()
      local proxy_client
      local route

      lazy_setup(function()
        local bp = helpers.get_db_utils(strategy, {
          "routes",
          "services",
          "plugins",
        }, {
          "enable-buffering",
        })

        route = bp.routes:insert({
          methods    = { "GET" },
          protocols  = { "http" },
          strip_path = false,
        })

        if enable_buffering then
          bp.plugins:insert {
            name = "enable-buffering",
            protocols = { "http", "https", "grpc", "grpcs" },
          }
        end

        assert(helpers.start_kong({
          router_flavor = flavor,
          worker_consistency = consistency,
          database = strategy,
          nginx_worker_processes = 4,
          plugins = "bundled,enable-buffering",
          nginx_conf = "spec/fixtures/custom_nginx.template",
        }))
      end)

      lazy_teardown(function()
        helpers.stop_kong()
      end)

      before_each(function()
        proxy_client = helpers.proxy_client()
      end)

      after_each(function()
        if proxy_client then
          proxy_client:close()
        end
      end)

      it("uses configuration from datastore or declarative_config", function()
        for _ = 1, 1000 do
          proxy_client = helpers.proxy_client()
          local res = assert(proxy_client:send {
            method  = "GET",
            path    = "/get",
            headers = { ["kong-debug"] = 1 },
          })

          assert.response(res).has_status(200)

          assert.equal(route.service.name, res.headers["kong-service-name"])
          proxy_client:close()
        end
      end)

      it("#db worker respawn correctly rebuilds router", function()
        local admin_client = helpers.admin_client()

        local res = assert(admin_client:post("/routes", {
          headers = { ["Content-Type"] = "application/json" },
          body = {
            paths = { "/foo" },
          },
        }))
        assert.res_status(201, res)
        admin_client:close()

        local workers_before = helpers.get_kong_workers()
        assert(helpers.signal_workers(nil, "-TERM"))
        helpers.wait_until_no_common_workers(workers_before, 1) -- respawned

        proxy_client:close()
        proxy_client = helpers.proxy_client()

        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/foo",
          headers = { ["kong-debug"] = 1 },
        })

        local body = assert.response(res).has_status(503)
        local json = cjson.decode(body)
        assert.equal("no Service found with those values", json.message)
      end)

      it("#db rebuilds router correctly after passing invalid route", function()
        local admin_client = helpers.admin_client()

        local res = assert(admin_client:post("/routes", {
          headers = { ["Content-Type"] = "application/json" },
          body = {
            -- this is a invalid regex path
            paths = { "~/delay/(?<delay>[^\\/]+)$", },
          },
        }))
        assert.res_status(201, res)

        helpers.wait_for_all_config_update()

        local res = assert(admin_client:post("/routes", {
          headers = { ["Content-Type"] = "application/json" },
          body = {
            paths = { "/foo" },
          },
        }))
        assert.res_status(201, res)

        admin_client:close()

        helpers.wait_for_all_config_update()

        proxy_client:close()
        proxy_client = helpers.proxy_client()

        local res = assert(proxy_client:send {
          method  = "GET",
          path    = "/foo",
          headers = { ["kong-debug"] = 1 },
        })

        local body = assert.response(res).has_status(503)
        local json = cjson.decode(body)
        assert.equal("no Service found with those values", json.message)
      end)
    end)
  end
end
end
end


text:
import {Page, NavController} from 'ionic-angular';
import {DisplayTools} from '../../comon/display';
import {Geolocation} from 'ionic-native';
import {LaunchNavigator} from 'ionic-native';

/*
  Generated class for the MotionPage page.

  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/
@Page({
  templateUrl: 'build/pages/device/geolocation/geolocation.html',
  providers: [DisplayTools]
})
export class geolocationPage {
  display: DisplayTools;
  geo: any;
  options:any;
  subscription: any;
  pluginOk: boolean;
  record: boolean;
  constructor(public nav: NavController, display: DisplayTools) {
    this.display = display;
    this.geo=null;
    this.options={ maximumAge: 3000, timeout: 5000, enableHighAccuracy: true };
    this.pluginOk=false;
    this.record=false;
    this.getCurrent();
  }
  getCurrent() {
    let loading = this.display.displayLoading("Géolocalisation en cours...");
    Geolocation.getCurrentPosition(this.options).then((resp) => {
      console.log(resp);
      this.geo = resp;
      this.pluginOk=true;
      loading.dismiss();
    }, error => {
      this.pluginOk=false;
      this.display.displayAlert("Geolocalisation indisponible : "+JSON.stringify(error));
      loading.dismiss();
    });
  }
  startWatch() {
    this.subscription = Geolocation.watchPosition(this.options).subscribe(position => {
      this.record=true;
      console.log(position);
      this.geo = position;
    });
  }
  stopWatch() {
    // To stop notifications
    this.record=false;
    this.subscription.unsubscribe();
  }
  goDest(geo){
    let position=[geo.coords.latitude,geo.coords.longitude];
    LaunchNavigator.navigate(position).then(
    success => console.log("Launched navigator"),
    error => this.display.displayAlert("Error launching navigator : "+JSON.stringify(error))
  );
  }
}


text:
typedef unsigned long grammar;
typedef unsigned char byte;

#define GRAMMAR_PORT_INCLUDE 1
#include "grammar.h"
#undef GRAMMAR_PORT_INCLUDE

#endif


text:
using System;
using System.Collections.Generic;

namespace Mozu.Api.Contracts.ProductAdmin
{
		///
		///	Mozu.ProductAdmin.Contracts.ProductImageGroup ApiType DOCUMENT_HERE
		///
		public class ProductImageGroup
		{
			///
			///productImageGroupId ApiType DOCUMENT_HERE
			///
			public string ProductImageGroupId { get; set; }

			///
			///productImageGroupTags ApiType DOCUMENT_HERE
			///
			public List<ProductImageGroupTag> ProductImageGroupTags { get; set; }

		}

}


text:
package co.nstant.in.cbor.examples;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import org.junit.Assert;
import org.junit.Test;

import co.nstant.in.cbor.CborDecoder;
import co.nstant.in.cbor.CborEncoder;
import co.nstant.in.cbor.CborException;
import co.nstant.in.cbor.model.DataItem;
import co.nstant.in.cbor.model.SimpleValue;

/**
 * undefined -> 0xf7
 */
public class Example44Test {

    private static final byte[] ENCODED_VALUE = new byte[] { (byte) 0xf7 };

    @Test
    public void shouldEncode() throws CborException {
        ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
        CborEncoder encoder = new CborEncoder(byteOutputStream);
        encoder.encode(SimpleValue.UNDEFINED);
        Assert.assertArrayEquals(ENCODED_VALUE, byteOutputStream.toByteArray());
    }

    @Test
    public void shouldDecode() throws CborException {
        InputStream inputStream = new ByteArrayInputStream(ENCODED_VALUE);
        CborDecoder decoder = new CborDecoder(inputStream);
        DataItem dataItem = decoder.decodeNext();
        Assert.assertTrue(dataItem instanceof SimpleValue);
        SimpleValue simpleValue = (SimpleValue) dataItem;
        Assert.assertEquals(SimpleValue.UNDEFINED, simpleValue);
    }

}


text:
package org.springframework.security.integration.multiannotation;

import org.springframework.security.access.annotation.Secured;

/**
 *
 * @author Luke Taylor
 */
public interface SecuredService {
	@Secured("ROLE_A")
	void securedMethod();
}