当前位置: 首页>>代码示例>>Java>>正文


Java HttpRequest类代码示例

本文整理汇总了Java中ch.boye.httpclientandroidlib.HttpRequest的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest类的具体用法?Java HttpRequest怎么用?Java HttpRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpRequest类属于ch.boye.httpclientandroidlib包,在下文中一共展示了HttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: flushInvalidatedCacheEntries

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
/** Flushes entries that were invalidated by the given response
 * received for the given host/request pair.
 */
public void flushInvalidatedCacheEntries(final HttpHost host,
        final HttpRequest request, final HttpResponse response) {
    final int status = response.getStatusLine().getStatusCode();
    if (status < 200 || status > 299) {
        return;
    }
    final URL reqURL = getAbsoluteURL(cacheKeyGenerator.getURI(host, request));
    if (reqURL == null) {
        return;
    }
    final URL contentLocation = getContentLocationURL(reqURL, response);
    if (contentLocation != null) {
        flushLocationCacheEntry(reqURL, response, contentLocation);
    }
    final URL location = getLocationURL(reqURL, response);
    if (location != null) {
        flushLocationCacheEntry(reqURL, response, location);
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:23,代码来源:CacheInvalidator.java

示例2: process

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:18,代码来源:RequestUserAgent.java

示例3: doReceiveResponse

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
/**
 * Waits for and receives a response.
 * This method will automatically ignore intermediate responses
 * with status code 1xx.
 *
 * @param request   the request for which to obtain the response
 * @param conn      the connection over which the request was sent
 * @param context   the context for receiving the response
 *
 * @return  the terminal response, not yet post-processed
 *
 * @throws IOException in case of an I/O error.
 * @throws HttpException in case of HTTP protocol violation or a processing
 *   problem.
 */
protected HttpResponse doReceiveResponse(
        final HttpRequest request,
        final HttpClientConnection conn,
        final HttpContext context) throws HttpException, IOException {
    Args.notNull(request, "HTTP request");
    Args.notNull(conn, "Client connection");
    Args.notNull(context, "HTTP context");
    HttpResponse response = null;
    int statusCode = 0;

    while (response == null || statusCode < HttpStatus.SC_OK) {

        response = conn.receiveResponseHeader();
        if (canResponseHaveBody(request, response)) {
            conn.receiveResponseEntity(response);
        }
        statusCode = response.getStatusLine().getStatusCode();

    } // while intermediate response

    return response;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:38,代码来源:HttpRequestExecutor.java

示例4: process

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(request, "HTTP request");
    Args.notNull(context, "HTTP context");

    final String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        return;
    }

    if (request.containsHeader(AUTH.WWW_AUTH_RESP)) {
        return;
    }

    // Obtain authentication state
    final AuthState authState = (AuthState) context.getAttribute(
            ClientContext.TARGET_AUTH_STATE);
    if (authState == null) {
        this.log.debug("Target auth state not set in the context");
        return;
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Target auth state: " + authState.getState());
    }
    process(authState, request, context);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:27,代码来源:RequestTargetAuthentication.java

示例5: process

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
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 HttpClientContext clientContext = HttpClientContext.adapt(context);
                final RequestConfig config = clientContext.getRequestConfig();
                if (config.isExpectContinueEnabled()) {
                    request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
                }
            }
        }
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:21,代码来源:RequestExpectContinue.java

