/** * Adds many query parameters at once. Although it accepts objects, each value will be converted * to string. */ public HttpRequest query(String name1, Object value1, Object... parameters) { query(name1, value1 == null ? null : value1.toString()); for (int i = 0; i < parameters.length; i += 2) { String name = parameters[i].toString(); String value = parameters[i + 1].toString(); query.add(name, value == null ? null : value); } return this; }
/** Prepares the request buffer. */ @Override protected Buffer buffer(boolean fullRequest) { // INITIALIZATION // host port if (header(HEADER_HOST) == null) { setHostHeader(); } // form Buffer formBuffer = formBuffer(); // query string String queryString = queryString(); // user-agent if (header("User-Agent") == null) { header("User-Agent", "Jodd HTTP"); } // POST method requires Content-Type to be set if (method.equals("POST") && (contentLength() == null)) { contentLength(0); } // BUILD OUT Buffer request = new Buffer(); request.append(method).append(SPACE).append(path); if (query != null && !query.isEmpty()) { request.append('?'); request.append(queryString); } request.append(SPACE).append(httpVersion).append(CRLF); populateHeaderAndBody(request, formBuffer, fullRequest); return request; }
/** * Sets request path. Query string is allowed. Adds a slash if path doesn't start with one. Query * will be stripped out from the path. Previous query is discarded. * * @see #query() */ public HttpRequest path(String path) { // this must be the only place that sets the path if (!path.startsWith(StringPool.SLASH)) { path = StringPool.SLASH + path; } int ndx = path.indexOf('?'); if (ndx != -1) { String queryString = path.substring(ndx + 1); path = path.substring(0, ndx); query = HttpUtil.parseQuery(queryString, true); } else { query = HttpMultiMap.newCaseInsensitveMap(); } this.path = path; return this; }
/** Removes query parameters for given name. */ public HttpRequest removeQuery(String name) { query.remove(name); return this; }
/** Clears all query parameters. */ public HttpRequest clearQueries() { query.clear(); return this; }
/** Adds all parameters from the provided map. */ public HttpRequest query(Map<String, String> queryMap) { for (Map.Entry<String, String> entry : queryMap.entrySet()) { query.add(entry.getKey(), entry.getValue()); } return this; }
/** Adds query parameter. */ public HttpRequest query(String name, String value) { query.add(name, value); return this; }