package org.onetwo.cloud.core;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import lombok.Data;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * @author wayshall
 * <br/>
 */
@ConfigurationProperties(prefix=BootJfishCloudConfig.CONFIG_PREFIX)
@Data
public class BootJfishCloudConfig {
	
	public static final String CONFIG_PREFIX = "jfish.cloud"; 
	public static final String ZUUL_FIXHEADERS_ENABLED = CONFIG_PREFIX + ".zuul.endabledFixHeader";
	
	public static final String EUREKA_EMBEDDED_KEY = "jfish.cloud.eureka.embedded";
	
	public static final String HYSTRIX_SHARE_REQUEST_CONTEXT = "jfish.cloud.hystrix.shareRequestContext";
	
	ZuulConfig zuul = new ZuulConfig();
	
	@Data
	public class ZuulConfig {
		List<FixHeadersConfig> fixHeaders = new ArrayList<>();
	}

	@Data
	static public class FixHeadersConfig {
		List<String> pathPatterns;
		String header;
		String value;
		PathMatcher matcher = PathMatcher.ANT;
		Map<String, Pattern> patterns = null;
		
		public Map<String, Pattern> getPatterns(){
			Map<String, Pattern> patterns = this.patterns;
			if(patterns==null || patterns.isEmpty()){
				patterns = pathPatterns.stream().collect(Collectors.toMap(path->path, path->Pattern.compile(path)));
			}
			return patterns;
		}
	}
	
	public static enum PathMatcher {
		ANT,
		REGEX
	}
}

@@ -49,24 +49,54 @@
 .ArrayList;%0A
+import java.util.Collections;%0A
 import java.
@@ -201,29 +201,8 @@
 s;%0A%0A
-import lombok.Data;%0A%0A
 impo
@@ -274,16 +274,37 @@
 rties;%0A%0A
+import lombok.Data;%0A%0A
 /**%0A * @
@@ -1163,16 +1163,93 @@
 erns()%7B%0A
+%09%09%09if (matcher!=PathMatcher.REGEX) %7B%0A%09%09%09%09return Collections.emptyMap();%0A%09%09%09%7D%0A
 %09%09%09Map%3CS

fix zuul header