示例6: DefaultManagedHttpClientConnection

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
public DefaultManagedHttpClientConnection(
        final String id,
        final int buffersize,
        final int fragmentSizeHint,
        final CharsetDecoder chardecoder,
        final CharsetEncoder charencoder,
        final MessageConstraints constraints,
        final ContentLengthStrategy incomingContentStrategy,
        final ContentLengthStrategy outgoingContentStrategy,
        final HttpMessageWriterFactory<HttpRequest> requestWriterFactory,
        final HttpMessageParserFactory<HttpResponse> responseParserFactory) {
    super(buffersize, fragmentSizeHint, chardecoder, charencoder,
            constraints, incomingContentStrategy, outgoingContentStrategy,
            requestWriterFactory, responseParserFactory);
    this.id = id;
    this.attributes = new ConcurrentHashMap<String, Object>();
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:18,代码来源:DefaultManagedHttpClientConnection.java

示例7: requestHasWeakETagAndRange

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
private RequestProtocolError requestHasWeakETagAndRange(final HttpRequest request) {
    // TODO: Should these be looking at all the headers marked as Range?
    final String method = request.getRequestLine().getMethod();
    if (!(HeaderConstants.GET_METHOD.equals(method))) {
        return null;
    }

    final Header range = request.getFirstHeader(HeaderConstants.RANGE);
    if (range == null) {
        return null;
    }

    final Header ifRange = request.getFirstHeader(HeaderConstants.IF_RANGE);
    if (ifRange == null) {
        return null;
    }

    final String val = ifRange.getValue();
    if (val.startsWith("W/")) {
        return RequestProtocolError.WEAK_ETAG_AND_RANGE_ERROR;
    }

    return null;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:25,代码来源:RequestProtocolCompliance.java

示例8: authenticate

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
/**
 * Produces a digest authorization string for the given set of
 * {@link Credentials}, method name and URI.
 *
 * @param credentials A set of credentials to be used for athentication
 * @param request    The request being authenticated
 *
 * @throws ch.boye.httpclientandroidlib.auth.InvalidCredentialsException if authentication credentials
 *         are not valid or not applicable for this authentication scheme
 * @throws AuthenticationException if authorization string cannot
 *   be generated due to an authentication failure
 *
 * @return a digest authorization string
 */
@Override
public Header authenticate(
        final Credentials credentials,
        final HttpRequest request,
        final HttpContext context) throws AuthenticationException {

    Args.notNull(credentials, "Credentials");
    Args.notNull(request, "HTTP request");
    if (getParameter("realm") == null) {
        throw new AuthenticationException("missing realm in challenge");
    }
    if (getParameter("nonce") == null) {
        throw new AuthenticationException("missing nonce in challenge");
    }
    // Add method name and request-URI to the parameter map
    getParameters().put("methodname", request.getRequestLine().getMethod());
    getParameters().put("uri", request.getRequestLine().getUri());
    final String charset = getParameter("charset");
    if (charset == null) {
        getParameters().put("charset", getCredentialsCharset(request));
    }
    return createDigestHeader(credentials, request);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:38,代码来源:DigestScheme.java

示例9: storeVariantEntry

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
void storeVariantEntry(
        final HttpHost target,
        final HttpRequest req,
        final HttpCacheEntry entry) throws IOException {
    final String parentURI = uriExtractor.getURI(target, req);
    final String variantURI = uriExtractor.getVariantURI(target, req, entry);
    storage.putEntry(variantURI, entry);

    final HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback() {

        public HttpCacheEntry update(final HttpCacheEntry existing) throws IOException {
            return doGetUpdatedParentEntry(
                    req.getRequestLine().getUri(), existing, entry,
                    uriExtractor.getVariantKey(req, entry),
                    variantURI);
        }

    };

    try {
        storage.updateEntry(parentURI, callback);
    } catch (final HttpCacheUpdateException e) {
        log.warn("Could not update key [" + parentURI + "]", e);
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:26,代码来源:BasicHttpCache.java

示例10: etagValidatorMatches

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
/**
 * Check entry against If-None-Match
 * @param request The current httpRequest being made
 * @param entry the cache entry
 * @return boolean does the etag validator match
 */
private boolean etagValidatorMatches(final HttpRequest request, final HttpCacheEntry entry) {
    final Header etagHeader = entry.getFirstHeader(HeaderConstants.ETAG);
    final String etag = (etagHeader != null) ? etagHeader.getValue() : null;
    final Header[] ifNoneMatch = request.getHeaders(HeaderConstants.IF_NONE_MATCH);
    if (ifNoneMatch != null) {
        for (final Header h : ifNoneMatch) {
            for (final HeaderElement elt : h.getElements()) {
                final String reqEtag = elt.toString();
                if (("*".equals(reqEtag) && etag != null)
                        || reqEtag.equals(etag)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:24,代码来源:CachedResponseSuitabilityChecker.java

示例11: requestIsFatallyNonCompliant

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
/**
 * Test to see if the {@link HttpRequest} is HTTP1.1 compliant or not
 * and if not, we can not continue.
 *
 * @param request the HttpRequest Object
 * @return list of {@link RequestProtocolError}
 */
public List<RequestProtocolError> requestIsFatallyNonCompliant(final HttpRequest request) {
    final List<RequestProtocolError> theErrors = new ArrayList<RequestProtocolError>();

    RequestProtocolError anError = requestHasWeakETagAndRange(request);
    if (anError != null) {
        theErrors.add(anError);
    }

    if (!weakETagOnPutDeleteAllowed) {
        anError = requestHasWeekETagForPUTOrDELETEIfMatch(request);
        if (anError != null) {
            theErrors.add(anError);
        }
    }

    anError = requestContainsNoCacheDirectiveWithFieldName(request);
    if (anError != null) {
        theErrors.add(anError);
    }

    return theErrors;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:30,代码来源:RequestProtocolCompliance.java

示例12: LoggingManagedHttpClientConnection

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
public LoggingManagedHttpClientConnection(
        final String id,
        final HttpClientAndroidLog log,
        final HttpClientAndroidLog headerlog,
        final HttpClientAndroidLog wirelog,
        final int buffersize,
        final int fragmentSizeHint,
        final CharsetDecoder chardecoder,
        final CharsetEncoder charencoder,
        final MessageConstraints constraints,
        final ContentLengthStrategy incomingContentStrategy,
        final ContentLengthStrategy outgoingContentStrategy,
        final HttpMessageWriterFactory<HttpRequest> requestWriterFactory,
        final HttpMessageParserFactory<HttpResponse> responseParserFactory) {
    super(id, buffersize, fragmentSizeHint, chardecoder, charencoder,
            constraints, incomingContentStrategy, outgoingContentStrategy,
            requestWriterFactory, responseParserFactory);
    this.log = log;
    this.headerlog = headerlog;
    this.wire = new Wire(wirelog, id);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:22,代码来源:LoggingManagedHttpClientConnection.java

示例13: process

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
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;
    }

    if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
        // Default policy is to keep connection alive
        // whenever possible
        request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:16,代码来源:RequestConnControl.java

示例14: determineRoute

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
public HttpRoute determineRoute(final HttpHost target,
                                final HttpRequest request,
                                final HttpContext context)
    throws HttpException {

    Args.notNull(request, "HTTP request");

    // If we have a forced route, we can do without a target.
    HttpRoute route =
        ConnRouteParams.getForcedRoute(request.getParams());
    if (route != null) {
        return route;
    }

    // If we get here, there is no forced route.
    // So we need a target to compute a route.

    Asserts.notNull(target, "Target host");

    final InetAddress local =
        ConnRouteParams.getLocalAddress(request.getParams());
    final HttpHost proxy = determineProxy(target, request, context);

    final Scheme schm =
        this.schemeRegistry.getScheme(target.getSchemeName());
    // as it is typically used for TLS/SSL, we assume that
    // a layered scheme implies a secure connection
    final boolean secure = schm.isLayered();

    if (proxy == null) {
        route = new HttpRoute(target, local, secure);
    } else {
        route = new HttpRoute(target, local, proxy, secure);
    }
    return route;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:37,代码来源:ProxySelectorRoutePlanner.java

示例15: requestMinorVersionIsTooHighMajorVersionsMatch

import ch.boye.httpclientandroidlib.HttpRequest; //导入依赖的package包/类
protected boolean requestMinorVersionIsTooHighMajorVersionsMatch(final HttpRequest request) {
    final ProtocolVersion requestProtocol = request.getProtocolVersion();
    if (requestProtocol.getMajor() != HttpVersion.HTTP_1_1.getMajor()) {
        return false;
    }

    if (requestProtocol.getMinor() > HttpVersion.HTTP_1_1.getMinor()) {
        return true;
    }

    return false;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:13,代码来源:RequestProtocolCompliance.java


注:本文中的ch.boye.httpclientandroidlib.HttpRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。