Skip to content

Commit

Permalink
[JENKINS-28876] Add user-agent information to slow-requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
christ66 committed Jun 15, 2015
1 parent 62e67ad commit 8e0f309
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 8e0f309

Please sign in to comment.