Skip to content

Commit

Permalink
Merge branch '3.8.x' into 4.0.x-merge
Browse files Browse the repository at this point in the history
# Conflicts:
#	core/src/main/java/io/micronaut/core/convert/value/ConvertibleMultiValuesMap.java
#	core/src/main/java/io/micronaut/core/convert/value/ConvertibleValuesMap.java
#	gradle/libs.versions.toml
#	http-client/src/main/java/io/micronaut/http/client/netty/ConnectionManager.java
#	http-client/src/main/java/io/micronaut/http/client/netty/DefaultHttpClient.java
#	http-client/src/main/java/io/micronaut/http/client/netty/websocket/NettyWebSocketClientHandler.java
#	http-netty/src/main/java/io/micronaut/http/netty/websocket/AbstractNettyWebSocketHandler.java
#	inject-java-test/src/main/groovy/io/micronaut/annotation/processing/test/AbstractTypeElementSpec.groovy
#	jackson-databind/src/test/groovy/io/micronaut/jackson/modules/BeanIntrospectionModuleSpec.groovy
#	jackson-databind/src/test/groovy/io/micronaut/jackson/modules/testclasses/HTTPCheck.java
#	parent/build.gradle
  • Loading branch information
yawkat committed Dec 15, 2022
2 parents cada0a4 + 1e98d85 commit b5f06ab
Show file tree
Hide file tree
Showing 37 changed files with 1,625 additions and 641 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/graalvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
matrix:
java: ['17']
graalvm: ['latest', 'dev']
include:
- graalvm: 'latest'
java: '11'
steps:
# https://github.com/actions/virtual-environments/issues/709
- name: Free disk space
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -144,6 +145,23 @@ protected Map<CharSequence, List<V>> wrapValues(Map<CharSequence, List<V>> value
return Collections.unmodifiableMap(values);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ConvertibleMultiValuesMap<?> that = (ConvertibleMultiValuesMap<?>) o;
return values.equals(that.values);
}

@Override
public int hashCode() {
return Objects.hash(values);
}

