admin 管理员组文章数量: 1087139
2024年2月18日发(作者:指针直接赋值1024)
24252627282936373839464748495657585966import Utils;import ponentsBuilder;
/** * @author Spencer Gibb */public class AddRequestParameterGatewayFilterFactory extends AbstractNameValueGatewayFilterFactory {
@Override public GatewayFilter apply(NameValueConfig config) { return (exchange, chain) -> { URI uri = uest().getURI(); StringBuilder query = new StringBuilder(); String originalQuery = Query();
if (t(originalQuery)) { (originalQuery); if ((() - 1) != '&') { ('&'); } }
//TODO urlencode? (e()); ('='); (ue());
try { URI newUri = i(uri) .replaceQuery(ng()) .build(true) .toUri();
ServerHttpRequest request = uest().mutate().uri(newUri).build();
return (().request(request).build()); } catch (RuntimeException ex) { throw new IllegalStateException("Invalid URI query: "" + ng() + """); } }; }
}17/* * Copyright 2013-2018 the original author or authors. * * Licensed 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 * * /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. * */
8293637383946474849565758596667686976777879808182
package e;
import ;
import serterContext;import BodyOutputMessage;import ;import ;
import yFilter;import ctGatewayFilterFactory;import tServerRequest;import ffer;import aders;import CodecConfigurer;import HttpRequestDecorator;import serter;import serters;import Request;
/** * This filter is BETA and may be subject to change in a future release. */public class ModifyRequestBodyGatewayFilterFactory extends AbstractGatewayFilterFactory<> {
public ModifyRequestBodyGatewayFilterFactory() { super(); }
@Deprecated public ModifyRequestBodyGatewayFilterFactory(ServerCodecConfigurer codecConfigurer) { this(); }
@Override @SuppressWarnings("unchecked") public GatewayFilter apply(Config config) { return (exchange, chain) -> { Class inClass = lass();
ServerRequest serverRequest = new DefaultServerRequest(exchange); //TODO: flux or mono Mono> modifiedBody = Mono(inClass) // .log("modify_request_mono", ) .flatMap(o -> (exchange, o));
BodyInserter bodyInserter = blisher(modifiedBody, Class()); HttpHeaders headers = new HttpHeaders(); (uest().getHeaders());
// the new content type will be computed by bodyInserter // and then set in the request decorator (T_LENGTH);
// if the body is changing content types, set it here, to the bodyInserter will know about it if (tentType() != null) { (T_TYPE, tentType()); } CachedBodyOutputMessage outputMessage = new CachedBodyOutputMessage(exchange, headers); return (outputMessage, new BodyInserterContext()) // .log("modify_request", ) .then((() -> { ServerHttpRequestDecorator decorator = new ServerHttpRequestDecorator( uest()) {
828384858687888996979899597597 uest()) { @Override public HttpHeaders getHeaders() { long contentLength = tentLength(); HttpHeaders httpHeaders = new HttpHeaders(); (ders()); if (contentLength > 0) { tentLength(contentLength); } else { // TODO: this causes a 'HTTP/1.1 411 Length Required' on (ER_ENCODING, "chunked"); } return httpHeaders; }
@Override public Flux
}; }
public static class Config { private Class inClass; private Class outClass;
private String contentType;
@Deprecated private Map
private RewriteFunction rewriteFunction;
public Class getInClass() { return inClass; }
public Config setInClass(Class inClass) { s = inClass; return this; }
public Class getOutClass() { return outClass; }
public Config setOutClass(Class outClass) { ss = outClass; return this; }
@Deprecated public Map
@Deprecated public Config setInHints(Map
版权声明:本文标题:springcloudgateway在GatewayFilter中获取并修改请求参数 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/b/1708216316a516993.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论