本文整理汇总了Java中io.netty.handler.codec.http.HttpHeaders.entries方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHeaders.entries方法的具体用法?Java HttpHeaders.entries怎么用?Java HttpHeaders.entries使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.handler.codec.http.HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders.entries方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHeaderSize
import io.netty.handler.codec.http.HttpHeaders; //导入方法依赖的package包/类
/**
* Returns the size of the headers, including the 2 CRLFs at the end of the header block.
*
* @param headers headers to size
* @return length of the headers, in bytes
*/
public static long getHeaderSize(HttpHeaders headers) {
long headersSize = 0;
for (Map.Entry<String, String> header : headers.entries()) {
// +2 for ': ', +2 for new line
headersSize += header.getKey().length() + header.getValue().length() + 4;
}
return headersSize;
}
示例2: captureHeaders
import io.netty.handler.codec.http.HttpHeaders; //导入方法依赖的package包/类
protected void captureHeaders(HttpHeaders headers) {
Log.e("InnerHandle", "captureHeaders " + harEntry.getId());
for (Map.Entry<String, String> header : headers.entries()) {
harRequest.getRequest().getHeaders().add(new HarNameValuePair(header.getKey(), header.getValue()));
harRequest.addHeader(header.getKey(), header.getValue());
}
}
示例3: captureResponseHeaders
import io.netty.handler.codec.http.HttpHeaders; //导入方法依赖的package包/类
protected void captureResponseHeaders(HttpResponse httpResponse) {
Log.e("InnerHandle", "captureResponseHeaders " + harEntry.getId());
HttpHeaders headers = httpResponse.headers();
for (Map.Entry<String, String> header : headers.entries()) {
harResponse.getResponse().getHeaders().add(new HarNameValuePair(header.getKey(), header.getValue()));
harResponse.addHeader(header.getKey(), header.getValue());
}
}
示例4: getRequestHash
import io.netty.handler.codec.http.HttpHeaders; //导入方法依赖的package包/类
private String getRequestHash(FullHttpRequest request) {
HttpHeaders headers = request.headers();
String requestURI = getRequestURI(request);
HttpMethod requestMethod = request.getMethod();
Set<String> skipHeaders = m_skipHeaders;
boolean skipRequestContent = m_uriMatchEnabled
&& WildcardMatcher.isPatternCanBeMatchedIn(
m_uriMatchOnly,
new CacheDecisionObject(requestURI, requestMethod
.name()));
if(skipRequestContent){
skipHeaders = new HashSet<>(m_skipHeaders);
skipHeaders.add(HttpHeaders.Names.CONTENT_LENGTH.toUpperCase());
}
int uriHashcode = requestURI.hashCode();
int methodHashCode = requestMethod.hashCode();
List<Entry<String, String>> entries = headers.entries();
List<String> hashList = new ArrayList<>();
for (Iterator<Entry<String, String>> it = entries.iterator(); it
.hasNext();) {
Entry<String, String> entry = it.next();
if (skipHeaders.contains(entry.getKey().toUpperCase())) {
continue;
}
hashList.add(entry.getKey());
hashList.add(entry.getValue());
}
int headersHashcode = hashList.hashCode();
StringBuilder sb = new StringBuilder(4);
sb.append(uriHashcode).append(methodHashCode).append(headersHashcode);
if (!skipRequestContent) {
ByteBuf content = request.content();
sb.append(content.hashCode());
}
return Checksum.checksum(sb.toString());
}
示例5: formget
import io.netty.handler.codec.http.HttpHeaders; //导入方法依赖的package包/类
/**
* Standard usage of HTTP API in Netty without file Upload (get is not able to achieve File upload
* due to limitation on request size).
*
* @return the list of headers that will be used in every example after
**/
private static List<Entry<String, String>> formget(
Bootstrap bootstrap, String host, int port, String get, URI uriSimple) throws Exception {
// XXX /formget
// No use of HttpPostRequestEncoder since not a POST
Channel channel = bootstrap.connect(host, port).sync().channel();
// Prepare the HTTP request.
QueryStringEncoder encoder = new QueryStringEncoder(get);
// add Form attribute
encoder.addParam("getform", "GET");
encoder.addParam("info", "first value");
encoder.addParam("secondinfo", "secondvalue ���&");
// not the big one since it is not compatible with GET size
// encoder.addParam("thirdinfo", textArea);
encoder.addParam("thirdinfo", "third value\r\ntest second line\r\n\r\nnew line\r\n");
encoder.addParam("Send", "Send");
URI uriGet = new URI(encoder.toString());
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uriGet.toASCIIString());
HttpHeaders headers = request.headers();
headers.set(HttpHeaderNames.HOST, host);
headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
headers.set(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP + "," + HttpHeaderValues.DEFLATE);
headers.set(HttpHeaderNames.ACCEPT_CHARSET, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
headers.set(HttpHeaderNames.ACCEPT_LANGUAGE, "fr");
headers.set(HttpHeaderNames.REFERER, uriSimple.toString());
headers.set(HttpHeaderNames.USER_AGENT, "Netty Simple Http Client side");
headers.set(HttpHeaderNames.ACCEPT, "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
//connection will not close but needed
// headers.set("Connection","keep-alive");
// headers.set("Keep-Alive","300");
headers.set(
HttpHeaderNames.COOKIE, ClientCookieEncoder.STRICT.encode(
new DefaultCookie("my-cookie", "foo"),
new DefaultCookie("another-cookie", "bar"))
);
// send request
channel.writeAndFlush(request);
// Wait for the server to close the connection.
channel.closeFuture().sync();
// convert headers to list
return headers.entries();
}