ggregory

Remove-IncomingHttpEntity

Nov 22nd, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.47 KB | None | 0 0
  1. diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
  2. index fdf4ab0..9a43a90 100644
  3. --- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
  4. +++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
  5. @@ -58,6 +58,7 @@
  6. import org.apache.hc.core5.http.io.BHttpConnection;
  7. import org.apache.hc.core5.http.io.SessionInputBuffer;
  8. import org.apache.hc.core5.http.io.SessionOutputBuffer;
  9. +import org.apache.hc.core5.http.io.entity.InputStreamEntity;
  10. import org.apache.hc.core5.io.CloseMode;
  11. import org.apache.hc.core5.io.Closer;
  12. import org.apache.hc.core5.net.InetAddressUtils;
  13. @@ -172,12 +173,20 @@
  14. final HttpMessage message,
  15. final SessionInputBuffer inBuffer,
  16. final InputStream inputStream,
  17. - final long len) {
  18. - return new IncomingHttpEntity(
  19. - createContentInputStream(len, inBuffer, inputStream),
  20. - len >= 0 ? len : -1, len == ContentLengthStrategy.CHUNKED,
  21. - message.getFirstHeader(HttpHeaders.CONTENT_TYPE),
  22. - message.getFirstHeader(HttpHeaders.CONTENT_ENCODING));
  23. + final long len) {
  24. + final InputStreamEntity inputStreamEntity = new InputStreamEntity(
  25. + createContentInputStream(len, inBuffer, inputStream),
  26. + len >= 0 ? len : -1);
  27. + inputStreamEntity.setChunked(len == ContentLengthStrategy.CHUNKED);
  28. + final Header ctHeader = message.getFirstHeader(HttpHeaders.CONTENT_TYPE);
  29. + if (ctHeader != null) {
  30. + inputStreamEntity.setContentType(ctHeader.getValue());
  31. + }
  32. + final Header ceHeader = message.getFirstHeader(HttpHeaders.CONTENT_ENCODING);
  33. + if (ceHeader != null) {
  34. + inputStreamEntity.setContentEncoding(ceHeader.getValue());
  35. + }
  36. + return inputStreamEntity;
  37. }
  38.  
  39. @Override
  40. diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/IncomingHttpEntity.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/IncomingHttpEntity.java
  41. deleted file mode 100644
  42. index 8da8065..0000000
  43. --- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/IncomingHttpEntity.java
  44. +++ /dev/null
  45. @@ -1,107 +0,0 @@
  46. -/*
  47. - * ====================================================================
  48. - * Licensed to the Apache Software Foundation (ASF) under one
  49. - * or more contributor license agreements. See the NOTICE file
  50. - * distributed with this work for additional information
  51. - * regarding copyright ownership. The ASF licenses this file
  52. - * to you under the Apache License, Version 2.0 (the
  53. - * "License"); you may not use this file except in compliance
  54. - * with the License. You may obtain a copy of the License at
  55. - *
  56. - * http://www.apache.org/licenses/LICENSE-2.0
  57. - *
  58. - * Unless required by applicable law or agreed to in writing,
  59. - * software distributed under the License is distributed on an
  60. - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61. - * KIND, either express or implied. See the License for the
  62. - * specific language governing permissions and limitations
  63. - * under the License.
  64. - * ====================================================================
  65. - *
  66. - * This software consists of voluntary contributions made by many
  67. - * individuals on behalf of the Apache Software Foundation. For more
  68. - * information on the Apache Software Foundation, please see
  69. - * <http://www.apache.org/>.
  70. - *
  71. - */
  72. -
  73. -package org.apache.hc.core5.http.impl.io;
  74. -
  75. -import java.io.IOException;
  76. -import java.io.InputStream;
  77. -import java.util.Collections;
  78. -import java.util.List;
  79. -import java.util.Set;
  80. -
  81. -import org.apache.hc.core5.http.Header;
  82. -import org.apache.hc.core5.function.Supplier;
  83. -import org.apache.hc.core5.http.io.entity.AbstractImmutableHttpEntity;
  84. -import org.apache.hc.core5.io.Closer;
  85. -
  86. -class IncomingHttpEntity extends AbstractImmutableHttpEntity {
  87. -
  88. - private final InputStream content;
  89. - private final long len;
  90. - private final boolean chunked;
  91. - private final Header contentType;
  92. - private final Header contentEncoding;
  93. -
  94. - IncomingHttpEntity(final InputStream content, final long len, final boolean chunked, final Header contentType, final Header contentEncoding) {
  95. - this.content = content;
  96. - this.len = len;
  97. - this.chunked = chunked;
  98. - this.contentType = contentType;
  99. - this.contentEncoding = contentEncoding;
  100. - }
  101. -
  102. - @Override
  103. - public boolean isRepeatable() {
  104. - return false;
  105. - }
  106. -
  107. - @Override
  108. - public boolean isChunked() {
  109. - return chunked;
  110. - }
  111. -
  112. - @Override
  113. - public long getContentLength() {
  114. - return len;
  115. - }
  116. -
  117. - @Override
  118. - public String getContentType() {
  119. - return contentType != null ? contentType.getValue() : null;
  120. - }
  121. -
  122. - @Override
  123. - public String getContentEncoding() {
  124. - return contentEncoding != null ? contentEncoding.getValue() : null;
  125. - }
  126. -
  127. - @Override
  128. - public InputStream getContent() throws IOException, IllegalStateException {
  129. - return content;
  130. - }
  131. -
  132. - @Override
  133. - public boolean isStreaming() {
  134. - return content != null && content != EmptyInputStream.INSTANCE;
  135. - }
  136. -
  137. - @Override
  138. - public Supplier<List<? extends Header>> getTrailers() {
  139. - return null;
  140. - }
  141. -
  142. - @Override
  143. - public Set<String> getTrailerNames() {
  144. - return Collections.emptySet();
  145. - }
  146. -
  147. - @Override
  148. - public void close() throws IOException {
  149. - Closer.close(content);
  150. - }
  151. -
  152. -}
  153. diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/InputStreamEntity.java b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/InputStreamEntity.java
  154. index 9180183..19d38be 100644
  155. --- a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/InputStreamEntity.java
  156. +++ b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/InputStreamEntity.java
  157. @@ -32,6 +32,7 @@
  158. import java.io.OutputStream;
  159.  
  160. import org.apache.hc.core5.http.ContentType;
  161. +import org.apache.hc.core5.http.impl.io.EmptyInputStream;
  162. import org.apache.hc.core5.util.Args;
  163.  
  164. /**
  165. @@ -150,7 +151,7 @@
  166.  
  167. @Override
  168. public boolean isStreaming() {
  169. - return true;
  170. + return this.content != EmptyInputStream.INSTANCE;
  171. }
  172.  
  173. @Override
Advertisement
Add Comment
Please, Sign In to add comment