All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.muserver.RequestBodyListener Maven / Gradle / Ivy

There is a newer version: 2.0.3
Show newest version
package io.muserver;

import java.nio.ByteBuffer;

/**
 * 

Callbacks for reading request body data asynchronously.

*

Example usage:

*

 *  server = httpsServer()
 *      .addHandler((request, response) -> {
 *          AsyncHandle ctx = request.handleAsync();
 *          ctx.setReadListener(new RequestBodyListener() {
 *              public void onDataReceived(ByteBuffer bb) {
 *                  byte[] b = new byte[bb.remaining()];
 *                  bb.get(b);
 *                  try {
 *                      response.outputStream().write(b);
 *                  } catch (IOException e) {
 *                      errors.add(e);
 *                  }
 *              }
 *
 *              public void onComplete() {
 *                  ctx.complete();
 *              }
 *
 *              public void onError(Throwable t) {
 *                  errors.add(t);
 *              }
 *          });
 *
 *          return true;
 *      })
 *      .start();
 * 
*/ public interface RequestBodyListener { /** *

Called when request data is received from the client.

*

NOTE: this method should not block as it runs on a socket acceptor thread. If you need to do any blocking operations * it is recommended you process the data on another thread.

* @param buffer A buffer holding some of the request body data */ void onDataReceived(ByteBuffer buffer); /** * Called when the request body is fully received. */ void onComplete(); /** * Called if there is an error reading the body. * @param t The error. */ void onError(Throwable t); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy