forked from square/retrofit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request square#35 from square/rdickerson/profiler-data
Adding a beforeCall() to HttpProfiler.
- Loading branch information
Showing
2 changed files
with
113 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,27 @@ | |
* | ||
* @author Eric Burke ([email protected]) | ||
*/ | ||
public interface HttpProfiler { | ||
public interface HttpProfiler<T> { | ||
|
||
/** | ||
* Invoked before an HTTP method call. The object returned by this method will be | ||
* passed to {@link #afterCall} when the call returns. | ||
* | ||
* This method gives implementors the opportunity to include information that may | ||
* change during the server call in {@code afterCall} logic. | ||
*/ | ||
T beforeCall(); | ||
|
||
/** | ||
* Invoked after an HTTP method completes. This is called from the | ||
* RestAdapter's background thread. | ||
* | ||
* @param requestInfo information about the originating HTTP request. | ||
* @param elapsedTime time in milliseconds it took the HTTP request to complete. | ||
* @param statusCode response status code. | ||
* @param beforeCallData the data returned by the corresponding {@link #beforeCall()}. | ||
*/ | ||
void afterCall(RequestInformation requestInfo, long elapsedTime, int statusCode, T beforeCallData); | ||
|
||
/** The HTTP method. */ | ||
public enum Method { | ||
|
@@ -17,16 +37,46 @@ public enum Method { | |
PUT | ||
} | ||
|
||
/** | ||
* Invoked after an HTTP method completes. This is called from the | ||
* RestAdapter's background thread. | ||
* | ||
* @param method the HTTP method (POST, GET, etc). | ||
* @param baseUrl the URL that was called. | ||
* @param relativePath the path part of the URL. | ||
* @param elapsedTime time in milliseconds. | ||
* @param statusCode response status code. | ||
*/ | ||
void called(Method method, String baseUrl, String relativePath, | ||
long elapsedTime, int statusCode); | ||
/** Information about the HTTP request. */ | ||
public static final class RequestInformation { | ||
private final Method method; | ||
private final String baseUrl; | ||
private final String relativePath; | ||
private final long contentLength; | ||
private final String contentType; | ||
|
||
public RequestInformation(Method method, String baseUrl, String relativePath, long contentLength, | ||
String contentType) { | ||
this.method = method; | ||
this.baseUrl = baseUrl; | ||
this.relativePath = relativePath; | ||
this.contentLength = contentLength; | ||
this.contentType = contentType; | ||
} | ||
|
||
/** Returns the HTTP method of the originating request. */ | ||
public Method getMethod() { | ||
return method; | ||
} | ||
|
||
/** Returns the URL to which the originating request was sent. */ | ||
public String getBaseUrl() { | ||
return baseUrl; | ||
} | ||
|
||
/** Returns the path relative to the base URL to which the originating request was sent. */ | ||
public String getRelativePath() { | ||
return relativePath; | ||
} | ||
|
||
/** Returns the number of bytes in the originating request. */ | ||
public long getContentLength() { | ||
return contentLength; | ||
} | ||
|
||
/** Returns the content type header value of the originating request. */ | ||
public String getContentType() { | ||
return contentType; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters