Skip to content

Commit

Permalink
Merge pull request #35 from christ66/JENKINS-28876
Browse files Browse the repository at this point in the history
[JENKINS-28876] Add user-agent information to slow-requests.
  • Loading branch information
christ66 committed Jun 15, 2015
2 parents 62e67ad + 8e0f309 commit 153bbf7
Showing 1 changed file with 10 additions and 0 deletions.
Expand Up @@ -2,6 +2,8 @@

import com.google.common.net.HttpHeaders;
import jenkins.model.Jenkins;
import net.sf.uadetector.ReadableUserAgent;
import net.sf.uadetector.service.UADetectorServiceFactory;
import org.kohsuke.stapler.StaplerRequest;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -50,17 +52,25 @@ final class InflightRequest {
*/
final String referer;

/**
* User Agent that invoked the slow request.
*/
final ReadableUserAgent userAgent;

InflightRequest(HttpServletRequest req) {
String query = req.getQueryString();
url = req.getRequestURL() + (query == null ? "" : "?" + query);
startTime = System.currentTimeMillis();
userName = Jenkins.getAuthentication().getName();
referer = req.getHeader("Referer");
String agentHeader = req.getHeader("User-Agent");
userAgent = UADetectorServiceFactory.getResourceModuleParser().parse(agentHeader);
}

void writeHeader(PrintWriter w) {
w.println("Username: " + userName);
w.println("Referer: " + referer);
w.println("User Agent: " + userAgent);
w.println("Date: " + new Date());
w.println("URL: " + url);
w.println();
Expand Down

0 comments on commit 153bbf7

Please sign in to comment.