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

8265123: Add static factory methods to com.sun.net.httpserver.Filter #3468

Closed
wants to merge 9 commits into from

Conversation

FrauBoes
Copy link
Member

@FrauBoes FrauBoes commented Apr 13, 2021

Add two static factory methods to com.sun.net.httpserver.Filter that facilitate the creation of pre- and post-processing Filters:

public static Filter beforeResponse(String description, Consumer<HttpExchange> filterImpl) {}
public static Filter afterResponse(String description, Consumer<HttpExchange> filterImpl) {}


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8265123: Add static factory methods to com.sun.net.httpserver.Filter

Reviewers

Contributors

  • Michael McMahon <michaelm@openjdk.org>

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3468/head:pull/3468
$ git checkout pull/3468

Update a local copy of the PR:
$ git checkout pull/3468
$ git pull https://git.openjdk.java.net/jdk pull/3468/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3468

View PR using the GUI difftool:
$ git pr show -t 3468

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3468.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 13, 2021

👋 Welcome back jboes! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Apr 13, 2021

@FrauBoes The following label will be automatically applied to this pull request:

  • net

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the net net-dev@openjdk.org label Apr 13, 2021
@FrauBoes FrauBoes marked this pull request as ready for review Apr 14, 2021
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 14, 2021
@FrauBoes
Copy link
Member Author

FrauBoes commented Apr 14, 2021

/csr needed

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Apr 14, 2021
@openjdk
Copy link

openjdk bot commented Apr 14, 2021

@FrauBoes has indicated that a compatibility and specification (CSR) request is needed for this pull request.
@FrauBoes please create a CSR request and add link to it in JDK-8265123. This pull request cannot be integrated until the CSR request is approved.

@mlbridge
Copy link

mlbridge bot commented Apr 14, 2021

Webrevs

@FrauBoes
Copy link
Member Author

FrauBoes commented Apr 14, 2021

/contributor add michaelm

@openjdk
Copy link

openjdk bot commented Apr 14, 2021

@FrauBoes
Contributor Michael McMahon <michaelm@openjdk.org> successfully added.

@FrauBoes
Copy link
Member Author

FrauBoes commented Apr 26, 2021

Updated the method names and specifications, which now include @apiNotes and examples. I'm not sure if we want to keep both examples for afterHandler?
Added a test for the uncommon case where the filters handle the exchange (not the handler).

API docs: http://cr.openjdk.java.net/~jboes/webrevs/8265123/api/jdk.httpserver/com/sun/net/httpserver/Filter.html

@FrauBoes
Copy link
Member Author

FrauBoes commented Apr 26, 2021

This looks a little odd - writing to the output steam before the response headers have been sent. Does it work because the length is actually 0? Please add some response body to the test, this should then show that writing to the output stream before the headers have been sent is an error.

Oops, that's fixed now!

test/jdk/com/sun/net/httpserver/FilterTest.java Outdated Show resolved Hide resolved
test/jdk/com/sun/net/httpserver/FilterTest.java Outdated Show resolved Hide resolved
test/jdk/com/sun/net/httpserver/FilterTest.java Outdated Show resolved Hide resolved
test/jdk/com/sun/net/httpserver/FilterTest.java Outdated Show resolved Hide resolved
test/jdk/com/sun/net/httpserver/FilterTest.java Outdated Show resolved Hide resolved
test/jdk/com/sun/net/httpserver/FilterTest.java Outdated Show resolved Hide resolved
@FrauBoes
Copy link
Member Author

FrauBoes commented Apr 28, 2021

Thanks for your comments, Daniel. I incorporated them and tightened the specs and examples.

API docs updated in place: http://cr.openjdk.java.net/~jboes/webrevs/8265123/api/jdk.httpserver/com/sun/net/httpserver/Filter.html

*
* <p> Example of adding a response header to all responses:
* <p> Example of adding the Foo response header to all responses:
Copy link
Member

@dfuch dfuch Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the {@code "Foo"} ? Or the {@code "Foo: Bar"}?

* Doing so is likely to fail, since this is commonly done by the exchange
* handler.
Copy link
Member

@dfuch dfuch Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe ... since the request is expected to have already been handled before the operation is invoked?

* The order in which the filters are invoked is reverse to the order in
* which they are added to the context's filter-list.
Copy link
Member

@dfuch dfuch Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May need to be a bit more precise. The filters are invoked in the order they are added, but their operations are invoked in the reverse order. I'd suggest:

     * The order in which the filter's operations are invoked is reverse to the order in
     * which the filters are added to the context's filter-list.

* Returns a pre-processing {@code Filter} with the given description and
* operation.
*
* <p>The {@link #description() description} describes the returned filter.
Copy link
Member

@Michael-Mc-Mahon Michael-Mc-Mahon Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, delete the first sentence here. I don't think it adds much value. Then the @param for description could say: The string to be returned from {@link #description()}

dfuch
dfuch approved these changes Apr 28, 2021
Copy link
Member

@dfuch dfuch left a comment

I wonder if instead of simply saying:

* @return a filter

we should say:

* @return a filter whose operation is invoked before the exchange is handled
* @return a filter whose operation is invoked after the exchange is handled

Otherwise, LGTM!

No need for a new review if you take on these changes.

dfuch
dfuch approved these changes Apr 28, 2021
@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Apr 28, 2021
@openjdk
Copy link

openjdk bot commented Apr 28, 2021

@FrauBoes This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8265123: Add static factory methods to com.sun.net.httpserver.Filter

Co-authored-by: Michael McMahon <michaelm@openjdk.org>
Reviewed-by: chegar, michaelm, dfuchs

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 7 new commits pushed to the master branch:

  • 21f65f8: 8266206: Build failure after JDK-8264752 with older GCCs
  • c71c268: 8266165: TestNoWarningLoopStripMiningIterSet is runnable only on VM w/ G1, Shenandoah, Z and Epsilon
  • 8954bef: 8266188: mark hotspot compiler/cpuflags tests which ignore VM flags
  • 19d3c45: 8266184: a few compiler/debug tests don't check exit code
  • 7e3bc4c: 8228442: DHKeyExchange/LegacyDHEKeyExchange.java failed due to "SSLException: An established connection was aborted by the software in your host machine"
  • f40bf1d: 8266087: Move 'buffer' declaration in get_user_name_slow() inside of linux specific code
  • ec383ab: 8183374: Refactor java/lang/Runtime shell tests to java

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 28, 2021
@FrauBoes
Copy link
Member Author

FrauBoes commented Apr 29, 2021

/integrate

@openjdk openjdk bot closed this Apr 29, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 29, 2021
@openjdk
Copy link

openjdk bot commented Apr 29, 2021

@FrauBoes Since your change was applied there have been 31 commits pushed to the master branch:

  • 39abac9: 8266176: -Wmaybe-uninitialized happens in libArrayIndexOutOfBoundsExceptionTest.c
  • 155da25: 8265005: Introduce the new client property for mac: apple.awt.windowTitleVisible
  • 91226fa: 8265940: Enable C2's optimization for Math.pow(x, 0.5) on all platforms
  • 56cde70: 8266265: mark hotspot compiler/vectorization tests which ignore VM flags
  • 4937214: 8266174: -Wmisleading-indentation happens in libmlib_image sources
  • b305eff: 8266238: mark hotspot compiler/inlining tests which ignore VM flags
  • df3b2d0: 8266264: mark hotspot compiler/eliminateAutobox tests which ignore VM flags
  • 6b263e6: 8266256: compiler.vectorization.TestBufferVectorization does testing twice
  • 69155f4: 8266231: mark hotspot compiler/c1 tests which ignore VM flags
  • 0e225ef: 8197821: Test java/awt/font/TextLayout/LigatureCaretTest.java fails on Windows
  • ... and 21 more: https://git.openjdk.java.net/jdk/compare/343a4a76f273078f78897e8fb7e695bc2c111536...master

Your commit was automatically rebased without conflicts.

Pushed as commit 115a413.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@FrauBoes FrauBoes deleted the 8265123 branch May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated net net-dev@openjdk.org
5 participants