作者小头像 Lv.1
0 成长值

个人介绍

这个人很懒,什么都没有留下

感兴趣或擅长的领域

暂无数据
个人勋章
TA还没获得勋章~
成长雷达
0
0
0
0
0

个人资料

个人介绍

这个人很懒,什么都没有留下

感兴趣或擅长的领域

暂无数据

达成规则

发布时间 2020/04/06 16:52:51 最后回复 China_RKD 2020/04/06 17:01:02 版块 微服务引擎
2569 1 0
他的回复:
可以在 edge 加一个 HttpClientFilter ```java /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.commons.lang3.StringUtils; import org.apache.servicecomb.common.rest.filter.HttpClientFilter; import org.apache.servicecomb.core.Invocation; import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx; import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx; import org.apache.servicecomb.swagger.invocation.Response; import java.util.Arrays; import java.util.List; public class EdgeAddHeader implements HttpClientFilter { private static final List HEADER_KEY = Arrays.asList("header", "test", "User-Agent"); @Override public int getOrder() { return 0; } @Override public void beforeSendRequest(Invocation invocation, HttpServletRequestEx requestEx) { HttpServletRequestEx oldRequest = invocation.getRequestEx(); HEADER_KEY.forEach(key -> { requestEx.addHeader(key, StringUtils.isEmpty(oldRequest.getHeader(key)) ? "default_header_xxx" : oldRequest.getHeader(key)); }); } @Override public Response afterReceiveResponse(Invocation invocation, HttpServletResponseEx responseEx) { return null; } } ```