mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-04 18:17:08 +08:00 
			
		
		
		
	headers: Fix Caddyfile parsing for request_header with matchers (#4085)
				
					
				
			This commit is contained in:
		
							
								
								
									
										90
									
								
								caddytest/integration/caddyfile_adapt/request_header.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								caddytest/integration/caddyfile_adapt/request_header.txt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,90 @@
 | 
				
			|||||||
 | 
					:80
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@matcher path /something*
 | 
				
			||||||
 | 
					request_header @matcher Denis "Ritchie"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					request_header +Edsger "Dijkstra"
 | 
				
			||||||
 | 
					request_header -Wolfram
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@images path /images/*
 | 
				
			||||||
 | 
					request_header @images Cache-Control "public, max-age=3600, stale-while-revalidate=86400"
 | 
				
			||||||
 | 
					----------
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						"apps": {
 | 
				
			||||||
 | 
							"http": {
 | 
				
			||||||
 | 
								"servers": {
 | 
				
			||||||
 | 
									"srv0": {
 | 
				
			||||||
 | 
										"listen": [
 | 
				
			||||||
 | 
											":80"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										"routes": [
 | 
				
			||||||
 | 
											{
 | 
				
			||||||
 | 
												"match": [
 | 
				
			||||||
 | 
													{
 | 
				
			||||||
 | 
														"path": [
 | 
				
			||||||
 | 
															"/something*"
 | 
				
			||||||
 | 
														]
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
												],
 | 
				
			||||||
 | 
												"handle": [
 | 
				
			||||||
 | 
													{
 | 
				
			||||||
 | 
														"handler": "headers",
 | 
				
			||||||
 | 
														"request": {
 | 
				
			||||||
 | 
															"set": {
 | 
				
			||||||
 | 
																"Denis": [
 | 
				
			||||||
 | 
																	"Ritchie"
 | 
				
			||||||
 | 
																]
 | 
				
			||||||
 | 
															}
 | 
				
			||||||
 | 
														}
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
 | 
											{
 | 
				
			||||||
 | 
												"match": [
 | 
				
			||||||
 | 
													{
 | 
				
			||||||
 | 
														"path": [
 | 
				
			||||||
 | 
															"/images/*"
 | 
				
			||||||
 | 
														]
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
												],
 | 
				
			||||||
 | 
												"handle": [
 | 
				
			||||||
 | 
													{
 | 
				
			||||||
 | 
														"handler": "headers",
 | 
				
			||||||
 | 
														"request": {
 | 
				
			||||||
 | 
															"set": {
 | 
				
			||||||
 | 
																"Cache-Control": [
 | 
				
			||||||
 | 
																	"public, max-age=3600, stale-while-revalidate=86400"
 | 
				
			||||||
 | 
																]
 | 
				
			||||||
 | 
															}
 | 
				
			||||||
 | 
														}
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
 | 
											{
 | 
				
			||||||
 | 
												"handle": [
 | 
				
			||||||
 | 
													{
 | 
				
			||||||
 | 
														"handler": "headers",
 | 
				
			||||||
 | 
														"request": {
 | 
				
			||||||
 | 
															"add": {
 | 
				
			||||||
 | 
																"Edsger": [
 | 
				
			||||||
 | 
																	"Dijkstra"
 | 
				
			||||||
 | 
																]
 | 
				
			||||||
 | 
															}
 | 
				
			||||||
 | 
														}
 | 
				
			||||||
 | 
													},
 | 
				
			||||||
 | 
													{
 | 
				
			||||||
 | 
														"handler": "headers",
 | 
				
			||||||
 | 
														"request": {
 | 
				
			||||||
 | 
															"delete": [
 | 
				
			||||||
 | 
																"Wolfram"
 | 
				
			||||||
 | 
															]
 | 
				
			||||||
 | 
														}
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -151,6 +151,10 @@ func parseCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
 | 
				
			|||||||
//     request_header [<matcher>] [[+|-]<field> [<value|regexp>] [<replacement>]]
 | 
					//     request_header [<matcher>] [[+|-]<field> [<value|regexp>] [<replacement>]]
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
func parseReqHdrCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) {
 | 
					func parseReqHdrCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) {
 | 
				
			||||||
 | 
						if !h.Next() {
 | 
				
			||||||
 | 
							return nil, h.ArgErr()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	matcherSet, err := h.ExtractMatcherSet()
 | 
						matcherSet, err := h.ExtractMatcherSet()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user