當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpHeaders.get方法代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.HttpHeaders.get方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpHeaders.get方法的具體用法?Java HttpHeaders.get怎麽用?Java HttpHeaders.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.handler.codec.http.HttpHeaders的用法示例。


在下文中一共展示了HttpHeaders.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDownFileSize

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * 取下載文件的總大小
 */
public static long getDownFileSize(HttpHeaders resHeaders) {
  String contentRange = resHeaders.get(HttpHeaderNames.CONTENT_RANGE);
  if (contentRange != null) {
    Pattern pattern = Pattern.compile("^[^\\d]*(\\d+)-(\\d+)/.*$");
    Matcher matcher = pattern.matcher(contentRange);
    if (matcher.find()) {
      long startSize = Long.parseLong(matcher.group(1));
      long endSize = Long.parseLong(matcher.group(2));
      return endSize - startSize + 1;
    }
  } else {
    String contentLength = resHeaders.get(HttpHeaderNames.CONTENT_LENGTH);
    if (contentLength != null) {
      return Long.valueOf(resHeaders.get(HttpHeaderNames.CONTENT_LENGTH));
    }
  }
  return 0;
}
 
開發者ID:monkeyWie,項目名稱:proxyee-down,代碼行數:22,代碼來源:HttpDownUtil.java

示例2: determineCharsetFromContentType

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * @param headers
 *     The headers containing the content-type header to parse
 * @param def
 *     The default charset to use if one wasn't found in the headers
 *
 * @return The encoding specified in the header or the default Charset if not specified.
 **/
public static Charset determineCharsetFromContentType(HttpHeaders headers, Charset def) {
    if (headers == null)
        return def;

    String contentTypeHeader = headers.get(HttpHeaders.Names.CONTENT_TYPE);
    if (contentTypeHeader == null)
        return def;

    String charset;
    Matcher m = CONTENT_TYPE_CHARSET_EXTRACTOR_PATTERN.matcher(contentTypeHeader);
    if (m.find()) {
        charset = m.group(1).trim().toUpperCase();
        try {
            return Charset.forName(charset);
        }
        catch (Exception ex) {
            throw new InvalidCharsetInContentTypeHeaderException("Invalid charset in Content-Type header", ex,
                                                                 contentTypeHeader);
        }
    }

    return def;
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:32,代碼來源:HttpUtils.java

示例3: preCall

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Override
public boolean preCall(HttpRequest request, HttpResponder responder, ServiceMethodInfo serviceMethodInfo) {
    HttpHeaders headers = request.headers();
    if (headers != null) {
        String authHeader = headers.get(HttpHeaders.Names.AUTHORIZATION);
        if (authHeader != null) {
            String authType = authHeader.substring(0, AUTH_TYPE_BASIC_LENGTH);
            String authEncoded = authHeader.substring(AUTH_TYPE_BASIC_LENGTH).trim();
            if (AUTH_TYPE_BASIC.equals(authType) && !authEncoded.isEmpty()) {
                byte[] decodedByte = authEncoded.getBytes(Charset.forName("UTF-8"));
                String authDecoded = new String(Base64.getDecoder().decode(decodedByte), Charset.forName("UTF-8"));
                String[] authParts = authDecoded.split(":");
                String username = authParts[0];
                String password = authParts[1];
                if (authenticate(username, password)) {
                    return true;
                }
            }

        }
    }
    Multimap<String, String> map = ArrayListMultimap.create();
    map.put(HttpHeaders.Names.WWW_AUTHENTICATE, AUTH_TYPE_BASIC);
    responder.sendStatus(HttpResponseStatus.UNAUTHORIZED, map);
    return false;
}
 
開發者ID:sagara-gunathunga,項目名稱:msf4j-intro-webinar-samples,代碼行數:27,代碼來源:AbstractBasicAuthInterceptor.java

示例4: afterResponse

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Override
public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpResponse httpResponse,
    HttpProxyInterceptPipeline pipeline) throws Exception {
  boolean downFlag = false;
  if ((httpResponse.status().code() + "").indexOf("20") == 0) { //響應碼為20x
    HttpHeaders httpResHeaders = httpResponse.headers();
    String accept = pipeline.getHttpRequest().headers().get(HttpHeaderNames.ACCEPT);
    String contentType = httpResHeaders.get(HttpHeaderNames.CONTENT_TYPE);
    if (accept != null
        && accept.matches("^.*text/html.*$")  //直接url的方式訪問不是以HTML標簽加載的(a標簽除外)
        && contentType != null
        && !contentType.matches("^.*text/.*$")) { //響應體不是text/html報文
      //有兩種情況進行下載 1.url後綴為.xxx  2.帶有CONTENT_DISPOSITION:ATTACHMENT響應頭
      String disposition = httpResHeaders.get(HttpHeaderNames.CONTENT_DISPOSITION);
      if (pipeline.getHttpRequest().uri().matches("^.*\\.[^./]{1,5}(\\?[^?]*)?$")
          || (disposition != null && disposition.contains(HttpHeaderValues.ATTACHMENT))) {
        downFlag = true;
      }
    }
    HttpRequestInfo httpRequestInfo = (HttpRequestInfo) pipeline.getHttpRequest();
    if (downFlag) {   //如果是下載
      proxyChannel.close();//關閉嗅探下載連接
      HttpDownServer.LOGGER.debug("=====================下載===========================\n" +
          pipeline.getHttpRequest().toString() + "\n" +
          httpResponse.toString() + "\n" +
          "================================================");
      //原始的請求協議
      httpRequestInfo.setRequestProto(pipeline.getRequestProto());
      pipeline.afterResponse(clientChannel, proxyChannel, httpResponse);
    } else {
      if (httpRequestInfo.content() != null) {
        httpRequestInfo.setContent(null);
      }
    }
  }
  pipeline.getDefault().afterResponse(clientChannel, proxyChannel, httpResponse, pipeline);
}
 
