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

play.libs.ws.WSBodyWritables Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 
 */

package play.libs.ws;

import org.apache.pekko.stream.javadsl.Source;
import org.apache.pekko.util.ByteString;
import play.mvc.Http;
import play.mvc.MultipartFormatter;

/** JSON, XML and Multipart Form Data Writables used for Play-WS bodies. */
public interface WSBodyWritables extends DefaultBodyWritables, XMLBodyWritables, JsonBodyWritables {

  default SourceBodyWritable multipartBody(
      Source>, ?> body) {
    String boundary = MultipartFormatter.randomBoundary();
    Source source = MultipartFormatter.transform(body, boundary);
    String contentType = "multipart/form-data; boundary=" + boundary;
    return new SourceBodyWritable(source, contentType);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy