You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2015/04/13 20:25:42 UTC
svn commit: r1673254 - in /httpcomponents/httpcore/branches/4.4.x:
httpcore-h2/ httpcore-h2/src/ httpcore-h2/src/main/
httpcore-h2/src/main/java/ httpcore-h2/src/main/java/org/
httpcore-h2/src/main/java/org/apache/
httpcore-h2/src/main/java/org/apache/...
Author: olegk
Date: Mon Apr 13 18:25:42 2015
New Revision: 1673254
URL: http://svn.apache.org/r1673254
Log:
Reduced intermediate garbage in HeaderGroup and DefaultConnectionReuseStrategy
Added:
httpcomponents/httpcore/branches/4.4.x/httpcore-h2/
httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/
httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/
httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/
httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/
httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/apache/
httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/apache/hc5/
httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/apache/hc5/core/
httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/apache/hc5/core/http2/
httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/apache/hc5/core/http2/stream/
httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/apache/hc5/core/http2/stream/MessageEncoder.java (with props)
Modified:
httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java
httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java
Added: httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/apache/hc5/core/http2/stream/MessageEncoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/apache/hc5/core/http2/stream/MessageEncoder.java?rev=1673254&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/apache/hc5/core/http2/stream/MessageEncoder.java (added)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/apache/hc5/core/http2/stream/MessageEncoder.java Mon Apr 13 18:25:42 2015
@@ -0,0 +1,36 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc5.core.http2.stream;
+
+import org.apache.http.MessageHead;
+
+public interface MessageEncoder<T extends MessageHead> {
+
+ void encode(T message);
+
+}
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/apache/hc5/core/http2/stream/MessageEncoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/apache/hc5/core/http2/stream/MessageEncoder.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/branches/4.4.x/httpcore-h2/src/main/java/org/apache/hc5/core/http2/stream/MessageEncoder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java?rev=1673254&r1=1673253&r2=1673254&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java Mon Apr 13 18:25:42 2015
@@ -37,6 +37,7 @@ import org.apache.http.ParseException;
import org.apache.http.ProtocolVersion;
import org.apache.http.TokenIterator;
import org.apache.http.annotation.Immutable;
+import org.apache.http.message.BasicHeaderIterator;
import org.apache.http.message.BasicTokenIterator;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
@@ -107,9 +108,9 @@ public class DefaultConnectionReuseStrat
// Check for the "Connection" header. If that is absent, check for
// the "Proxy-Connection" header. The latter is an unspecified and
// broken but unfortunately common extension of HTTP.
- HeaderIterator hit = response.headerIterator(HTTP.CONN_DIRECTIVE);
- if (!hit.hasNext()) {
- hit = response.headerIterator("Proxy-Connection");
+ Header[] connHeaders = response.getHeaders(HTTP.CONN_DIRECTIVE);
+ if (connHeaders.length == 0) {
+ connHeaders = response.getHeaders("Proxy-Connection");
}
// Experimental usage of the "Connection" header in HTTP/1.0 is
@@ -135,9 +136,9 @@ public class DefaultConnectionReuseStrat
// it takes precedence and indicates a non-persistent connection.
// If there is no "close" but a "keep-alive", we take the hint.
- if (hit.hasNext()) {
+ if (connHeaders.length != 0) {
try {
- final TokenIterator ti = createTokenIterator(hit);
+ final TokenIterator ti = new BasicTokenIterator(new BasicHeaderIterator(connHeaders, null));
boolean keepalive = false;
while (ti.hasNext()) {
final String token = ti.nextToken();
@@ -148,8 +149,7 @@ public class DefaultConnectionReuseStrat
keepalive = true;
}
}
- if (keepalive)
- {
+ if (keepalive) {
return true;
// neither "close" nor "keep-alive", use default policy
}
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java?rev=1673254&r1=1673253&r2=1673254&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java Mon Apr 13 18:25:42 2015
@@ -51,6 +51,8 @@ public class HeaderGroup implements Clon
private static final long serialVersionUID = 2608834160639271617L;
+ private final Header[] EMPTY = new Header[] {};
+
/** The list of headers for this group, in the order in which they were added */
private final List<Header> headers;
@@ -173,18 +175,20 @@ public class HeaderGroup implements Clon
* @return an array of length ≥ 0
*/
public Header[] getHeaders(final String name) {
- final List<Header> headersFound = new ArrayList<Header>();
+ List<Header> headersFound = null;
// HTTPCORE-361 : we don't use the for-each syntax, i.e.
// for (Header header : headers)
// as that creates an Iterator that needs to be garbage-collected
for (int i = 0; i < this.headers.size(); i++) {
final Header header = this.headers.get(i);
if (header.getName().equalsIgnoreCase(name)) {
+ if (headersFound == null) {
+ headersFound = new ArrayList<Header>();
+ }
headersFound.add(header);
}
}
-
- return headersFound.toArray(new Header[headersFound.size()]);
+ return headersFound != null ? headersFound.toArray(new Header[headersFound.size()]) : EMPTY;
}
/**