開發者ID:monkeyWie,項目名稱:proxyee-down,代碼行數:38,代碼來源:HttpDownSniffIntercept.java

示例5: checkHeaderDiffer

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
private void checkHeaderDiffer(HttpHeaders headers1, HttpHeaders headers2,
		List<String> mh) {
	for (String headerName : headers1.names()) {
		if (!s_vaStrict
				&& s_tolerantHeaders.contains(headerName.toUpperCase())) {
			continue;
		}
		String v1 = headers1.get(headerName);
		String v2 = headers2.get(headerName);
		if (!v1.equals(v2)) {
			mh.add(headerName);
		}
	}
}
 
開發者ID:eBay,項目名稱:ServiceCOLDCache,代碼行數:15,代碼來源:CacheResultVerifier.java

示例6: getClientVersion

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Get the value of the X-Cerberus-Client header or "Unknown" if not found.
 */
public static String getClientVersion(RequestInfo request) {
    final HttpHeaders headers = request.getHeaders();
    if (headers != null) {
        String value = headers.get(HEADER_X_CERBERUS_CLIENT);
        if (value != null) {
            return value;
        }
    }
    return UNKNOWN;
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:14,代碼來源:CerberusHttpHeaders.java

示例7: getXForwardedClientIp

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Get the first IP address from the Http header "X-Forwarded-For"
 *
 * E.g. "X-Forwarded-For: ip1, ip2, ip3" would return "ip1"
 */
public static String getXForwardedClientIp(RequestInfo request) {
    final HttpHeaders headers = request.getHeaders();
    if (headers != null) {
        String value = headers.get(HEADER_X_FORWARDED_FOR);
        if (value != null) {
            return StringUtils.substringBefore(value, ",").trim();
        }
    }
    return UNKNOWN;
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:16,代碼來源:CerberusHttpHeaders.java

示例8: getHeader

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Override
public String getHeader(String headerName) {
    HttpHeaders headers = httpRequest.headers();
    if (headers == null)
        return null;

    return headers.get(headerName);
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:9,代碼來源:RequestWithHeadersNettyAdapter.java

示例9: extractMimeTypeFromContentTypeHeader

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
protected String extractMimeTypeFromContentTypeHeader(HttpHeaders headers, String def) {
    if (headers == null)
        return def;

    String contentTypeHeader = headers.get(HttpHeaders.Names.CONTENT_TYPE);
    if (contentTypeHeader == null || contentTypeHeader.trim().length() == 0)
        return def;

    if (contentTypeHeader.contains(";"))
        contentTypeHeader = contentTypeHeader.substring(0, contentTypeHeader.indexOf(";"));

    return contentTypeHeader.trim();
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:14,代碼來源:ResponseSender.java

示例10: extractCookies

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
public static Set<Cookie> extractCookies(HttpRequest request) {
    Set<Cookie> cookies = new HashSet<>();

    HttpHeaders trailingHeaders = extractTrailingHeadersIfPossible(request);

    String cookieString = request.headers().get(COOKIE);
    if (cookieString == null && trailingHeaders != null)
        cookieString = trailingHeaders.get(COOKIE);

    if (cookieString != null)
        cookies.addAll(ServerCookieDecoder.LAX.decode(cookieString));

    return cookies;
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:15,代碼來源:HttpUtils.java

示例11: newMultipartBody

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Creates a new multipart entity containing the given parts.
 * 
 * @param parts the parts to include.
 * @param requestHeaders the request headers
 * @return a MultipartBody
 */
public static MultipartBody newMultipartBody(List<Part> parts, HttpHeaders requestHeaders) {
    assertNotNull(parts, "parts");

    byte[] boundary;
    String contentType;

    String contentTypeHeader = requestHeaders.get(HttpHeaders.Names.CONTENT_TYPE);
    if (isNonEmpty(contentTypeHeader)) {
        int boundaryLocation = contentTypeHeader.indexOf("boundary=");
        if (boundaryLocation != -1) {
            // boundary defined in existing Content-Type
            contentType = contentTypeHeader;
            boundary = (contentTypeHeader.substring(boundaryLocation + "boundary=".length()).trim()).getBytes(US_ASCII);
        } else {
            // generate boundary and append it to existing Content-Type
            boundary = generateBoundary();
            contentType = computeContentType(contentTypeHeader, boundary);
        }
    } else {
        boundary = generateBoundary();
        contentType = computeContentType(MULTIPART_FORM_DATA, boundary);
    }

    List<MultipartPart<? extends Part>> multipartParts = generateMultipartParts(parts, boundary);

    return new MultipartBody(multipartParts, contentType, boundary);
}
 
開發者ID:amaralDaniel,項目名稱:megaphone,代碼行數:35,代碼來源:MultipartUtils.java

示例12: build

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Override
public TransportRequest build(
    HttpRequest request, TransportBody body, AttributeMap channelAttrs) {
  HttpHeaders httpHeaders = request.headers();

  // Keep track of request information
  String service = httpHeaders.get(HeaderMapper.SERVICE);
  channelAttrs.attr(ChannelAttributes.SERVICE).set(service);
  String procedure = httpHeaders.get(HeaderMapper.PROCEDURE);
  channelAttrs.attr(ChannelAttributes.PROCEDURE).set(procedure);
  String caller = httpHeaders.get(HeaderMapper.CALLER);
  channelAttrs.attr(ChannelAttributes.CALLER).set(caller);

  // Keep track of when the request started
  Instant start = Instant.now();
  channelAttrs.attr(ChannelAttributes.REQUEST_START).set(start);

  Instant deadline =
      createDeadline(start, service, procedure, httpHeaders.get(HeaderMapper.TIMEOUT));
  Span span = createSpan(start, service, procedure, caller, httpHeaders);
  channelAttrs.attr(ChannelAttributes.SPAN).set(span);

  return DefaultTransportRequest.builder()
      .service(service)
      .procedure(procedure)
      .deadline(deadline)
      .caller(caller)
      .encoding(httpHeaders.get(HeaderMapper.ENCODING))
      .shardKey(httpHeaders.get(HeaderMapper.SHARD_KEY))
      .routingKey(httpHeaders.get(HeaderMapper.ROUTING_KEY))
      .routingDelegate(httpHeaders.get(HeaderMapper.ROUTING_DELEGATE))
      .headers(HeaderMapper.fromHttpHeaders(httpHeaders))
      .span(span)
      .body(body)
      .build();
}
 
開發者ID:yarpc,項目名稱:yarpc-java,代碼行數:37,代碼來源:TransportRequestDecoderConfiguration.java

示例13: removeSDCHEncoding

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Remove sdch from encodings we accept since we can't decode it.
 * 
 * @param headers
 *            The headers to modify
 */
private void removeSDCHEncoding(HttpHeaders headers) {
    String ae = headers.get(HttpHeaders.Names.ACCEPT_ENCODING);
    if (StringUtils.isNotBlank(ae)) {
        //
        String noSdch = ae.replace(",sdch", "").replace("sdch", "");
        headers.set(HttpHeaders.Names.ACCEPT_ENCODING, noSdch);
        LOG.debug("Removed sdch and inserted: {}", noSdch);
    }
}
 
開發者ID:wxyzZ,項目名稱:little_mitm,代碼行數:16,代碼來源:ClientToProxyConnection.java

示例14: switchProxyConnectionHeader

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Switch the de-facto standard "Proxy-Connection" header to "Connection"
 * when we pass it along to the remote host. This is largely undocumented
 * but seems to be what most browsers and servers expect.
 * 
 * @param headers
 *            The headers to modify
 */
private void switchProxyConnectionHeader(HttpHeaders headers) {
    String proxyConnectionKey = "Proxy-Connection";
    if (headers.contains(proxyConnectionKey)) {
        String header = headers.get(proxyConnectionKey);
        headers.remove(proxyConnectionKey);
        headers.set(HttpHeaders.Names.CONNECTION, header);
    }
}
 
開發者ID:wxyzZ,項目名稱:little_mitm,代碼行數:17,代碼來源:ClientToProxyConnection.java

示例15: getIP

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
public static String getIP(HttpHeaders headers) {

        String[] ips = proxyIP(headers);

        if (ips.length > 0 && !"".equals(ips[0])) {

            return ips[0].split(":")[0];
        }

        CharSequence realIpChar = headers.get(X_REAL_IP);

        if (realIpChar != null) {

            String[] realIp = realIpChar.toString().split(":");

            if (realIp.length > 0 && !"[".equals(realIp[0])) {

                return realIp[0];
            }
        }

        return "127.0.0.1";
    }
 
開發者ID:thundernet8,項目名稱:Razor,代碼行數:24,代碼來源:HttpKit.java


注:本文中的io.netty.handler.codec.http.HttpHeaders.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。