public Builder setQop(String qop) { if (isNonEmpty(qop)) { this.qop = qop; } return this; }
@Override public boolean hasResponseBody() { return isNonEmpty(bodyParts); }
public String getNonEmptyPath() { return isNonEmpty(path) ? path : "/"; }
private String cookiePath(String rawCookiePath, String requestPath) { if (MiscUtils.isNonEmpty(rawCookiePath) && rawCookiePath.charAt(0) == '/') { return rawCookiePath; } else { // rfc6265#section-5.1.4 int indexOfLastSlash = requestPath.lastIndexOf('/'); if (!requestPath.isEmpty() && requestPath.charAt(0) == '/' && indexOfLastSlash > 0) return requestPath.substring(0, indexOfLastSlash); else return "/"; } }
public String toRelativeUrl() { StringBuilder sb = StringBuilderPool.DEFAULT.stringBuilder(); if (MiscUtils.isNonEmpty(path)) sb.append(path); else sb.append('/'); if (query != null) sb.append('?').append(query); return sb.toString(); }
private void computeRegularPath() { if (originalUrl.charAt(currentIndex) == '/') { path = originalUrl.substring(currentIndex, end); } else if (isNonEmpty(path)) { handleRelativePath(); } else { String pathEnd = originalUrl.substring(currentIndex, end); path = isNonEmpty(pathEnd) && pathEnd.charAt(0) != '/' ? "/" + pathEnd : pathEnd; } handlePathDots(); }
private String withoutQuery(final List<Param> queryParams) { return isNonEmpty(queryParams) ? withoutQueryWithParams(queryParams) : null; }
/** * @return [scheme]://[hostname](:[port])/path. Port is omitted if it matches the scheme's default one. */ public String toBaseUrl() { StringBuilder sb = StringBuilderPool.DEFAULT.stringBuilder(); sb.append(scheme).append("://").append(host); if (port != -1 && port != getSchemeDefaultPort()) { sb.append(':').append(port); } if (isNonEmpty(path)) { sb.append(path); } return sb.toString(); }
private List<Cookie> buildCookies() { List<String> setCookieHeaders = headers.getAll(SET_COOKIE2); if (!isNonEmpty(setCookieHeaders)) { setCookieHeaders = headers.getAll(SET_COOKIE); } if (isNonEmpty(setCookieHeaders)) { List<Cookie> cookies = new ArrayList<>(1); for (String value : setCookieHeaders) { Cookie c = ClientCookieDecoder.STRICT.decode(value); if (c != null) cookies.add(c); } return Collections.unmodifiableList(cookies); } return Collections.emptyList(); }
@Override public List<Param> getQueryParams() { if (queryParams == null) // lazy load if (isNonEmpty(uri.getQuery())) { queryParams = new ArrayList<>(1); for (String queryStringParam : uri.getQuery().split("&")) { int pos = queryStringParam.indexOf('='); if (pos <= 0) queryParams.add(new Param(queryStringParam, null)); else queryParams.add(new Param(queryStringParam.substring(0, pos), queryStringParam.substring(pos + 1))); } } else queryParams = Collections.emptyList(); return queryParams; }
private String encodeQuery(final String query, final List<Param> queryParams) { return isNonEmpty(query) ? withQuery(query, queryParams) : withoutQuery(queryParams); } }
private String withQuery(final String query, final List<Param> queryParams) { return isNonEmpty(queryParams) ? withQueryWithParams(query, queryParams) : withQueryWithoutParams(query); }
public T setQueryParams(List<Param> params) { // reset existing query if (this.uri != null && isNonEmpty(this.uri.getQuery())) this.uri = this.uri.withNewQuery(null); queryParams = params; return asDerivedType(); }
public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if ("POST".equalsIgnoreCase(request.getMethod())) { String p = request.getParameter("test"); if (isNonEmpty(p)) { response.setStatus(HttpServletResponse.SC_OK); response.addHeader("X-Param", p); } else { response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE); } } else { // this handler is to handle POST request response.sendError(HttpServletResponse.SC_FORBIDDEN); } response.getOutputStream().flush(); response.getOutputStream().close(); } }
public static String computeRealmURI(Uri uri, boolean useAbsoluteURI, boolean omitQuery) { if (useAbsoluteURI) { return omitQuery && MiscUtils.isNonEmpty(uri.getQuery()) ? uri.withNewQuery(null).toUrl() : uri.toUrl(); } else { String path = uri.getNonEmptyPath(); return omitQuery || !MiscUtils.isNonEmpty(uri.getQuery()) ? path : path + "?" + uri.getQuery(); } }
public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if ("GET".equalsIgnoreCase(request.getMethod())) { String qs = request.getQueryString(); if (isNonEmpty(qs)) { for (String qnv : qs.split("&")) { String nv[] = qnv.split("="); response.addHeader(nv[0], nv[1]); } response.setStatus(HttpServletResponse.SC_OK); } else { response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE); } } else { // this handler is to handle POST request response.sendError(HttpServletResponse.SC_FORBIDDEN); } r.setHandled(true); } }
protected void visitCustomHeaders(PartVisitor visitor) { if (isNonEmpty(part.getCustomHeaders())) { for (Param param : part.getCustomHeaders()) { visitor.withBytes(CRLF_BYTES); visitor.withBytes(param.getName().getBytes(US_ASCII)); visitor.withBytes(HEADER_NAME_VALUE_SEPARATOR_BYTES); visitor.withBytes(param.getValue().getBytes(US_ASCII)); } } }
private boolean overrideWithContext(Uri context) { boolean isRelative = false; // use context only if schemes match if (context != null && (scheme == null || scheme.equalsIgnoreCase(context.getScheme()))) { // see RFC2396 5.2.3 String contextPath = context.getPath(); if (isNonEmpty(contextPath) && contextPath.charAt(0) == '/') { scheme = null; } if (scheme == null) { scheme = context.getScheme(); userInfo = context.getUserInfo(); host = context.getHost(); port = context.getPort(); path = contextPath; isRelative = true; } } return isRelative; }
public Builder parseProxyAuthenticateHeader(String headerLine) { setRealmName(match(headerLine, "realm")) .setNonce(match(headerLine, "nonce")) .setOpaque(match(headerLine, "opaque")) .setScheme(isNonEmpty(nonce) ? AuthScheme.DIGEST : AuthScheme.BASIC); String algorithm = match(headerLine, "algorithm"); if (isNonEmpty(algorithm)) { setAlgorithm(algorithm); } // FIXME qop is different with proxy? setQop(match(headerLine, "qop")); return this; }
public Builder parseWWWAuthenticateHeader(String headerLine) { setRealmName(match(headerLine, "realm")) .setNonce(match(headerLine, "nonce")) .setOpaque(match(headerLine, "opaque")) .setScheme(isNonEmpty(nonce) ? AuthScheme.DIGEST : AuthScheme.BASIC); String algorithm = match(headerLine, "algorithm"); if (isNonEmpty(algorithm)) { setAlgorithm(algorithm); } // FIXME qop is different with proxy? String rawQop = match(headerLine, "qop"); if (rawQop != null) { setQop(parseRawQop(rawQop)); } return this; }