@Override
public ConversionService getConversionService() {
return conversionService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -106,6 +107,23 @@ public static <V> ConvertibleValues<V> empty() {
return EMPTY;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ConvertibleValuesMap<?> that = (ConvertibleValuesMap<?>) o;
return map.equals(that.map);
}

@Override
public int hashCode() {
return Objects.hash(map);
}

@Override
public void setConversionService(ConversionService conversionService) {
this.conversionService = conversionService;
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ developers=Graeme Rocher
kapt.use.worker.api=true

# Dependency Versions
micronautMavenPluginVersion=3.5.0
micronautMavenPluginVersion=3.5.1
chromedriverVersion=79.0.3945.36
geckodriverVersion=0.26.0
webdriverBinariesVersion=1.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,15 @@ default <I, O> Publisher<HttpResponse<O>> exchange(@NonNull HttpRequest<I> reque
* @param <E> The error type
* @return A {@link Publisher} that emits a result of the given type
*/
@SuppressWarnings("unchecked")
default <I, O, E> Publisher<O> retrieve(@NonNull HttpRequest<I> request, @NonNull Argument<O> bodyType, @NonNull Argument<E> errorType) {
// note: this default impl isn't used by us anymore, it's overridden by DefaultHttpClient
return Flux.from(exchange(request, bodyType, errorType)).map(response -> {
Flux<HttpResponse<O>> exchange = Flux.from(exchange(request, bodyType, errorType));
if (bodyType.getType() == void.class) {
// exchange() returns a HttpResponse<Void>, we can't map the Void body properly, so just drop it and complete
return (Publisher<O>) exchange.ignoreElements();
}
return exchange.map(response -> {
if (bodyType.getType() == HttpStatus.class) {
return (O) response.getStatus();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,8 @@ public Object intercept(MethodInvocationContext<Object, Object> context) {
request.setAttribute(HttpAttributes.INVOCATION_CONTEXT, context);
// Set the URI template used to make the request for tracing purposes
request.setAttribute(HttpAttributes.URI_TEMPLATE, resolveTemplate(annotationMetadata, uriTemplate.toString()));
String serviceId = getClientId(annotationMetadata);
Argument<?> errorType = annotationMetadata.classValue(Client.class, "errorType")
.map((Function<Class, Argument>) Argument::of).orElse(HttpClient.DEFAULT_ERROR_TYPE);
request.setAttribute(HttpAttributes.SERVICE_ID, serviceId);


final MediaType[] acceptTypes;
Collection<MediaType> accept = request.accept();
Expand Down Expand Up @@ -426,7 +423,7 @@ private Publisher httpClientResponsePublisher(HttpClient httpClient, MutableHttp
Class<?> argumentType = reactiveValueArgument.getType();
if (Void.class == argumentType || returnType.isVoid()) {
request.getHeaders().remove(HttpHeaders.ACCEPT);
return httpClient.exchange(request, Argument.VOID, errorType);
return httpClient.retrieve(request, Argument.VOID, errorType);
} else {
if (HttpResponse.class.isAssignableFrom(argumentType)) {
return httpClient.exchange(request, reactiveValueArgument, errorType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import io.micronaut.core.util.ArrayUtils;
import io.micronaut.core.util.CollectionUtils;
import io.micronaut.core.util.StringUtils;
import io.micronaut.core.util.SupplierUtil;
import io.micronaut.http.HttpAttributes;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpResponseWrapper;
import io.micronaut.http.HttpStatus;
Expand Down Expand Up @@ -91,6 +91,7 @@
import io.micronaut.http.sse.Event;
import io.micronaut.http.uri.UriBuilder;
import io.micronaut.http.uri.UriTemplate;
import io.micronaut.http.util.HttpHeadersUtil;
import io.micronaut.json.JsonMapper;
import io.micronaut.json.codec.JsonMediaTypeCodec;
import io.micronaut.json.codec.JsonStreamMediaTypeCodec;
Expand Down Expand Up @@ -189,7 +190,6 @@
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Pattern;

import static io.micronaut.scheduling.instrument.InvocationInstrumenter.NOOP;

Expand All @@ -216,9 +216,6 @@ public class DefaultHttpClient implements
private static final int DEFAULT_HTTP_PORT = 80;
private static final int DEFAULT_HTTPS_PORT = 443;

private static final Supplier<Pattern> HEADER_MASK_PATTERNS = SupplierUtil.memoized(() ->
Pattern.compile(".*(password|cred|cert|key|secret|token|auth|signat).*", Pattern.CASE_INSENSITIVE)
);
/**
* Which headers <i>not</i> to copy from the first request when redirecting to a second request. There doesn't
* appear to be a spec for this. {@link java.net.HttpURLConnection} seems to drop all headers, but that would be a
Expand Down Expand Up @@ -792,7 +789,12 @@ private <I, O, E> Flux<HttpResponse<O>> exchange(io.micronaut.http.HttpRequest<I
public <I, O, E> Publisher<O> retrieve(io.micronaut.http.HttpRequest<I> request, Argument<O> bodyType, Argument<E> errorType) {
setupConversionService(request);
// mostly same as default impl, but with exception customization
return Flux.from(exchange(request, bodyType, errorType)).map(response -> {
Flux<HttpResponse<O>> exchange = Flux.from(exchange(request, bodyType, errorType));
if (bodyType.getType() == void.class) {
// exchange() returns a HttpResponse<Void>, we can't map the Void body properly, so just drop it and complete
return (Publisher<O>) exchange.ignoreElements();
}
return exchange.map(response -> {
if (bodyType.getType() == HttpStatus.class) {
return (O) response.getStatus();
} else {
Expand Down Expand Up @@ -1241,7 +1243,13 @@ private <I, R extends io.micronaut.http.HttpResponse<?>> Publisher<R> applyFilte
Publisher<R> responsePublisher) {

if (request instanceof MutableHttpRequest) {
((MutableHttpRequest<I>) request).uri(requestURI);
MutableHttpRequest<I> mutRequest = (MutableHttpRequest<I>) request;
mutRequest.uri(requestURI);
if (informationalServiceId != null &&
!mutRequest.getAttribute(HttpAttributes.SERVICE_ID).isPresent()) {

mutRequest.setAttribute(HttpAttributes.SERVICE_ID, informationalServiceId);
}

List<HttpClientFilter> filters =
filterResolver.resolveFilters(request, clientFilterEntries);
Expand Down Expand Up @@ -1552,10 +1560,6 @@ private <I, O, E> void sendRequestThroughChannel(
new FullHttpResponseHandler<>(responsePromise, poolHandle, secure, finalRequest, bodyType, errorType));
poolHandle.notifyRequestPipelineBuilt();
Publisher<HttpResponse<O>> publisher = new NettyFuturePublisher<>(responsePromise, true);
if (bodyType != null && bodyType.isVoid()) {
// don't emit response if bodyType is void
publisher = Flux.from(publisher).filter(r -> false);
}
publisher.subscribe(new ForwardingSubscriber<>(emitter));

requestWriter.write(poolHandle, secure, emitter);
Expand Down Expand Up @@ -1706,7 +1710,7 @@ private ClientFilterChain buildChain(AtomicReference<MutableHttpRequest<?>> requ
public Publisher<? extends io.micronaut.http.HttpResponse<?>> proceed(MutableHttpRequest<?> request) {

int pos = integer.incrementAndGet();
if (pos > len) {
if (pos >= len) {
throw new IllegalStateException("The FilterChain.proceed(..) method should be invoked exactly once per filter execution. The method has instead been invoked multiple times by an erroneous filter definition.");
}
HttpClientFilter httpFilter = filters.get(pos);
Expand Down Expand Up @@ -1815,7 +1819,7 @@ private void debugRequest(URI requestURI, io.netty.handler.codec.http.HttpReques

private void traceRequest(io.micronaut.http.HttpRequest<?> request, io.netty.handler.codec.http.HttpRequest nettyRequest) {
HttpHeaders headers = nettyRequest.headers();
traceHeaders(headers);
HttpHeadersUtil.trace(log, headers.names(), headers::getAll);
if (io.micronaut.http.HttpMethod.permitsRequestBody(request.getMethod()) && request.getBody().isPresent() && nettyRequest instanceof FullHttpRequest) {
FullHttpRequest fullHttpRequest = (FullHttpRequest) nettyRequest;
ByteBuf content = fullHttpRequest.content();
Expand All @@ -1839,30 +1843,6 @@ private void traceChunk(ByteBuf content) {
log.trace("----");
}

private void traceHeaders(HttpHeaders headers) {
for (String name : headers.names()) {
boolean isMasked = HEADER_MASK_PATTERNS.get().matcher(name).matches();
List<String> all = headers.getAll(name);
if (all.size() > 1) {
for (String value : all) {
String maskedValue = isMasked ? mask(value) : value;
log.trace("{}: {}", name, maskedValue);
}
} else if (!all.isEmpty()) {
String maskedValue = isMasked ? mask(all.get(0)) : all.get(0);
log.trace("{}: {}", name, maskedValue);
}
}
}

@Nullable
private String mask(@Nullable String value) {
if (value == null) {
return null;
}
return "*MASKED*";
}

private static MediaTypeCodecRegistry createDefaultMediaTypeRegistry() {
JsonMapper mapper = JsonMapper.createDefault();
ApplicationConfiguration configuration = new ApplicationConfiguration();
Expand Down Expand Up @@ -2134,7 +2114,7 @@ protected void channelReadInstrumented(ChannelHandlerContext ctx, R msg) throws
HttpHeaders headers = msg.headers();
if (log.isTraceEnabled()) {
log.trace("HTTP Client Response Received ({}) for Request: {} {}", msg.status(), finalRequest.getMethodName(), finalRequest.getUri());
traceHeaders(headers);
HttpHeadersUtil.trace(log, headers.names(), headers::getAll);
}
buildResponse(responsePromise, msg);
removeHandler(ctx);
Expand Down
Loading

0 comments on commit b5f06ab

Please sign in to comment.