Skip to content

Body: expose method to get contents if materialized #3431

@hearnadam

Description

@hearnadam

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions