/** * @return the transfer encodings applied to the HTTP message body. * <p> * RFC-7230 explicitly mentions "chunked", "compress", "deflate" and "gzip", but others may also be applied * as long as they are included in the * <a href="https://tools.ietf.org/html/rfc7230#section-8.4">Transfer Coding Registry</a>. * <p> * RawHTTP can support custom encodings by being given custom implementations of * {@link rawhttp.core.body.encoding.HttpBodyEncodingRegistry} or, more simply, by using the * {@link rawhttp.core.body.encoding.ServiceLoaderHttpBodyEncodingRegistry} mechanism, which is the default. */ public List<String> getEncodings() { return bodyDecoder.getEncodings(); }
/** * @return the transfer encodings applied to the HTTP message body. * <p> * RFC-7230 explicitly mentions "chunked", "compress", "deflate" and "gzip", but others may also be applied * as long as they are included in the * <a href="https://tools.ietf.org/html/rfc7230#section-8.4">Transfer Coding Registry</a>. * <p> * RawHTTP can support custom encodings by being given custom implementations of * {@link rawhttp.core.body.encoding.HttpBodyEncodingRegistry} or, more simply, by using the * {@link rawhttp.core.body.encoding.ServiceLoaderHttpBodyEncodingRegistry} mechanism, which is the default. */ public List<String> getEncodings() { return bodyDecoder.getEncodings(); }
/** * Create a new instance of the {@link Chunked} body type. * * @param bodyDecoder the body encoding * @param metadataParser parser for the body trailer part */ public Chunked(BodyDecoder bodyDecoder, HttpMetadataParser metadataParser) { super(bodyDecoder); assert "chunked".equalsIgnoreCase(bodyDecoder.getEncodings().get(bodyDecoder.getEncodings().size() - 1)); this.bodyParser = new ChunkedBodyParser(metadataParser); }
/** * Create a new instance of the {@link Chunked} body type. * * @param bodyDecoder the body encoding * @param metadataParser parser for the body trailer part */ public Chunked(BodyDecoder bodyDecoder, HttpMetadataParser metadataParser) { super(bodyDecoder); assert "chunked".equalsIgnoreCase(bodyDecoder.getEncodings().get(bodyDecoder.getEncodings().size() - 1)); this.bodyParser = new ChunkedBodyParser(metadataParser); }
/** * Create a new {@link ChunkedBody} to encode the contents of the given stream. * <p> * The stream is read lazily, so it shouldn't be closed until this body is consumed. * * @param stream content to encode * @param contentType Content-Type of the stream contents * @param chunkLength the length of each chunk * @param bodyDecoder decoder capable of decoding the body. The last encoding must be "chunked". * @param metadataParser metadata parser (chunked body may contain metadata) * @throws IllegalArgumentException if the bodyDecoder's last encoding is not "chunked" */ public ChunkedBody(InputStream stream, @Nullable String contentType, int chunkLength, BodyDecoder bodyDecoder, HttpMetadataParser metadataParser) { super(contentType, bodyDecoder); this.stream = stream; this.chunkLength = chunkLength; this.metadataParser = metadataParser; validateEncodings(bodyDecoder.getEncodings()); }
/** * Create a new {@link ChunkedBody} to encode the contents of the given stream. * <p> * The stream is read lazily, so it shouldn't be closed until this body is consumed. * * @param stream content to encode * @param contentType Content-Type of the stream contents * @param chunkLength the length of each chunk * @param bodyDecoder decoder capable of decoding the body. The last encoding must be "chunked". * @param metadataParser metadata parser (chunked body may contain metadata) * @throws IllegalArgumentException if the bodyDecoder's last encoding is not "chunked" */ public ChunkedBody(InputStream stream, @Nullable String contentType, int chunkLength, BodyDecoder bodyDecoder, HttpMetadataParser metadataParser) { super(contentType, bodyDecoder); this.stream = stream; this.chunkLength = chunkLength; this.metadataParser = metadataParser; validateEncodings(bodyDecoder.getEncodings()); }
/** * @param headers headers object to adapt to include this HTTP message body. * @return adjusted headers for this HTTP message body. * The Content-Type and Content-Length headers may be modified to fit a HTTP message * containing this body. If the body is encoded, the Transfer-Encoding header will be set. */ public RawHttpHeaders headersFrom(RawHttpHeaders headers) { RawHttpHeaders.Builder builder = RawHttpHeaders.newBuilder(headers); getContentType().ifPresent(contentType -> builder.overwrite("Content-Type", contentType)); getContentLength().ifPresent(length -> builder.overwrite("Content-Length", Long.toString(length))); Optional.ofNullable(bodyDecoder).ifPresent(decoder -> { if (!decoder.getEncodings().isEmpty()) { builder.overwrite("Transfer-Encoding", String.join(",", decoder.getEncodings())); } }); return builder.build(); }
/** * @param headers headers object to adapt to include this HTTP message body. * @return adjusted headers for this HTTP message body. * The Content-Type and Content-Length headers may be modified to fit a HTTP message * containing this body. If the body is encoded, the Transfer-Encoding header will be set. */ public RawHttpHeaders headersFrom(RawHttpHeaders headers) { RawHttpHeaders.Builder builder = RawHttpHeaders.newBuilder(headers); getContentType().ifPresent(contentType -> builder.overwrite("Content-Type", contentType)); getContentLength().ifPresent(length -> builder.overwrite("Content-Length", Long.toString(length))); Optional.ofNullable(bodyDecoder).ifPresent(decoder -> { if (!decoder.getEncodings().isEmpty()) { builder.overwrite("Transfer-Encoding", String.join(",", decoder.getEncodings())); } }); return builder.build(); }