Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIFI-14115 Set Standard HTTP Headers for Framework Responses #9598

Closed
wants to merge 3 commits into from

Conversation

exceptionfactory
Copy link
Contributor

Summary

NIFI-14115 Adjusts the framework Jetty Server configuration to set standard HTTP headers for all responses, regardless of web application.

The current implementation uses the Spring Security HeaderWriterFilter and applies standard Servlet Filters to configured web applications. This covers both framework REST API and custom extensions, but does not include requests to the root web server path.

The updated implementation replaces the Servlet Filter approach with a HeaderWriterHandler to set the same response headers using a Jetty Handler class. The change introduces a new StandardServerProvider to decouple Jetty Server instance initialization from lifecycle operations. The StandardServerProvider includes decoupled tests for basic operation, including returning expected response headers.

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using mvn clean install -P contrib-check
    • JDK 21

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

- Added HeaderWriterHandler implementing Jetty Handler methods for setting standard HTTP response headers
- Removed HeaderWriterFilter approach for writing standard HTTP headers
- Refactored Jetty Server instantiation to StandardServerProvider for streamlined configuration and testing
@joewitt
Copy link
Contributor

joewitt commented Dec 27, 2024

Changes look good. Confirmed all headers previously supported are ported over. Verifying build locally then will merge.

@joewitt
Copy link
Contributor

joewitt commented Dec 27, 2024

Local build failed.

[ERROR] Tests run: 3, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.125 s <<< FAILURE! -- in org.apache.nifi.web.server.StandardServerProviderTest [ERROR] org.apache.nifi.web.server.StandardServerProviderTest.testGetServerStart -- Time elapsed: 0.101 s <<< ERROR! java.io.IOException: HTTP/1.1 header parser received no bytes at java.net.http/jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:966) at java.net.http/jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:133) at org.apache.nifi.web.server.StandardServerProviderTest.getResponseHeaders(StandardServerProviderTest.java:118) at org.apache.nifi.web.server.StandardServerProviderTest.testGetServerStart(StandardServerProviderTest.java:105) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at java.base/java.util.ArrayList.forEach(ArrayList.java:1596) at java.base/java.util.ArrayList.forEach(ArrayList.java:1596) Caused by: java.io.IOException: HTTP/1.1 header parser received no bytes at java.net.http/jdk.internal.net.http.common.Utils.wrapWithExtraDetail(Utils.java:388) at java.net.http/jdk.internal.net.http.Http1Response$HeadersReader.onReadError(Http1Response.java:590) at java.net.http/jdk.internal.net.http.Http1AsyncReceiver.checkForErrors(Http1AsyncReceiver.java:302) at java.net.http/jdk.internal.net.http.Http1AsyncReceiver.flush(Http1AsyncReceiver.java:268) at java.net.http/jdk.internal.net.http.common.SequentialScheduler$LockingRestartableTask.run(SequentialScheduler.java:182) at java.net.http/jdk.internal.net.http.common.SequentialScheduler$CompleteRestartableTask.run(SequentialScheduler.java:149) at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:207) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) at java.base/java.lang.Thread.run(Thread.java:1583) Caused by: java.io.EOFException: EOF reached while reading at java.net.http/jdk.internal.net.http.Http1AsyncReceiver$Http1TubeSubscriber.onComplete(Http1AsyncReceiver.java:601) at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$ReadSubscription.signalCompletion(SocketTube.java:648) at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$InternalReadSubscription.read(SocketTube.java:853) at java.net.http/jdk.internal.net.http.SocketTube$SocketFlowTask.run(SocketTube.java:181) at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:207) at java.net.http/jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:280) at java.net.http/jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:233) at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$InternalReadSubscription.signalReadable(SocketTube.java:782) at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$ReadEvent.signalEvent(SocketTube.java:965) at java.net.http/jdk.internal.net.http.SocketTube$SocketFlowEvent.handle(SocketTube.java:253) at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:1469) at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.lambda$run$3(HttpClientImpl.java:1414) at java.base/java.util.ArrayList.forEach(ArrayList.java:1596) at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:1414)

@joewitt
Copy link
Contributor

joewitt commented Dec 27, 2024

I tried the build on a different system (linux host) and the build was fine. I suspect what I'm hitting is a local system/security configuration issue. Still reviewing

@exceptionfactory
Copy link
Contributor Author

Thanks for the feedback @joewitt.

Although I did not have the local build issue, the error points to a potential timing issue with the Jetty Server instance not being ready for the test sends the HTTP request.

To avoid potential timing issues, I simplified the test method to just check that the server start did not fail.

@joewitt
Copy link
Contributor

joewitt commented Dec 27, 2024

With timing addressed and header checks changed the test does now pass. Running full clean build to confirm all the things. Have all three commits

@joewitt joewitt closed this in 5f72313 Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants