Package com.styra.opa.openapi.utils
Class Helpers
java.lang.Object
com.styra.opa.openapi.utils.Helpers
Public helper methods for use by customers and end-users.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
bodyBytes
(HttpRequest request) Returns the request body as a byte array.static String
bodyUtf8
(HttpRequest request) Returns the request body as a String assuming that the bytes of the request body are encoded with UTF-8.static HttpRequest.Builder
copy
(HttpRequest request) Returns anHttpRequest.Builder
which is initialized with the state of the givenHttpRequest
.static HttpRequest.Builder
copy
(HttpRequest request, BiPredicate<String, String> filter) Returns anHttpRequest.Builder
which is initialized with the state of the givenHttpRequest
.
-
Constructor Details
-
Helpers
public Helpers()
-
-
Method Details
-
copy
Returns anHttpRequest.Builder
which is initialized with the state of the givenHttpRequest
.Note that headers can be added and modified but not removed. To remove headers use
copy(HttpRequest, BiPredicate)
(which applies a filter to the headers while copying).Note also that this method is redundant from JDK 16 because the method
HttpRequest.newBuilder(HttpRequest)
is available.- Parameters:
request
- request to copy- Returns:
- a builder initialized with values from
request
-
copy
Returns anHttpRequest.Builder
which is initialized with the state of the givenHttpRequest
.Note that this method is redundant from JDK 16 because the method
HttpRequest.newBuilder(HttpRequest, BiPredicate)
is available.- Parameters:
request
- request to copyfilter
- selects which header key-values to include in the copied request- Returns:
- a builder initialized with values from
request
-
bodyBytes
Returns the request body as a byte array.- Parameters:
request
- http request to extract from- Returns:
- byte array
-
bodyUtf8
Returns the request body as a String assuming that the bytes of the request body are encoded with UTF-8.- Parameters:
request
- http request to extract from- Returns:
- request body as a String
-