Skip to content

Commit

Permalink
Get string representation of javadsl Content and Media Type
Browse files Browse the repository at this point in the history
  • Loading branch information
mdedetrich committed Nov 27, 2024
1 parent 4fb8554 commit 6e2888c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void customMediaTypes() throws ExecutionException, InterruptedException {
extractRequest(
req ->
complete(
req.entity().getContentType().toString()
req.entity().getContentType().value()
+ " = "
+ req.entity().getContentType().getClass()));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.pekko.http.javadsl.model.ContentType.value")
ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.pekko.http.javadsl.model.MediaType.value")
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package org.apache.pekko.http.javadsl.model

import org.apache.pekko.annotation.DoNotInherit

import java.util.Optional

// Has to be defined in Scala even though it's JavaDSL because of:
Expand Down Expand Up @@ -45,6 +47,7 @@ object ContentType {
*
* See [[ContentTypes]] for convenience access to often used values.
*/
@DoNotInherit
trait ContentType {

/**
Expand All @@ -61,4 +64,10 @@ trait ContentType {
* Returns the charset if this ContentType is non-binary.
*/
def getCharsetOption: Optional[HttpCharset]

/**
* Returns the string representation of this ContentType
* @since 1.2.0
*/
def value: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package org.apache.pekko.http.javadsl.model

import org.apache.pekko.annotation.DoNotInherit

/**
* Represents an Http media-type. A media-type consists of a main-type and a sub-type.
*
Expand Down Expand Up @@ -65,6 +67,7 @@ object MediaType {
}
}

@DoNotInherit
trait MediaType {

/**
Expand Down Expand Up @@ -110,4 +113,10 @@ trait MediaType {
* Creates a media-range from this media-type with a given qValue.
*/
def toRange(qValue: Float): MediaRange

/**
* Returns the string representation of this MediaType
* @since 1.2.0
*/
def value: String
}

0 comments on commit 6e2888c

Please sign in to comment.