Skip to content

Commit

Permalink
fix(deps): update dependency io.micronaut:micronaut-core-bom to v4.5.1 (
Browse files Browse the repository at this point in the history
#677)

* fix(deps): update dependency io.micronaut:micronaut-core-bom to v4.5.1

* Implement byteBody

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: yawkat <[email protected]>
  • Loading branch information
renovate[bot] and yawkat authored Jun 4, 2024
1 parent e1eff84 commit a3ca47f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,22 @@
import io.micronaut.http.MutableHttpHeaders;
import io.micronaut.http.MutableHttpParameters;
import io.micronaut.http.MutableHttpRequest;
import io.micronaut.http.ServerHttpRequest;
import io.micronaut.http.body.AvailableByteBody;
import io.micronaut.http.cookie.Cookie;
import io.micronaut.http.cookie.Cookies;
import io.micronaut.http.simple.SimpleHttpParameters;
import io.micronaut.servlet.http.BodyBuilder;
import io.micronaut.servlet.http.ByteArrayByteBuffer;
import io.micronaut.servlet.http.MutableServletHttpRequest;
import io.micronaut.servlet.http.ParsedBodyHolder;
import io.micronaut.servlet.http.ServletExchange;
import io.micronaut.servlet.http.ServletHttpRequest;
import io.micronaut.servlet.http.ServletHttpResponse;
import io.micronaut.servlet.http.body.AvailableByteArrayBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand All @@ -78,6 +79,7 @@
public final class AzureFunctionHttpRequest<T> implements
MutableServletHttpRequest<HttpRequestMessage<Optional<String>>, T>,
ServletExchange<HttpRequestMessage<Optional<String>>, HttpResponseMessage>,
ServerHttpRequest<T>,
FullHttpRequest<T>,
ParsedBodyHolder<T> {

Expand All @@ -96,8 +98,6 @@ public final class AzureFunctionHttpRequest<T> implements
private T parsedBody;
private T overriddenBody;

private ByteArrayByteBuffer<T> servletByteBuffer;

public AzureFunctionHttpRequest(
HttpRequestMessage<Optional<String>> request,
AzureFunctionHttpResponse<Object> response,
Expand Down Expand Up @@ -131,7 +131,17 @@ public byte[] getBodyBytes() throws IOException {
}
}

protected static HttpMethod parseMethod(Supplier<String> httpMethodConsumer) {
@Override
public @NonNull AvailableByteBody byteBody() {
try {
return new AvailableByteArrayBody(getBodyBytes());
} catch (IOException e) {
// empty body
return new AvailableByteArrayBody(ArrayUtils.EMPTY_BYTE_ARRAY);
}
}

private static HttpMethod parseMethod(Supplier<String> httpMethodConsumer) {
try {
return HttpMethod.valueOf(httpMethodConsumer.get());
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -171,7 +181,7 @@ public MutableHttpParameters getParameters() {

@Override
public InputStream getInputStream() throws IOException {
return servletByteBuffer != null ? servletByteBuffer.toInputStream() : new ByteArrayInputStream(getBodyBytes());
return byteBody().split().toInputStream();
}

@Override
Expand Down Expand Up @@ -251,7 +261,7 @@ public <B> Optional<B> getBody(Argument<B> arg) {
* @param contentType Content Type
* @return returns true if the content type is either application/x-www-form-urlencoded or multipart/form-data
*/
protected boolean isFormSubmission(MediaType contentType) {
private boolean isFormSubmission(MediaType contentType) {
return MediaType.APPLICATION_FORM_URLENCODED_TYPE.equals(contentType) || MediaType.MULTIPART_FORM_DATA_TYPE.equals(contentType);
}

Expand Down Expand Up @@ -285,14 +295,7 @@ public void setParsedBody(T body) {

@Override
public @Nullable ByteBuffer<?> contents() {
try {
if (servletByteBuffer == null) {
this.servletByteBuffer = new ByteArrayByteBuffer<>(getInputStream().readAllBytes());
}
return servletByteBuffer;
} catch (IOException e) {
throw new IllegalStateException("Error getting all body contents", e);
}
return byteBody().split().toByteBuffer();
}

@Override
Expand All @@ -307,7 +310,7 @@ public void setParsedBody(T body) {
* @return body bytes
* @throws IOException if the body is empty
*/
protected byte[] getBodyBytes(@NonNull Supplier<String> bodySupplier, @NonNull BooleanSupplier base64EncodedSupplier) throws IOException {
private byte[] getBodyBytes(@NonNull Supplier<String> bodySupplier, @NonNull BooleanSupplier base64EncodedSupplier) throws IOException {
String requestBody = bodySupplier.get();
if (StringUtils.isEmpty(requestBody)) {
throw new IOException("Empty Body");
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ kotlin = "1.9.23"
system-lambda = "1.2.1"

# Micronaut
micronaut = "4.4.1"
micronaut = "4.5.1"
micronaut-platform = "4.3.8"
micronaut-logging = "1.1.2"
micronaut-reactor = "3.3.0"
micronaut-serde = "2.9.0"
micronaut-servlet = "4.6.0"
micronaut-servlet = "4.9.0"
micronaut-test = "4.1.1"
micronaut-test-resources = "2.4.0"
micronaut-validation = "4.4.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void close() throws IOException {
private final static Set<String> HEADERS_USED_IN_TEST_SUITE = Set.of(
"X-Test-Filter",
"X-Captured-Remote-Address",
"X-HEAD-BODY",
HttpHeaders.ACCESS_CONTROL_ALLOW_PRIVATE_NETWORK
);

Expand Down

0 comments on commit a3ca47f

Please sign in to comment.