Java Code Examples for io.undertow.server.HttpServerExchange#getRequestContentLength()
The following examples show how to use
io.undertow.server.HttpServerExchange#getRequestContentLength() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SavedRequest.java From quarkus-http with Apache License 2.0 | 5 votes |
public static void trySaveRequest(final HttpServerExchange exchange) { int maxSize = getMaxBufferSizeToSave(exchange); if (maxSize > 0) { //if this request has a body try and cache the response if (!exchange.isRequestComplete()) { final long requestContentLength = exchange.getRequestContentLength(); if (requestContentLength > maxSize) { UndertowLogger.REQUEST_LOGGER.debugf("Request to %s was to large to save", exchange.getRequestURI()); return;//failed to save the request, we just return } //TODO: we should really be used pooled buffers //TODO: we should probably limit the number of saved requests at any given time byte[] buffer = new byte[maxSize]; int read = 0; int res = 0; InputStream in = exchange.getInputStream(); try { while ((res = in.read(buffer, read, buffer.length - read)) > 0) { read += res; if (read == maxSize) { UndertowLogger.REQUEST_LOGGER.debugf("Request to %s was to large to save", exchange.getRequestURI()); return;//failed to save the request, we just return } } //save request from buffer trySaveRequest(exchange, buffer, read); } catch (IOException e) { UndertowLogger.REQUEST_IO_LOGGER.ioException(e); } } } }
Example 2
Source File: RequestBodyParser.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
public RequestBodyParser(HttpServerExchange exchange, HttpHandler handler) { this.exchange = exchange; this.handler = handler; int length = (int) exchange.getRequestContentLength(); if (length < 0) body = new ByteArrayOutputStream(); else body = new ByteArrayOutputStream(length); }
Example 3
Source File: UndertowIOHandler.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
private boolean hasBody(HttpServerExchange exchange) { int length = (int) exchange.getRequestContentLength(); if (length == 0) return false; HttpString method = exchange.getRequestMethod(); return Methods.POST.equals(method) || Methods.PUT.equals(method); }
Example 4
Source File: SavedRequest.java From lams with GNU General Public License v2.0 | 5 votes |
public static void trySaveRequest(final HttpServerExchange exchange) { int maxSize = getMaxBufferSizeToSave(exchange); if (maxSize > 0) { //if this request has a body try and cache the response if (!exchange.isRequestComplete()) { final long requestContentLength = exchange.getRequestContentLength(); if (requestContentLength > maxSize) { UndertowLogger.REQUEST_LOGGER.debugf("Request to %s was to large to save", exchange.getRequestURI()); return;//failed to save the request, we just return } //TODO: we should really be used pooled buffers //TODO: we should probably limit the number of saved requests at any given time byte[] buffer = new byte[maxSize]; int read = 0; int res = 0; InputStream in = exchange.getInputStream(); try { while ((res = in.read(buffer, read, buffer.length - read)) > 0) { read += res; if (read == maxSize) { UndertowLogger.REQUEST_LOGGER.debugf("Request to %s was to large to save", exchange.getRequestURI()); return;//failed to save the request, we just return } } //save request from buffer trySaveRequest(exchange, buffer, read); } catch (IOException e) { UndertowLogger.REQUEST_IO_LOGGER.ioException(e); } } } }
Example 5
Source File: HTTPIOHandler.java From core-ng-project with Apache License 2.0 | 5 votes |
private boolean hasBody(HttpServerExchange exchange) { int length = (int) exchange.getRequestContentLength(); if (length == 0) return false; // if body is empty, skip reading HttpString method = exchange.getRequestMethod(); return Methods.POST.equals(method) || Methods.PUT.equals(method) || Methods.PATCH.equals(method); }
Example 6
Source File: RequestBodyReader.java From core-ng-project with Apache License 2.0 | 4 votes |
public RequestBodyReader(HttpServerExchange exchange, HTTPHandler handler) { this.exchange = exchange; this.handler = handler; contentLength = (int) exchange.getRequestContentLength(); if (contentLength >= 0) body = new byte[contentLength]; }