Skip to content

Commit

Permalink
Factor request bodyHandler code as default HttpServerRequest interface
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Mar 13, 2016
1 parent f173ea5 commit 2dd4294
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/main/java/io/vertx/core/http/HttpServerRequest.java
Expand Up @@ -174,7 +174,12 @@ public interface HttpServerRequest extends ReadStream<Buffer> {
* @param bodyHandler This handler will be called after all the body has been received
*/
@Fluent
HttpServerRequest bodyHandler(@Nullable Handler<Buffer> bodyHandler);
default HttpServerRequest bodyHandler(@Nullable Handler<Buffer> bodyHandler) {
Buffer body = Buffer.buffer();
handler(body::appendBuffer);
endHandler(v -> bodyHandler.handle(body));
return this;
}

/**
* Get a net socket for the underlying connection of this request.
Expand Down
Expand Up @@ -337,11 +337,6 @@ public String absoluteURI() {
return absoluteURI;
}

@Override
public HttpServerRequest bodyHandler(@Nullable Handler<Buffer> bodyHandler) {
throw new UnsupportedOperationException();
}

@Override
public NetSocket netSocket() {
throw new UnsupportedOperationException();
Expand Down
Expand Up @@ -252,14 +252,6 @@ public X509Certificate[] peerCertificateChain() throws SSLPeerUnverifiedExceptio
return conn.getPeerCertificateChain();
}

@Override
public HttpServerRequest bodyHandler(final Handler<Buffer> bodyHandler) {
Buffer body = Buffer.buffer();
handler(body::appendBuffer);
endHandler(v -> bodyHandler.handle(body));
return this;
}

@Override
public NetSocket netSocket() {
if (netSocket == null) {
Expand Down

0 comments on commit 2dd4294

Please sign in to comment.