@Override public void start() throws Exception { vertx.createHttpServer().requestHandler(req -> { System.out.println("Got form with content-type " + req.getHeader("content-type")); req.setExpectMultipart(true); req.endHandler(v -> { System.out.println("firstName: " + req.getFormAttribute("firstName")); System.out.println("lastName: " + req.getFormAttribute("lastName")); System.out.println("male: " + req.getFormAttribute("male")); req.response().end(); }); }).listen(8080, listenResult -> { if (listenResult.failed()) { System.out.println("Could not start HTTP server"); listenResult.cause().printStackTrace(); } else { System.out.println("Server started"); } }); } }
@Override public void start() throws Exception { vertx.createHttpServer().requestHandler(req -> { System.out.println("Got form with content-type " + req.getHeader("content-type")); req.setExpectMultipart(true); req.endHandler(v -> { System.out.println("firstName: " + req.getFormAttribute("firstName")); System.out.println("lastName: " + req.getFormAttribute("lastName")); System.out.println("male: " + req.getFormAttribute("male")); req.response().end(); }); }).listen(8080, listenResult -> { if (listenResult.failed()) { System.out.println("Could not start HTTP server"); listenResult.cause().printStackTrace(); } else { System.out.println("Server started"); } }); } }
@Override public void start() throws Exception { vertx.createHttpServer().requestHandler(req -> { if (req.uri().equals("/")) { // Serve the index page req.response().sendFile("index.html"); } else if (req.uri().startsWith("/form")) { req.response().setChunked(true); req.setExpectMultipart(true); req.endHandler((v) -> { for (String attr : req.formAttributes().names()) { req.response().write("Got attr " + attr + " : " + req.formAttributes().get(attr) + "\n"); } req.response().end(); }); } else { req.response().setStatusCode(404).end(); } }).listen(8080); } }
@Override public void start() throws Exception { vertx.createHttpServer().requestHandler(req -> { if (req.uri().equals("/")) { // Serve the index page req.response().sendFile("index.html"); } else if (req.uri().startsWith("/form")) { req.setExpectMultipart(true); req.uploadHandler(upload -> { upload.exceptionHandler(cause -> { req.response().setChunked(true).end("Upload failed"); }); upload.endHandler(v -> { req.response().setChunked(true).end("Successfully uploaded to " + upload.filename()); }); // FIXME - Potential security exploit! In a real system you must check this filename // to make sure you're not saving to a place where you don't want! // Or better still, just use Vert.x-Web which controls the upload area. upload.streamToFileSystem(upload.filename()); }); } else { req.response().setStatusCode(404); req.response().end(); } }).listen(8080); } }
private void testParamDecoding(String value) throws UnsupportedEncodingException { server.requestHandler(req -> { req.setExpectMultipart(true); req.endHandler(v -> { MultiMap formAttributes = req.formAttributes(); assertEquals(value, formAttributes.get("param")); }); req.response().end(); }); String postData = "param=" + URLEncoder.encode(value,"UTF-8"); server.listen(onSuccess(server -> { client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", onSuccess(resp -> testComplete())) .putHeader(HttpHeaders.CONTENT_TYPE, HttpHeaders.APPLICATION_X_WWW_FORM_URLENCODED) .putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(postData.length())) .write(postData).end(); })); await(); }
@Override public HttpServerRequest setExpectMultipart(boolean b) { return delegate.setExpectMultipart(b); }
if (req.method() == HttpMethod.POST) { assertEquals(req.path(), "/form"); req.setExpectMultipart(true); req.uploadHandler(event -> event.handler(buffer -> { fail("Should not get here");
assertEquals(req.path(), "/form"); req.response().setChunked(true); req.setExpectMultipart(true); req.uploadHandler(upload -> upload.handler(buffer -> { fail("Should get here");
req.setExpectMultipart(true); fail("Shouldn't be able to set expect multipart"); } catch (IllegalStateException e) {
assertEquals(req.path(), "/form"); req.response().setChunked(true); req.setExpectMultipart(true); assertTrue(req.isExpectMultipart()); req.setExpectMultipart(true); assertTrue(req.isExpectMultipart());
req.setExpectMultipart(true); fail("Shouldn't be able to set expect multipart"); } catch (IllegalStateException e) {
private void handleRequestWithBody(HttpServerRequest request) { final String contentType = request.headers().get("Content-Type"); if (HttpContentTypes.isFormContentType(contentType)) { request.setExpectMultipart(true); } final Buffer[] bufferHolder = new Buffer[1]; final HttpRequest bodyHttpRequest = vertxUtils.createRequest(request, () -> bufferHolder[0], new HashMap<>(), simpleHttpServer.getDecorators(), simpleHttpServer.getHttpResponseCreator()); if (simpleHttpServer.getShouldContinueReadingRequestBody().test(bodyHttpRequest)) { request.bodyHandler((buffer) -> { bufferHolder[0] = buffer; simpleHttpServer.handleRequest(bodyHttpRequest); }); } else { logger.info("Request body rejected {} {}", request.method(), request.absoluteURI()); } }
context.request().setExpectMultipart(true); if (handleFileUploads) { makeUploadDir(context.vertx().fileSystem());
request.setExpectMultipart(true);
private void testParamDecoding(String value) throws UnsupportedEncodingException { server.requestHandler(req -> { req.setExpectMultipart(true); req.endHandler(v -> { MultiMap formAttributes = req.formAttributes(); assertEquals(value, formAttributes.get("param")); }); req.response().end(); }); String postData = "param=" + URLEncoder.encode(value,"UTF-8"); server.listen(onSuccess(server -> { client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/") .putHeader(HttpHeaders.CONTENT_TYPE, HttpHeaders.APPLICATION_X_WWW_FORM_URLENCODED) .putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(postData.length())) .handler(resp -> { testComplete(); }) .write(postData).end(); })); await(); }
req.setExpectMultipart(true).bodyHandler(buffer -> { final String queryString = buffer.toString(); assertTrue(queryString.contains("username=paulo")); }); } else if (req.method() == HttpMethod.POST && "/oauth/revoke".equals(req.path())) { req.setExpectMultipart(true).bodyHandler(buffer -> req.response().end()); } else { req.response().setStatusCode(400).end();
if (req.method() == HttpMethod.POST) { assertEquals(req.path(), "/form"); req.setExpectMultipart(true); req.uploadHandler(event -> event.handler(buffer -> { fail("Should not get here");
assertEquals(req.path(), "/form"); req.response().setChunked(true); req.setExpectMultipart(true); req.uploadHandler(upload -> upload.handler(buffer -> { fail("Should get here");
req.setExpectMultipart(true); fail("Shouldn't be able to set expect multipart"); } catch (IllegalStateException e) {
req.setExpectMultipart(true); fail("Shouldn't be able to set expect multipart"); } catch (IllegalStateException e) {