Package com.google.cloud.functions
Interface HttpMessage
- All Known Subinterfaces:
HttpRequest,HttpRequest.HttpPart
public interface HttpMessage
Represents an HTTP message, either an HTTP request or a part of a multipart HTTP request.
-
Method Summary
Modifier and Type Method Description java.util.Optional<java.lang.String>getCharacterEncoding()Returns the character encoding specified in theContent-Typeheader, orOptional.empty()if there is noContent-Typeheader or it does not have thecharsetparameter.longgetContentLength()Returns the numeric value of theContent-Lengthheader.java.util.Optional<java.lang.String>getContentType()Returns the value of theContent-Typeheader, if any.default java.util.Optional<java.lang.String>getFirstHeader(java.lang.String name)Convenience method that returns the value of the first header with the given name.java.util.Map<java.lang.String,java.util.List<java.lang.String>>getHeaders()Returns a map describing the headers of this HTTP request, or this part of a multipart request.java.io.InputStreamgetInputStream()Returns anInputStreamthat can be used to read the body of this HTTP request.java.io.BufferedReadergetReader()Returns aBufferedReaderthat can be used to read the text body of this HTTP request.
-
Method Details
-
getContentType
java.util.Optional<java.lang.String> getContentType()Returns the value of theContent-Typeheader, if any.- Returns:
- the content type, if any.
-
getContentLength
long getContentLength()Returns the numeric value of theContent-Lengthheader.- Returns:
- the content length.
-
getCharacterEncoding
java.util.Optional<java.lang.String> getCharacterEncoding()Returns the character encoding specified in theContent-Typeheader, orOptional.empty()if there is noContent-Typeheader or it does not have thecharsetparameter.- Returns:
- the character encoding for the content type, if one is specified.
-
getInputStream
Returns anInputStreamthat can be used to read the body of this HTTP request. Every call to this method on the sameHttpMessagewill return the same object. This method is typically used to read binary data. If the body is text, thegetReader()method is more appropriate.- Returns:
- an
InputStreamthat can be used to read the body of this HTTP request. - Throws:
java.io.IOException- if a validInputStreamcannot be returned for some reason.java.lang.IllegalStateException- ifgetReader()has already been called on this instance.
-
getReader
Returns aBufferedReaderthat can be used to read the text body of this HTTP request. Every call to this method on the sameHttpMessagewill return the same object.- Returns:
- a
BufferedReaderthat can be used to read the text body of this HTTP request. - Throws:
java.io.IOException- if a validBufferedReadercannot be returned for some reason.java.lang.IllegalStateException- ifgetInputStream()has already been called on this instance.
-
getHeaders
java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders()Returns a map describing the headers of this HTTP request, or this part of a multipart request. If the headers look like this...Content-Type: text/plain Some-Header: some value Some-Header: another value
...then the returned value will map"Content-Type"to a one-element list containing"text/plain", and"Some-Header"to a two-element list containing"some value"and"another value".- Returns:
- a map where each key is an HTTP header and the corresponding
Listvalue has one element for each occurrence of that header.
-
getFirstHeader
Convenience method that returns the value of the first header with the given name. If the headers look like this...Content-Type: text/plain Some-Header: some value Some-Header: another value
...thengetFirstHeader("Some-Header")will returnOptional.of("some value"), andgetFirstHeader("Another-Header")will returnOptional.empty().- Parameters:
name- an HTTP header name.- Returns:
- the first value of the given header, if present.
-