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 classDeprecated. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedGitHubConnectorResponse(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.voidclose()Gets the value of a header field for this response.booleanThe body stream rereadable state.final intParse a header value as a signed decimal integer.protected abstract InputStreamGet the raw implementation specific body stream for this response.request()Gets theGitHubConnectorfor this response.voidForce body stream to rereadable regardless of status code.intThe status code for this response.protected InputStreamwrapStream(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
-
allHeaders
The headers for this response.- Returns:
- the headers for this response.
-
bodyStream
The response body as anInputStream. WhenisBodyStreamRereadableis 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. WhenisBodyStreamRereadableis 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.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
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
nullif the header isn't set.
-
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 forceisBodyStreamRereadableto be true for this response regardless ofstatusCodevalue.- Returns:
- true when body stream is rereadable.
-
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.
-
request
Gets theGitHubConnectorfor this response.- Returns:
- the
GitHubConnectorfor this response.
-
setBodyStreamRereadable
public void setBodyStreamRereadable()Force body stream to rereadable regardless of status code. CallingsetBodyStreamRereadable()will forceisBodyStreamRereadableto be true for this response regardless ofstatusCodevalue. 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(). -
statusCode
public int statusCode()The status code for this response.- Returns:
- the status code for this response.
-
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.
-
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.
-
GitHubConnectorResponse.