zio-http icon indicating copy to clipboard operation
zio-http copied to clipboard

Body: expose method to get contents if materialized

Open hearnadam opened this issue 9 months ago • 2 comments

Is your feature request related to a problem? Please describe. For internal debugging logic of our application (using zio-http as a client), we use the Request Body to generate reproducer queries.

However, since we know the body is already materialized, we don't want to run asString. Instead, we match on the internal zio-http classes:

    def body = request.body match {
      case asciiBody: AsciiStringBody => asciiBody.asciiString.toString
      case default => default.toString
    }

This is sub-optimal as it can break during upgrades + abuses the zio namespace.

Describe the solution you'd like Add a method to produce Option[String] for already materialized bodies. IIRC the asciiBody is url encoded, so something like:

def URLEncodedString: Option[String] would be very helpful.

Describe alternatives you've considered Continue using pattern match on internal classes, or evaluate the toString method.

Additional context Add any other context or screenshots about the feature request here.

hearnadam avatar Mar 24 '25 18:03 hearnadam

@hearnadam is there any worth for you to have a url encoded string or could we have a more generic solution, so we can delegate it to the body impl? So just plain string and AsciiStringBody would decode because it is impl. detail.

987Nabil avatar Nov 30 '25 08:11 987Nabil

@987Nabil I am not sure I understand the question. Our use of the AsciiStringBody is to generate the url encoded post url.

hearnadam avatar Dec 01 '25 18:12 hearnadam