java.lang.Object
org.kohsuke.github.connector.GitHubConnectorResponse
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
GitHubConnectorResponse.ByteArrayResponse
Response information supplied when a response is received and before the body is processed.
During a request to GitHub, GitHubConnector.send(GitHubConnectorRequest)
returns a
GitHubConnectorResponse
. This is processed to create a GitHubResponse.
Instances of this class are closed once the response is done being processed. This means that bodyStream()
will not be readable after a call is completed.
statusCode()
, allHeaders()
, and request()
will still be readable but it is recommended
that consumers copy any information they need rather than retaining a reference to GitHubConnectorResponse
.
- Author:
- Liam Newman
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Deprecated. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
GitHubConnectorResponse
(GitHubConnectorRequest request, int statusCode, Map<String, List<String>> headers) GitHubConnectorResponse constructor -
Method Summary
Modifier and TypeMethodDescriptionThe headers for this response.The response body as anInputStream
.void
close()
Gets the value of a header field for this response.boolean
The body stream rereadable state.final int
Parse a header value as a signed decimal integer.protected abstract InputStream
Get the raw implementation specific body stream for this response.request()
Gets theGitHubConnector
for this response.void
Force body stream to rereadable regardless of status code.int
The status code for this response.protected InputStream
wrapStream
(InputStream stream) Handles wrapping the body stream if indicated by the "Content-Encoding" header.
-
Constructor Details
-
GitHubConnectorResponse
protected GitHubConnectorResponse(@Nonnull GitHubConnectorRequest request, int statusCode, @Nonnull Map<String, List<String>> headers) GitHubConnectorResponse constructor- Parameters:
request
- the requeststatusCode
- the status codeheaders
- the headers
-
-
Method Details
-
header
Gets the value of a header field for this response.- Parameters:
name
- the name of the header field.- Returns:
- the value of the header field, or
null
if the header isn't set.
-
bodyStream
The response body as anInputStream
. WhenisBodyStreamRereadable
is false,bodyStream()
can only be called once and the returned stream should be assumed to be read-once and not resetable. This is the default behavior for HTTP_OK responses and significantly reduces memory usage. WhenisBodyStreamRereadable
is true,bodyStream()
can be called be called multiple times. The full stream data is read into a byte array during the first call. Each call returns a new stream backed by the same byte array. This uses more memory, but is required to enable rereading the body stream during trace logging, debugging, and error responses.- Returns:
- the response body
- Throws:
IOException
- if response stream is null or an I/O Exception occurs.
-
rawBodyStream
Get the raw implementation specific body stream for this response. This method will only be called once to completion. If an exception is thrown by this method, it may be called multiple times. The stream returned from this method will be closed when the response is closed or sooner. Inheriting classes do not need to close it.- Returns:
- the stream for the raw response
- Throws:
IOException
- if an I/O Exception occurs.
-
request
Gets theGitHubConnector
for this response.- Returns:
- the
GitHubConnector
for this response.
-
statusCode
public int statusCode()The status code for this response.- Returns:
- the status code for this response.
-
allHeaders
The headers for this response.- Returns:
- the headers for this response.
-
isBodyStreamRereadable
public boolean isBodyStreamRereadable()The body stream rereadable state. Body stream defaults to read once for HTTP_OK responses (to reduce memory usage). For non-HTTP_OK responses, body stream is switched to rereadable (in-memory byte array) for error processing. CallingsetBodyStreamRereadable()
will forceisBodyStreamRereadable
to be true for this response regardless ofstatusCode
value.- Returns:
- true when body stream is rereadable.
-
setBodyStreamRereadable
public void setBodyStreamRereadable()Force body stream to rereadable regardless of status code. CallingsetBodyStreamRereadable()
will forceisBodyStreamRereadable
to be true for this response regardless ofstatusCode
value. This is required to support body value logging during low-level tracing but should be avoided in general since it consumes significantly more memory. Will throw runtime exception if a non-rereadable body stream has already been returned frombodyStream()
. -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
wrapStream
Handles wrapping the body stream if indicated by the "Content-Encoding" header.- Parameters:
stream
- the stream to possibly wrap- Returns:
- an input stream potentially wrapped to decode gzip input
- Throws:
IOException
- if an I/O Exception occurs.
-
parseInt
Parse a header value as a signed decimal integer.- Parameters:
name
- the header field to parse- Returns:
- integer value of the header field
- Throws:
NumberFormatException
- if the header is missing or does not contain a parsable integer.
-
GitHubConnectorResponse
.