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
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.Optional<java.lang.String>
getCharacterEncoding()
Returns the character encoding specified in theContent-Type
header, orOptional.empty()
if there is noContent-Type
header or it does not have thecharset
parameter.long
getContentLength()
Returns the numeric value of theContent-Length
header.java.util.Optional<java.lang.String>
getContentType()
Returns the value of theContent-Type
header, 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.InputStream
getInputStream()
Returns anInputStream
that can be used to read the body of this HTTP request.java.io.BufferedReader
getReader()
Returns aBufferedReader
that can be used to read the text body of this HTTP request.
-
-
-
Method Detail
-
getContentType
java.util.Optional<java.lang.String> getContentType()
Returns the value of theContent-Type
header, if any.- Returns:
- the content type, if any.
-
getContentLength
long getContentLength()
Returns the numeric value of theContent-Length
header.- Returns:
- the content length.
-
getCharacterEncoding
java.util.Optional<java.lang.String> getCharacterEncoding()
Returns the character encoding specified in theContent-Type
header, orOptional.empty()
if there is noContent-Type
header or it does not have thecharset
parameter.- Returns:
- the character encoding for the content type, if one is specified.
-
getInputStream
java.io.InputStream getInputStream() throws java.io.IOException
Returns anInputStream
that can be used to read the body of this HTTP request. Every call to this method on the sameHttpMessage
will 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
InputStream
that can be used to read the body of this HTTP request. - Throws:
java.io.IOException
- if a validInputStream
cannot be returned for some reason.java.lang.IllegalStateException
- ifgetReader()
has already been called on this instance.
-
getReader
java.io.BufferedReader getReader() throws java.io.IOException
Returns aBufferedReader
that can be used to read the text body of this HTTP request. Every call to this method on the sameHttpMessage
will return the same object.- Returns:
- a
BufferedReader
that can be used to read the text body of this HTTP request. - Throws:
java.io.IOException
- if a validBufferedReader
cannot 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
List
value has one element for each occurrence of that header.
-
getFirstHeader
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. 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.
-
-