com.github.mcollovati.quarkus.hilla.BodyHandlerRecorder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-hilla-commons Show documentation
Show all versions of quarkus-hilla-commons Show documentation
Common files for Quarkus Hilla extension.
/*
* Copyright 2023 Marco Collovati, Dario Götze
*
* 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
*
* 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.
*/
package com.github.mcollovati.quarkus.hilla;
import com.vaadin.flow.shared.ApplicationConstants;
import io.quarkus.runtime.annotations.Recorder;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.ext.web.RoutingContext;
@Recorder
public class BodyHandlerRecorder {
/**
* In hybrid environment sometimes the requests hangs while reading body, causing the UI to freeze until read
* timeout is reached.
* This method returns a vert.x handler that delegates Flow requests to the Quarkus request body handler before
* proceeding with the execution.
* See https://github.com/mcollovati/quarkus-hilla/issues/182
* See https://github.com/mcollovati/quarkus-hilla/issues/490
*
* @param bodyHandler Quarkus request body handler
* @return a new handler that delegates Flow requests to request body handler.
*/
public Handler installBodyHandler(Handler bodyHandler) {
return routingContext -> {
HttpServerRequest request = routingContext.request();
// Do not delegate request to static resources
if (request.params().contains(ApplicationConstants.REQUEST_TYPE_PARAMETER)
&& !request.uri().startsWith("/VAADIN/")
&& !request.uri().startsWith("/HILLA/")) {
bodyHandler.handle(routingContext);
} else {
routingContext.next();
}
};
}
}