GeezerVison is showing github.com — HTTP/2 draft 14 HTTP message flow · netty/netty@3161f35
File treeExpand file treeCollapse file tree Open diff view settings main/java/io/netty/handler/codec/http2 test/java/io/netty/handler/codec/http2
codec-http/src/main/java/io/netty/handler/codec/http main/java/io/netty/handler/codec test/java/io/netty/handler/codec
example/src/main/java/io/netty/example/http2/client
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpRequest.java +69-3Lines changed: 69 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 17 | 17 |
| 18 | 18 | import io.netty.buffer.ByteBuf; | 19 | 19 | import io.netty.buffer.Unpooled; | | 20 | +import io.netty.util.internal.StringUtil; | 20 | 21 |
| 21 | 22 | /** | 22 | 23 | * Default implementation of {@link FullHttpRequest}. | 23 | 24 | */ | 24 | 25 | public class DefaultFullHttpRequest extends DefaultHttpRequest implements FullHttpRequest { | | 26 | + private static final int HASH_CODE_PRIME = 31; | 25 | 27 | private final ByteBuf content; | 26 | 28 | private final HttpHeaders trailingHeader; | 27 | 29 | private final boolean validateHeaders; | @@ -34,6 +36,10 @@ public DefaultFullHttpRequest(HttpVersion httpVersion, HttpMethod method, String | 34 | 36 | this(httpVersion, method, uri, content, true); | 35 | 37 | } | 36 | 38 |
| | 39 | + public DefaultFullHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri, boolean validateHeaders) { | | 40 | + this(httpVersion, method, uri, Unpooled.buffer(0), true); | | 41 | + } | | 42 | + | 37 | 43 | public DefaultFullHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri, | 38 | 44 | ByteBuf content, boolean validateHeaders) { | 39 | 45 | super(httpVersion, method, uri, validateHeaders); | @@ -112,15 +118,41 @@ public FullHttpRequest setUri(String uri) { | 112 | 118 | return this; | 113 | 119 | } | 114 | 120 |
| 115 | | - @Override | 116 | | - public FullHttpRequest copy() { | | 121 | + /** | | 122 | + * Copy this object | | 123 | + * | | 124 | + * @param copyContent | | 125 | + * <ul> | | 126 | + * <li>{@code true} if this object's {@link #content()} should be used to copy.</li> | | 127 | + * <li>{@code false} if {@code newContent} should be used instead.</li> | | 128 | + * </ul> | | 129 | + * @param newContent | | 130 | + * <ul> | | 131 | + * <li>if {@code copyContent} is false then this will be used in the copy's content.</li> | | 132 | + * <li>if {@code null} then a default buffer of 0 size will be selected</li> | | 133 | + * </ul> | | 134 | + * @return A copy of this object | | 135 | + */ | | 136 | + private FullHttpRequest copy(boolean copyContent, ByteBuf newContent) { | 117 | 137 | DefaultFullHttpRequest copy = new DefaultFullHttpRequest( | 118 | | - protocolVersion(), method(), uri(), content().copy(), validateHeaders); | | 138 | + protocolVersion(), method(), uri(), | | 139 | + copyContent ? content().copy() : | | 140 | + newContent == null ? Unpooled.buffer(0) : newContent); | 119 | 141 | copy.headers().set(headers()); | 120 | 142 | copy.trailingHeaders().set(trailingHeaders()); | 121 | 143 | return copy; | 122 | 144 | } | 123 | 145 |
| | 146 | + @Override | | 147 | + public FullHttpRequest copy(ByteBuf newContent) { | | 148 | + return copy(false, newContent); | | 149 | + } | | 150 | + | | 151 | + @Override | | 152 | + public FullHttpRequest copy() { | | 153 | + return copy(true, null); | | 154 | + } | | 155 | + | 124 | 156 | @Override | 125 | 157 | public FullHttpRequest duplicate() { | 126 | 158 | DefaultFullHttpRequest duplicate = new DefaultFullHttpRequest( | @@ -129,4 +161,38 @@ public FullHttpRequest duplicate() { | 129 | 161 | duplicate.trailingHeaders().set(trailingHeaders()); | 130 | 162 | return duplicate; | 131 | 163 | } | | 164 | + | | 165 | + @Override | | 166 | + public int hashCode() { | | 167 | + int result = 1; | | 168 | + result = HASH_CODE_PRIME * result + content().hashCode(); | | 169 | + result = HASH_CODE_PRIME * result + trailingHeaders().hashCode(); | | 170 | + result = HASH_CODE_PRIME * result + super.hashCode(); | | 171 | + return result; | | 172 | + } | | 173 | + | | 174 | + @Override | | 175 | + public boolean equals(Object o) { | | 176 | + if (!(o instanceof DefaultFullHttpRequest)) { | | 177 | + return false; | | 178 | + } | | 179 | + | | 180 | + DefaultFullHttpRequest other = (DefaultFullHttpRequest) o; | | 181 | + | | 182 | + return super.equals(other) && | | 183 | + content().equals(other.content()) && | | 184 | + trailingHeaders().equals(other.trailingHeaders()); | | 185 | + } | | 186 | + | | 187 | + @Override | | 188 | + public String toString() { | | 189 | + StringBuilder buf = new StringBuilder(); | | 190 | + appendAll(buf); | | 191 | + buf.append(StringUtil.NEWLINE); | | 192 | + appendHeaders(buf, trailingHeaders()); | | 193 | + | | 194 | + // Remove the last newline. | | 195 | + buf.setLength(buf.length() - StringUtil.NEWLINE.length()); | | 196 | + return buf.toString(); | | 197 | + } | 132 | 198 | } |
Collapse file Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/DefaultFullHttpResponse.java +69-4Lines changed: 69 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 17 | 17 |
| 18 | 18 | import io.netty.buffer.ByteBuf; | 19 | 19 | import io.netty.buffer.Unpooled; | | 20 | +import io.netty.util.internal.StringUtil; | 20 | 21 |
| 21 | 22 |
| 22 | 23 | /** | 23 | 24 | * Default implementation of a {@link FullHttpResponse}. | 24 | 25 | */ | 25 | 26 | public class DefaultFullHttpResponse extends DefaultHttpResponse implements FullHttpResponse { | 26 | | - | | 27 | + private static final int HASH_CODE_PRIME = 31; | 27 | 28 | private final ByteBuf content; | 28 | 29 | private final HttpHeaders trailingHeaders; | 29 | 30 | private final boolean validateHeaders; | @@ -36,6 +37,10 @@ public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, B | 36 | 37 | this(version, status, content, true); | 37 | 38 | } | 38 | 39 |
| | 40 | + public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, boolean validateHeaders) { | | 41 | + this(version, status, Unpooled.buffer(0), validateHeaders); | | 42 | + } | | 43 | + | 39 | 44 | public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, | 40 | 45 | ByteBuf content, boolean validateHeaders) { | 41 | 46 | super(version, status, validateHeaders); | @@ -108,15 +113,41 @@ public FullHttpResponse setStatus(HttpResponseStatus status) { | 108 | 113 | return this; | 109 | 114 | } | 110 | 115 |
| 111 | | - @Override | 112 | | - public FullHttpResponse copy() { | | 116 | + /** | | 117 | + * Copy this object | | 118 | + * | | 119 | + * @param copyContent | | 120 | + * <ul> | | 121 | + * <li>{@code true} if this object's {@link #content()} should be used to copy.</li> | | 122 | + * <li>{@code false} if {@code newContent} should be used instead.</li> | | 123 | + * </ul> | | 124 | + * @param newContent | | 125 | + * <ul> | | 126 | + * <li>if {@code copyContent} is false then this will be used in the copy's content.</li> | | 127 | + * <li>if {@code null} then a default buffer of 0 size will be selected</li> | | 128 | + * </ul> | | 129 | + * @return A copy of this object | | 130 | + */ | | 131 | + private FullHttpResponse copy(boolean copyContent, ByteBuf newContent) { | 113 | 132 | DefaultFullHttpResponse copy = new DefaultFullHttpResponse( | 114 | | - protocolVersion(), status(), content().copy(), validateHeaders); | | 133 | + protocolVersion(), status(), | | 134 | + copyContent ? content().copy() : | | 135 | + newContent == null ? Unpooled.buffer(0) : newContent); | 115 | 136 | copy.headers().set(headers()); | 116 | 137 | copy.trailingHeaders().set(trailingHeaders()); | 117 | 138 | return copy; | 118 | 139 | } | 119 | 140 |
| | 141 | + @Override | | 142 | + public FullHttpResponse copy(ByteBuf newContent) { | | 143 | + return copy(false, newContent); | | 144 | + } | | 145 | + | | 146 | + @Override | | 147 | + public FullHttpResponse copy() { | | 148 | + return copy(true, null); | | 149 | + } | | 150 | + | 120 | 151 | @Override | 121 | 152 | public FullHttpResponse duplicate() { | 122 | 153 | DefaultFullHttpResponse duplicate = new DefaultFullHttpResponse(protocolVersion(), status(), | @@ -125,4 +156,38 @@ public FullHttpResponse duplicate() { | 125 | 156 | duplicate.trailingHeaders().set(trailingHeaders()); | 126 | 157 | return duplicate; | 127 | 158 | } | | 159 | + | | 160 | + @Override | | 161 | + public int hashCode() { | | 162 | + int result = 1; | | 163 | + result = HASH_CODE_PRIME * result + content().hashCode(); | | 164 | + result = HASH_CODE_PRIME * result + trailingHeaders().hashCode(); | | 165 | + result = HASH_CODE_PRIME * result + super.hashCode(); | | 166 | + return result; | | 167 | + } | | 168 | + | | 169 | + @Override | | 170 | + public boolean equals(Object o) { | | 171 | + if (!(o instanceof DefaultFullHttpResponse)) { | | 172 | + return false; | | 173 | + } | | 174 | + | | 175 | + DefaultFullHttpResponse other = (DefaultFullHttpResponse) o; | | 176 | + | | 177 | + return super.equals(other) && | | 178 | + content().equals(other.content()) && | | 179 | + trailingHeaders().equals(other.trailingHeaders()); | | 180 | + } | | 181 | + | | 182 | + @Override | | 183 | + public String toString() { | | 184 | + StringBuilder buf = new StringBuilder(); | | 185 | + appendAll(buf); | | 186 | + buf.append(StringUtil.NEWLINE); | | 187 | + appendHeaders(buf, trailingHeaders()); | | 188 | + | | 189 | + // Remove the last newline. | | 190 | + buf.setLength(buf.length() - StringUtil.NEWLINE.length()); | | 191 | + return buf.toString(); | | 192 | + } | 128 | 193 | } |
Collapse file Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpMessage.java +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -104,6 +104,10 @@ public HttpMessage setProtocolVersion(HttpVersion version) { | 104 | 104 | } | 105 | 105 |
| 106 | 106 | void appendHeaders(StringBuilder buf) { | | 107 | + appendHeaders(buf, headers()); | | 108 | + } | | 109 | + | | 110 | + void appendHeaders(StringBuilder buf, HttpHeaders headers) { | 107 | 111 | for (Map.Entry<String, String> e: headers()) { | 108 | 112 | buf.append(e.getKey()); | 109 | 113 | buf.append(": "); | |
Collapse file Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpRequest.java +31-5Lines changed: 31 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 21 | 21 | * The default {@link HttpRequest} implementation. | 22 | 22 | */ | 23 | 23 | public class DefaultHttpRequest extends DefaultHttpMessage implements HttpRequest { | 24 | | - | | 24 | + private static final int HASH_CODE_PRIME = 31; | 25 | 25 | private HttpMethod method; | 26 | 26 | private String uri; | 27 | 27 |
| @@ -90,9 +90,39 @@ public HttpRequest setProtocolVersion(HttpVersion version) { | 90 | 90 | return this; | 91 | 91 | } | 92 | 92 |
| | 93 | + @Override | | 94 | + public int hashCode() { | | 95 | + int result = 1; | | 96 | + result = HASH_CODE_PRIME * result + method.hashCode(); | | 97 | + result = HASH_CODE_PRIME * result + uri.hashCode(); | | 98 | + result = HASH_CODE_PRIME * result + super.hashCode(); | | 99 | + return result; | | 100 | + } | | 101 | + | | 102 | + @Override | | 103 | + public boolean equals(Object o) { | | 104 | + if (!(o instanceof DefaultHttpRequest)) { | | 105 | + return false; | | 106 | + } | | 107 | + | | 108 | + DefaultHttpRequest other = (DefaultHttpRequest) o; | | 109 | + | | 110 | + return method().equals(other.method()) && | | 111 | + uri().equalsIgnoreCase(other.uri()) && | | 112 | + super.equals(o); | | 113 | + } | | 114 | + | 93 | 115 | @Override | 94 | 116 | public String toString() { | 95 | 117 | StringBuilder buf = new StringBuilder(); | | 118 | + appendAll(buf); | | 119 | + | | 120 | + // Remove the last newline. | | 121 | + buf.setLength(buf.length() - StringUtil.NEWLINE.length()); | | 122 | + return buf.toString(); | | 123 | + } | | 124 | + | | 125 | + void appendAll(StringBuilder buf) { | 96 | 126 | buf.append(StringUtil.simpleClassName(this)); | 97 | 127 | buf.append("(decodeResult: "); | 98 | 128 | buf.append(decoderResult()); | @@ -105,9 +135,5 @@ public String toString() { | 105 | 135 | buf.append(protocolVersion().text()); | 106 | 136 | buf.append(StringUtil.NEWLINE); | 107 | 137 | appendHeaders(buf); | 108 | | - | 109 | | - // Remove the last newline. | 110 | | - buf.setLength(buf.length() - StringUtil.NEWLINE.length()); | 111 | | - return buf.toString(); | 112 | 138 | } | 113 | 139 | } |
Collapse file Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpResponse.java +11-8Lines changed: 11 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 21 | 21 | * The default {@link HttpResponse} implementation. | 22 | 22 | */ | 23 | 23 | public class DefaultHttpResponse extends DefaultHttpMessage implements HttpResponse { | 24 | | - | | 24 | + private static final int HASH_CODE_PRIME = 31; | 25 | 25 | private HttpResponseStatus status; | 26 | 26 |
| 27 | 27 | /** | @@ -71,10 +71,9 @@ public HttpResponse setProtocolVersion(HttpVersion version) { | 71 | 71 |
| 72 | 72 | @Override | 73 | 73 | public int hashCode() { | 74 | | - final int prime = 31; | 75 | 74 | int result = 1; | 76 | | - result = prime * result + status.hashCode(); | 77 | | - result = prime * result + super.hashCode(); | | 75 | + result = HASH_CODE_PRIME * result + status.hashCode(); | | 76 | + result = HASH_CODE_PRIME * result + super.hashCode(); | 78 | 77 | return result; | 79 | 78 | } | 80 | 79 |
| @@ -92,6 +91,14 @@ public boolean equals(Object o) { | 92 | 91 | @Override | 93 | 92 | public String toString() { | 94 | 93 | StringBuilder buf = new StringBuilder(); | | 94 | + appendAll(buf); | | 95 | + | | 96 | + // Remove the last newline. | | 97 | + buf.setLength(buf.length() - StringUtil.NEWLINE.length()); | | 98 | + return buf.toString(); | | 99 | + } | | 100 | + | | 101 | + void appendAll(StringBuilder buf) { | 95 | 102 | buf.append(StringUtil.simpleClassName(this)); | 96 | 103 | buf.append("(decodeResult: "); | 97 | 104 | buf.append(decoderResult()); | @@ -102,9 +109,5 @@ public String toString() { | 102 | 109 | buf.append(status()); | 103 | 110 | buf.append(StringUtil.NEWLINE); | 104 | 111 | appendHeaders(buf); | 105 | | - | 106 | | - // Remove the last newline. | 107 | | - buf.setLength(buf.length() - StringUtil.NEWLINE.length()); | 108 | | - return buf.toString(); | 109 | 112 | } | 110 | 113 | } |
Collapse file Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/FullHttpMessage.java +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 | */ | 16 | 16 | package io.netty.handler.codec.http; | 17 | 17 |
| | 18 | +import io.netty.buffer.ByteBuf; | | 19 | + | 18 | 20 | /** | 19 | 21 | * Combines {@link HttpMessage} and {@link LastHttpContent} into one | 20 | 22 | * message. So it represent a <i>complete</i> http message. | 21 | 23 | */ | 22 | 24 | public interface FullHttpMessage extends HttpMessage, LastHttpContent { | | 25 | + /** | | 26 | + * Create a copy of this {@link FullHttpMessage} with alternative content. | | 27 | + * | | 28 | + * @param newContent The buffer to use instead of this {@link FullHttpMessage}'s content in the copy operation. | | 29 | + * <p> | | 30 | + * NOTE: retain will NOT be called on this buffer. {@code null} results in an empty default choice buffer. | | 31 | + * @return The result of the copy operation | | 32 | + */ | | 33 | + FullHttpMessage copy(ByteBuf newContent); | | 34 | + | 23 | 35 | @Override | 24 | 36 | FullHttpMessage copy(); | 25 | 37 |
| |
Collapse file Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/FullHttpRequest.java +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 | */ | 16 | 16 | package io.netty.handler.codec.http; | 17 | 17 |
| | 18 | +import io.netty.buffer.ByteBuf; | | 19 | + | 18 | 20 | /** | 19 | | - * Combinate the {@link HttpRequest} and {@link FullHttpMessage}, so the request is a <i>complete</i> HTTP | 20 | | - * request. | | 21 | + * Combinate the {@link HttpRequest} and {@link FullHttpMessage}, so the request is a <i>complete</i> HTTP request. | 21 | 22 | */ | 22 | 23 | public interface FullHttpRequest extends HttpRequest, FullHttpMessage { | | 24 | + @Override | | 25 | + FullHttpRequest copy(ByteBuf newContent); | | 26 | + | 23 | 27 | @Override | 24 | 28 | FullHttpRequest copy(); | 25 | 29 |
| |
Collapse file Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/FullHttpResponse.java +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 | */ | 16 | 16 | package io.netty.handler.codec.http; | 17 | 17 |
| | 18 | +import io.netty.buffer.ByteBuf; | | 19 | + | 18 | 20 | /** | 19 | | - * Combination of a {@link HttpResponse} and {@link FullHttpMessage}. | 20 | | - * So it represent a <i>complete</i> http response. | | 21 | + * Combination of a {@link HttpResponse} and {@link FullHttpMessage}. So it represent a <i>complete</i> http response. | 21 | 22 | */ | 22 | 23 | public interface FullHttpResponse extends HttpResponse, FullHttpMessage { | | 24 | + @Override | | 25 | + FullHttpResponse copy(ByteBuf newContent); | | 26 | + | 23 | 27 | @Override | 24 | 28 | FullHttpResponse copy(); | 25 | 29 |
| |
|