<commit_before>Feature: Request matching
	Incoming requests needs to be matched in flexible way and appropriate data needs to be available in form of variables used to parametrize processing.

	Background:
		Given httpthumbnailer server is running at http://localhost:3100/health_check
		Given httpimagestore server is running at http://localhost:3000/health_check with the following configuration
		"""
		# URI segment matchers
		get "string" {
			output_text "path: '#{path}'"
		}

		get "any" "default" ":test1" ":test2?foo" ":test3?bar" ":test4?baz" {
			output_text "test1: '#{test1}' test2: '#{test2}' test3: '#{test3}' test4: '#{test4}' path: '#{path}'"
		}
		get "any" ":test1" ":test2" {
			output_text "test1: '#{test1}' test2: '#{test2}' path: '#{path}'"
		}

		get "regexp1" ":test1/a.c/" ":test2/.*/" {
			output_text "test1: '#{test1}' test2: '#{test2}' path: '#{path}'"
		}
		get "regexp-404" ":test1/a.c.*/" ":test2/.*/" {
			output_text "test1: '#{test1}' test2: '#{test2}' path: '#{path}'"
		}

		get "regexp" "named" "/(?<test1>..)-(?<test2>..)/" ":test3/.*/" {
			output_text "test1: '#{test1}' test2: '#{test2}' test3: '#{test3}' path: '#{path}'"
		}
		get "regexp" "named" "bad1" "/(?<test1>..)-(?<test1>..)/" ":test3/.*/" {
			output_text "test1: '#{test1}' test2: '#{test2}' test3: '#{test3}' path: '#{path}'"
		}
		get "regexp" "named" "bad2" "/(?<test1>..)-(?<test1>..)/" ":test3/.*/" {
			output_text "test1: '#{test1}' test3: '#{test3}' path: '#{path}'"
		}

		# Query string matchers
		get "query" "key-value" "&hello=world" {
			output_text "query key-value matched path: '#{path}'"
		}

		get "query" "key" "default" "&:hello?abc" {
			output_text "key: '#{hello}' path: '#{path}'"
		}
		get "query" "key" "&:hello" {
			output_text "key: '#{hello}' path: '#{path}'"
		}
		"""

	@request-matching @string
	Scenario: Matching URI segment with strings
		When I do GET request http://localhost:3000/string/hello/world
		Then response status will be 200
		And response content type will be text/plain
		And response body will be CRLF ended lines
		"""
		path: 'hello/world'
		"""

	@request-matching @capture-any
	Scenario: Capturing any URI segment
		When I do GET request http://localhost:3000/any/foo/bar/hello/world
		Then response status will be 200
		And response content type will be text/plain
		And response body will be CRLF ended lines
		"""
		test1: 'foo' test2: 'bar' path: 'hello/world'
		"""

	@request-matching @capture-any-default
	Scenario: Capturing any URI segment with default value
		When I do GET request http://localhost:3000/any/default/foo/bar
		Then response status will be 200
		And response content type will be text/plain
		And response body will be CRLF ended lines
		"""
		test1: 'foo' test2: 'bar' test3: 'bar' test4: 'baz' path: ''
		"""

	@request-matching @capture-regexp
	Scenario: Capturing URI segment with regexp match
		When I do GET request http://localhost:3000/regexp1/abc/foobar/hello/world
		Then response status will be 200
		And response content type will be text/plain
		And response body will be CRLF ended lines
		"""
		test1: 'abc' test2: 'foobar/hello/world' path: ''
		"""
		When I do GET request http://localhost:3000/regexp2/abc/foobar/hello/world
		Then response status will be 404

	@request-matching @capture-named-regexp
	Scenario: Capturing URI segment with named regexp match
		When I do GET request http://localhost:3000/regexp/named/ab-12/hello/world
		Then response status will be 200
		And response content type will be text/plain
		And response body will be CRLF ended lines
		"""
		test1: 'ab' test2: '12' test3: 'hello/world' path: ''
		"""
		When I do GET request http://localhost:3000/regexp/named/ab-12
		Then response status will be 404<commit_msg>test for regexp without captures<commit_after>Feature: Request matching
	Incoming requests needs to be matched in flexible way and appropriate data needs to be available in form of variables used to parametrize processing.

	Background:
		Given httpthumbnailer server is running at http://localhost:3100/health_check
		Given httpimagestore server is running at http://localhost:3000/health_check with the following configuration
		"""
		# URI segment matchers
		get "string" {
			output_text "path: '#{path}'"
		}

		get "any" "default" ":test1" ":test2?foo" ":test3?bar" ":test4?baz" {
			output_text "test1: '#{test1}' test2: '#{test2}' test3: '#{test3}' test4: '#{test4}' path: '#{path}'"
		}
		get "any" ":test1" ":test2" {
			output_text "test1: '#{test1}' test2: '#{test2}' path: '#{path}'"
		}

		get "regexp1" ":test1/a.c/" ":test2/.*/" {
			output_text "test1: '#{test1}' test2: '#{test2}' path: '#{path}'"
		}
		get "regexp-404" ":test1/a.c.*/" ":test2/.*/" {
			output_text "test1: '#{test1}' test2: '#{test2}' path: '#{path}'"
		}

		get "regexp" "named" "/(?<test1>..)-(?<test2>..)/" ":test3/.*/" {
			output_text "test1: '#{test1}' test2: '#{test2}' test3: '#{test3}' path: '#{path}'"
		}
		get "regexp" "named" "nocapture" "/..-../" {
			output_text "path: '#{path}'"
		}
		get "regexp" "named" "bad1" "/(?<test1>..)-(?<test1>..)/" ":test3/.*/" {
			output_text "test1: '#{test1}' test2: '#{test2}' test3: '#{test3}' path: '#{path}'"
		}
		get "regexp" "named" "bad2" "/(?<test1>..)-(?<test1>..)/" ":test3/.*/" {
			output_text "test1: '#{test1}' test3: '#{test3}' path: '#{path}'"
		}

		# Query string matchers
		get "query" "key-value" "&hello=world" {
			output_text "query key-value matched path: '#{path}'"
		}

		get "query" "key" "default" "&:hello?abc" {
			output_text "key: '#{hello}' path: '#{path}'"
		}
		get "query" "key" "&:hello" {
			output_text "key: '#{hello}' path: '#{path}'"
		}
		"""

	@request-matching @string
	Scenario: Matching URI segment with strings
		When I do GET request http://localhost:3000/string/hello/world
		Then response status will be 200
		And response content type will be text/plain
		And response body will be CRLF ended lines
		"""
		path: 'hello/world'
		"""

	@request-matching @capture-any
	Scenario: Capturing any URI segment
		When I do GET request http://localhost:3000/any/foo/bar/hello/world
		Then response status will be 200
		And response content type will be text/plain
		And response body will be CRLF ended lines
		"""
		test1: 'foo' test2: 'bar' path: 'hello/world'
		"""

	@request-matching @capture-any-default
	Scenario: Capturing any URI segment with default value
		When I do GET request http://localhost:3000/any/default/foo/bar
		Then response status will be 200
		And response content type will be text/plain
		And response body will be CRLF ended lines
		"""
		test1: 'foo' test2: 'bar' test3: 'bar' test4: 'baz' path: ''
		"""

	@request-matching @capture-regexp
	Scenario: Capturing URI segment with regexp match
		When I do GET request http://localhost:3000/regexp1/abc/foobar/hello/world
		Then response status will be 200
		And response content type will be text/plain
		And response body will be CRLF ended lines
		"""
		test1: 'abc' test2: 'foobar/hello/world' path: ''
		"""
		When I do GET request http://localhost:3000/regexp2/abc/foobar/hello/world
		Then response status will be 404

	@request-matching @capture-named-regexp
	Scenario: Capturing URI segment with named regexp match
		When I do GET request http://localhost:3000/regexp/named/ab-12/hello/world
		Then response status will be 200
		And response content type will be text/plain
		And response body will be CRLF ended lines
		"""
		test1: 'ab' test2: '12' test3: 'hello/world' path: ''
		"""
		When I do GET request http://localhost:3000/regexp/named/nocapture/ab-12/hello/world
		Then response status will be 200
		And response content type will be text/plain
		And response body will be CRLF ended lines
		"""
		path: 'hello/world'
		"""
		When I do GET request http://localhost:3000/regexp/named/ab-12
		Then response status will be 404
{'fraction_non_alphanumeric': 0.162227602905569, 'fraction_numerical': 0.03606473811647763, 'mean_word_length': 3.895820336868372, 'pattern_counts': {'":': 26, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3809923', 'n_tokens_mistral': 3055, 'n_tokens_neox': 2690, 'n_words': 861}