/** * Gets the originating "X-Forwarded-..." header from the request. If there are multiple headers the originating * header is the first header. If the originating header contains a comma separated list, the originating entry * is the first one. * @param req the request * @param header the header name * @param defaultValue the value to return if the header is absent. * @return the originating entry of the header or the default value if the header was not present. */ private static String getXForwardedHeader(StaplerRequest req, String header, String defaultValue) { String value = req.getHeader(header); if (value != null) { int index = value.indexOf(','); return index == -1 ? value.trim() : value.substring(0,index).trim(); } return defaultValue; }
private boolean doesNotSupportPostMessage() { StaplerRequest req = Stapler.getCurrentRequest(); if (req==null) return false; String ua = req.getHeader("User-Agent"); if (ua==null) return false; // according to http://caniuse.com/#feat=x-doc-messaging, IE <=7 doesn't support pstMessage // see http://www.useragentstring.com/pages/Internet%20Explorer/ for user agents // we want to err on the cautious side here. // Because of JENKINS-15105, we can't serve signed metadata from JSON, which means we need to be // using a modern browser as a vehicle to request these data. This check is here to prevent Jenkins // from using older browsers that are known not to support postMessage as the vehicle. return ua.contains("Windows") && (ua.contains(" MSIE 5.") || ua.contains(" MSIE 6.") || ua.contains(" MSIE 7.")); }
/** * Changes the icon size by changing the cookie */ public void doIconSize( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { String qs = req.getQueryString(); if(qs==null) throw new ServletException(); Cookie cookie = new Cookie("iconSize", Functions.validateIconSize(qs)); cookie.setMaxAge(/* ~4 mo. */9999999); // #762 rsp.addCookie(cookie); String ref = req.getHeader("Referer"); if(ref==null) ref="."; rsp.sendRedirect2(ref); }
UUID uuid = UUID.fromString(req.getHeader("Session")); rsp.setHeader("Hudson-Duplex", "true"); // set the header so that the client would know if (req.getHeader("Side").equals("download")) { FullDuplexHttpService service = createService(req, uuid); LOGGER.log(Level.FINE, "Processing download side for {0}: {1}", new Object[] {uuid, service});
private ConsoleAnnotator<T> createAnnotator(StaplerRequest req) throws IOException { try { String base64 = req!=null ? req.getHeader("X-ConsoleAnnotator") : null; if (base64!=null) { Cipher sym = PASSING_ANNOTATOR.decrypt(); ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream( new CipherInputStream(new ByteArrayInputStream(Base64.decode(base64.toCharArray())),sym)), Jenkins.getInstance().pluginManager.uberClassLoader); try { long timestamp = ois.readLong(); if (TimeUnit.HOURS.toMillis(1) > abs(System.currentTimeMillis()-timestamp)) // don't deserialize something too old to prevent a replay attack return (ConsoleAnnotator)ois.readObject(); } finally { ois.close(); } } } catch (ClassNotFoundException e) { throw new IOException(e); } // start from scratch return ConsoleAnnotator.initial(context); }
private WebHookAction onPost(Item project, StaplerRequest request) { String eventHeader = request.getHeader("X-Gitlab-Event"); if (eventHeader == null) { LOGGER.log(Level.FINE, "Missing X-Gitlab-Event header"); return new NoopAction(); } String tokenHeader = request.getHeader("X-Gitlab-Token"); switch (eventHeader) { case "Merge Request Hook": return new MergeRequestBuildAction(project, getRequestBody(request), tokenHeader); case "Push Hook": case "Tag Push Hook": return new PushBuildAction(project, getRequestBody(request), tokenHeader); case "Note Hook": return new NoteBuildAction(project, getRequestBody(request), tokenHeader); case "Pipeline Hook": return new PipelineBuildAction(project, getRequestBody(request), tokenHeader); case "System Hook": return onSystemHook(project, getRequestBody(request), tokenHeader); default: LOGGER.log(Level.FINE, "Unsupported X-Gitlab-Event header: {0}", eventHeader); return new NoopAction(); } }
public static void initPageVariables(JellyContext context) { StaplerRequest currentRequest = Stapler.getCurrentRequest(); String rootURL = currentRequest.getContextPath(); Functions h = new Functions(); context.setVariable("h", h); // The path starts with a "/" character but does not end with a "/" character. context.setVariable("rootURL", rootURL); /* load static resources from the path dedicated to a specific version. This "/static/VERSION/abc/def.ghi" path is interpreted by stapler to be the same thing as "/abc/def.ghi", but this avoids the stale cache problem when the user upgrades to new Jenkins. Stapler also sets a long future expiration dates for such static resources. see https://wiki.jenkins-ci.org/display/JENKINS/Hyperlinks+in+HTML */ context.setVariable("resURL",rootURL+getResourcePath()); context.setVariable("imagesURL",rootURL+getResourcePath()+"/images"); context.setVariable("userAgent", currentRequest.getHeader("User-Agent")); IconSet.initPageVariables(context); }
/** * Checks if tracing is enabled for the given request. Tracing can be * enabled globally with the "stapler.trace=true" system property. Tracing * can be enabled per-request by setting "stapler.trace.per-request=true" * and sending an "X-Stapler-Trace" header set to "true" with the request. */ public static boolean isTraceEnabled(StaplerRequest req) { if (TRACE) return true; if (TRACE_PER_REQUEST && "true".equals(req.getHeader("X-Stapler-Trace"))) return true; return false; }
private boolean requestWantsJson(StaplerRequest req) { String a = req.getHeader("Accept"); if (a==null) return false; return !a.contains("text/html") && a.contains("application/json"); }
private boolean requestWantsJson(StaplerRequest req) { String a = req.getHeader("Accept"); if (a==null) return false; return !a.contains("text/html") && a.contains("application/json"); }
private boolean doesNotSupportPostMessage() { StaplerRequest req = Stapler.getCurrentRequest(); if (req==null) return false; String ua = req.getHeader("User-Agent"); if (ua==null) return false; // according to http://caniuse.com/#feat=x-doc-messaging, IE <=7 doesn't support pstMessage // see http://www.useragentstring.com/pages/Internet%20Explorer/ for user agents // we want to err on the cautious side here. // Because of JENKINS-15105, we can't serve signed metadata from JSON, which means we need to be // using a modern browser as a vehicle to request these data. This check is here to prevent Jenkins // from using older browsers that are known not to support postMessage as the vehicle. return ua.contains("Windows") && (ua.contains(" MSIE 5.") || ua.contains(" MSIE 6.") || ua.contains(" MSIE 7.")); }
public void forwardToPreviousPage(StaplerRequest request) throws ServletException, IOException { String referer = request.getHeader("Referer"); if(referer==null) referer="."; sendRedirect(referer); }
public void forwardToPreviousPage(StaplerRequest request) throws ServletException, IOException { String referer = request.getHeader("Referer"); if(referer==null) referer="."; sendRedirect(referer); }
public void forwardToPreviousPage(StaplerRequest request) throws ServletException, IOException { String referer = request.getHeader("Referer"); if(referer==null) referer="."; sendRedirect(referer); }
protected void check(StaplerRequest request) throws InvocationTargetException { if (!request.getMethod().equals("POST")) { throw new InvocationTargetException(error(SC_METHOD_NOT_ALLOWED, "Method POST required")); } if (request.getHeader("User-Agent") == null || request.getHeader("User-Agent").toLowerCase().indexOf("coding") == -1 ){ throw new InvocationTargetException(error(SC_METHOD_NOT_ALLOWED, "From Coding.Net required")); } }
Object parse(StaplerRequest request, Header a, Class type, String parameterName) throws ServletException { String name = a.value(); if(name.length()==0) name=parameterName; if(name==null) throw new IllegalArgumentException("Parameter name unavailable neither in the code nor in annotation"); String value = request.getHeader(name); if(a.required() && value==null) throw new ServletException("Required HTTP header "+name+" is missing"); return convert(type,value); } });
public Object parse(StaplerRequest request, Header a, Class type, String parameterName) throws ServletException { String name = a.value(); if(name.length()==0) name=parameterName; if(name==null) throw new IllegalArgumentException("Parameter name unavailable neither in the code nor in annotation"); String value = request.getHeader(name); if(a.required() && value==null) throw new ServletException("Required HTTP header "+name+" is missing"); return convert(type,value); } }
public Object parse(StaplerRequest request, Header a, Class type, String parameterName) throws ServletException { String name = a.value(); if(name.length()==0) name=parameterName; if(name==null) throw new IllegalArgumentException("Parameter name unavailable neither in the code nor in annotation"); String value = request.getHeader(name); if(a.required() && value==null) throw new ServletException("Required HTTP header "+name+" is missing"); return convert(type,value); } }
public void doIndex(final StaplerRequest req, final StaplerResponse response) throws IOException { String payload = req.getParameter("payload"); if (StringUtils.isEmpty(payload) && "POST".equalsIgnoreCase(req.getMethod())) { payload = getRequestPayload(req); } if (StringUtils.isEmpty(payload)) { throw new IllegalArgumentException("Not intended to be browsed interactively (must specify payload parameter)"); } processGitHubPayload(req.getHeader("X-GitHub-Event"), payload); }
/** * Changes the icon size by changing the cookie */ public void doIconSize( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { String qs = req.getQueryString(); if(qs==null) throw new ServletException(); Cookie cookie = new Cookie("iconSize", Functions.validateIconSize(qs)); cookie.setMaxAge(/* ~4 mo. */9999999); // #762 rsp.addCookie(cookie); String ref = req.getHeader("Referer"); if(ref==null) ref="."; rsp.sendRedirect2(ref); }