/** * Creates an instance of this class using the given request line. * * @param requestline request line. */ public BasicExecutionAwareRequest(final RequestLine requestline) { super(); this.requestline = Args.notNull(requestline, "Request line"); this.method = requestline.getMethod(); this.uri = requestline.getUri(); }
/** * Construct an Elasticsearch endpoint from the provided index, type and * id. * @param index - required; name of Elasticsearch index * @param type - optional; name of Elasticsearch type * @param id - optional; Elasticsearch document ID * @return the index, type and id concatenated with '/'. */ static String getEndpoint(String index, String type, String id) { requireNonNull(index); notBlank(index, "index"); StringBuilder sb = new StringBuilder(); sb.append("/").append(index); if (!(type == null || type.isEmpty())) { sb.append("/").append(type); } if (!(id == null || id.isEmpty())) { sb.append("/").append(id); } return sb.toString(); }
/** * Obtains value of the {@link CoreProtocolPNames#HTTP_CONTENT_CHARSET} parameter. * If not set, defaults to {@code ISO-8859-1}. * * @param params HTTP parameters. * @return HTTP content charset. */ public static String getContentCharset(final HttpParams params) { Args.notNull(params, "HTTP parameters"); String charset = (String) params.getParameter (CoreProtocolPNames.HTTP_CONTENT_CHARSET); if (charset == null) { charset = HTTP.DEF_CONTENT_CHARSET.name(); } return charset; }
final HttpResponse response, final HttpContext context) throws MalformedChallengeException { Args.notNull(response, "HTTP response"); final Header[] headers = response.getHeaders(this.headerName); final Map<String, Header> map = new HashMap<String, Header>(headers.length); int pos; if (header instanceof FormattedHeader) { buffer = ((FormattedHeader) header).getBuffer(); pos = ((FormattedHeader) header).getValuePos(); } else { final String s = header.getValue(); if (s == null) { throw new MalformedChallengeException("Header value is null"); buffer = new CharArrayBuffer(s.length()); buffer.append(s); pos = 0; while (pos < buffer.length() && HTTP.isWhitespace(buffer.charAt(pos))) { pos++;
public List<Cookie> parse(final Header header, final CookieOrigin origin) throws MalformedCookieException { Args.notNull(header, "Header"); Args.notNull(origin, "Cookie origin"); final String headername = header.getName(); if (!headername.equalsIgnoreCase(SM.SET_COOKIE)) { throw new MalformedCookieException("Unrecognized cookie header '" + header.toString() + "'"); HeaderElement[] helems = header.getElements(); boolean versioned = false; boolean netscape = false; final ParserCursor cursor; if (header instanceof FormattedHeader) { buffer = ((FormattedHeader) header).getBuffer(); cursor = new ParserCursor( ((FormattedHeader) header).getValuePos(), buffer.length()); } else { final String s = header.getValue(); if (s == null) { throw new MalformedCookieException("Header value is null"); buffer = new CharArrayBuffer(s.length()); buffer.append(s); cursor = new ParserCursor(0, buffer.length());
@Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { Args.notNull(request, "HTTP request"); if (!request.containsHeader(HTTP.EXPECT_DIRECTIVE)) { if (request instanceof HttpEntityEnclosingRequest) { final ProtocolVersion ver = request.getRequestLine().getProtocolVersion(); final HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity(); // Do not send the expect header if request body is known to be empty if (entity != null && entity.getContentLength() != 0 && !ver.lessEquals(HttpVersion.HTTP_1_0)) { final boolean active = request.getParams().getBooleanParameter( CoreProtocolPNames.USE_EXPECT_CONTINUE, this.activeByDefault); if (active) { request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE); } } } } }
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { Args.notNull(request, "HTTP request"); final String method = request.getRequestLine().getMethod(); if (method.equalsIgnoreCase("CONNECT")) { return; } // Add default headers @SuppressWarnings("unchecked") Collection<? extends Header> defHeaders = (Collection<? extends Header>) request.getParams().getParameter(ClientPNames.DEFAULT_HEADERS); if (defHeaders == null) { defHeaders = this.defaultHeaders; } if (defHeaders != null) { for (final Header defHeader : defHeaders) { request.addHeader(defHeader); } } }
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { Args.notNull(request, "HTTP request"); if (!request.containsHeader(HTTP.USER_AGENT)) { String s = null; final HttpParams params = request.getParams(); if (params != null) { s = (String) params.getParameter(CoreProtocolPNames.USER_AGENT); } if (s == null) { s = this.userAgent; } if (s != null) { request.addHeader(HTTP.USER_AGENT, s); } } }
public static RequestLine parseRequestLine(final String value, final LineParser parser) throws ParseException { Args.notNull(value, "Value"); final CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); final ParserCursor cursor = new ParserCursor(0, value.length()); return (parser != null ? parser : BasicLineParser.INSTANCE) .parseRequestLine(buffer, cursor); }
/** * Sets value of the {@link CoreProtocolPNames#HTTP_ELEMENT_CHARSET} parameter. * * @param params HTTP parameters. * @param charset HTTP element charset. */ public static void setHttpElementCharset(final HttpParams params, final String charset) { Args.notNull(params, "HTTP parameters"); params.setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, charset); }
@Override public List<Header> formatCookies(final List<Cookie> cookies) { Args.notEmpty(cookies, "List of cookies"); final CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size()); buffer.append(SM.COOKIE); buffer.append(": "); for (int i = 0; i < cookies.size(); i++) { final Cookie cookie = cookies.get(i); if (i > 0) { buffer.append("; "); } buffer.append(cookie.getName()); final String s = cookie.getValue(); if (s != null) { buffer.append("="); buffer.append(s); } } final List<Header> headers = new ArrayList<Header>(1); headers.add(new BufferedHeader(buffer)); return headers; }
/** * Sets value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter. * * @param params HTTP parameters. * @param timeout SO_TIMEOUT. */ public static void setSoTimeout(final HttpParams params, final int timeout) { Args.notNull(params, "HTTP parameters"); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); }
/** * Creates a new header from a buffer. * The name of the header will be parsed immediately, * the value only if it is accessed. * * @param buffer the buffer containing the header to represent * * @throws ParseException in case of a parse error */ public BufferedHeader(final CharArrayBuffer buffer) throws ParseException { super(); Args.notNull(buffer, "Char array buffer"); final int colon = buffer.indexOf(':'); if (colon == -1) { throw new ParseException ("Invalid header: " + buffer.toString()); } final String s = buffer.substringTrimmed(0, colon); if (s.length() == 0) { throw new ParseException ("Invalid header: " + buffer.toString()); } this.buffer = buffer; this.name = s; this.valuePos = colon + 1; }
/** * Sets value of the {@link CoreConnectionPNames#STALE_CONNECTION_CHECK} * parameter. * * @param params HTTP parameters. * @param value stale connection check flag. */ public static void setStaleCheckingEnabled(final HttpParams params, final boolean value) { Args.notNull(params, "HTTP parameters"); params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, value); }
/** * Wraps session input stream and reads chunk coded input. * * @param in The session input buffer * @param constraints Message constraints. If {@code null} * {@link MessageConstraints#DEFAULT} will be used. * * @since 4.4 */ public ChunkedInputStream(final SessionInputBuffer in, final MessageConstraints constraints) { super(); this.in = Args.notNull(in, "Session input buffer"); this.pos = 0L; this.buffer = new CharArrayBuffer(16); this.constraints = constraints != null ? constraints : MessageConstraints.DEFAULT; this.state = CHUNK_LEN; }
/** * Obtains value of the {@link CoreConnectionPNames#SOCKET_BUFFER_SIZE} * parameter. If not set, defaults to {@code -1}. * * @param params HTTP parameters. * @return socket buffer size */ public static int getSocketBufferSize(final HttpParams params) { Args.notNull(params, "HTTP parameters"); return params.getIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, -1); }
/** * Creates an instance of this class using the given request method * and URI. * * @param method request method. * @param uri request URI. */ public BasicExecutionAwareRequest(final String method, final String uri) { super(); this.method = Args.notNull(method, "Method name"); this.uri = Args.notNull(uri, "Request URI"); this.requestline = null; }
/** * Create a protocol version designator. * * @param protocol the name of the protocol, for example "HTTP" * @param major the major version number of the protocol * @param minor the minor version number of the protocol */ public ProtocolVersion(final String protocol, final int major, final int minor) { this.protocol = Args.notNull(protocol, "Protocol name"); this.major = Args.notNegative(major, "Protocol minor version"); this.minor = Args.notNegative(minor, "Protocol minor version"); }