/** * @return a configured instance of {@link RawHttpOptions}. * @see RawHttp#RawHttp(RawHttpOptions) */ public RawHttpOptions build() { HttpBodyEncodingRegistry registry = encodingRegistry == null ? new ServiceLoaderHttpBodyEncodingRegistry() : encodingRegistry; return new RawHttpOptions(insertHostHeaderIfMissing, insertHttpVersionIfMissing, allowNewLineWithoutReturn, ignoreLeadingEmptyLine, httpHeadersOptionsBuilder.getOptions(), registry); }
public ChunkedBodyParser(HttpMetadataParser metadataParser) { this.metadataParser = metadataParser; this.allowNewLineWithoutReturn = metadataParser.getOptions().allowNewLineWithoutReturn(); }
/** * Create a new instance of {@link RawHttp} using the default {@link RawHttpOptions} instance. */ public RawHttp() { this(RawHttpOptions.defaultInstance()); }
final boolean allowNewLineWithoutReturn = options.allowNewLineWithoutReturn(); StringBuilder metadataBuilder = new StringBuilder(); int length = 0; int lengthLimit = options.getHttpHeadersOptions().getMaxHeaderNameLength(); parsingValue = true; length = -1; lengthLimit = options.getHttpHeadersOptions().getMaxHeaderValueLength(); } else if (c == '\n' || c == '\r') { throw createError.apply("Invalid header: missing the ':' separator", lineNumber);
/** * @return an instance of {@link RawHttpOptions} that is as strict as the HTTP specification. It will not, * for example, allow LF without a CR character, or insert a Host header in a request when it's missing. */ public static RawHttpOptions strict() { return RawHttpOptions.newBuilder() .doNotAllowNewLineWithoutReturn() .doNotInsertHostHeaderIfMissing() .build(); }
/** * Parses the HTTP messages' request-line from the given input stream. * * @param inputStream supplying the request-line * @return request-line * @throws IOException if an error occurs while consuming the stream */ public RequestLine parseRequestLine(InputStream inputStream) throws IOException { return buildRequestLine(parseStartLine(inputStream, InvalidHttpRequest::new, options.ignoreLeadingEmptyLine())); }
if (options.insertHttpVersionIfMissing()) { version = HttpVersion.HTTP_1_1; } else {
/** * @return a strict HTTP metadata parser (uses {@link RawHttpOptions#strict()}. */ public static HttpMetadataParser createStrictHttpMetadataParser() { return new HttpMetadataParser(RawHttpOptions.strict()); }
/** * Parses the HTTP messages' headers from the given input stream. * * @param inputStream supplying the header fields * @param createError error factory - used in case an error is encountered * @return the {@link RawHttpHeaders} * @throws IOException if an error occurs while consuming the stream */ public RawHttpHeaders parseHeaders(InputStream inputStream, BiFunction<String, Integer, RuntimeException> createError) throws IOException { RawHttpHeaders headers = buildHeaders(inputStream, createError).build(); options.getHttpHeadersOptions().getHeadersValidator().accept(headers); return headers; }
@Nullable String requestLineHost = requestLineUri.getHost(); if (hostHeaderValues.isEmpty()) { if (!options.insertHostHeaderIfMissing()) { throw new InvalidHttpRequest("Host header is missing", 1); } else if (requestLineHost == null) {
BodyDecoder bodyDecoder = new BodyDecoder(options.getEncodingRegistry(), encodings);
final boolean allowNewLineWithoutReturn = options.allowNewLineWithoutReturn(); StringBuilder metadataBuilder = new StringBuilder(); int length = 0; int lengthLimit = options.getHttpHeadersOptions().getMaxHeaderNameLength(); parsingValue = true; length = -1; lengthLimit = options.getHttpHeadersOptions().getMaxHeaderValueLength(); } else if (c == '\n' || c == '\r') { throw createError.apply("Invalid header: missing the ':' separator", lineNumber);
/** * @return an instance of {@link RawHttpOptions} that is as strict as the HTTP specification. It will not, * for example, allow LF without a CR character, or insert a Host header in a request when it's missing. */ public static RawHttpOptions strict() { return RawHttpOptions.newBuilder() .doNotAllowNewLineWithoutReturn() .doNotInsertHostHeaderIfMissing() .build(); }
/** * Parses a HTTP response's status-line. * * @param inputStream providing the status-line * @return the status-line * @throws InvalidHttpResponse if the status-line is invalid * @throws IOException if an error occurs while consuming the stream */ public StatusLine parseStatusLine(InputStream inputStream) throws IOException { return buildStatusLine(parseStartLine(inputStream, InvalidHttpResponse::new, options.ignoreLeadingEmptyLine())); }
if (options.insertHttpVersionIfMissing()) { version = HttpVersion.HTTP_1_1; } else {
/** * @return a strict HTTP metadata parser (uses {@link RawHttpOptions#strict()}. */ public static HttpMetadataParser createStrictHttpMetadataParser() { return new HttpMetadataParser(RawHttpOptions.strict()); }
/** * Parses the HTTP messages' headers from the given input stream. * * @param inputStream supplying the header fields * @param createError error factory - used in case an error is encountered * @return the {@link RawHttpHeaders} * @throws IOException if an error occurs while consuming the stream */ public RawHttpHeaders parseHeaders(InputStream inputStream, BiFunction<String, Integer, RuntimeException> createError) throws IOException { RawHttpHeaders headers = buildHeaders(inputStream, createError).build(); options.getHttpHeadersOptions().getHeadersValidator().accept(headers); return headers; }
@Nullable String requestLineHost = requestLineUri.getHost(); if (hostHeaderValues.isEmpty()) { if (!options.insertHostHeaderIfMissing()) { throw new InvalidHttpRequest("Host header is missing", 1); } else if (requestLineHost == null) {
BodyDecoder bodyDecoder = new BodyDecoder(options.getEncodingRegistry(), encodings);
/** * Create a new instance of {@link RawHttp} using the default {@link RawHttpOptions} instance. */ public RawHttp() { this(RawHttpOptions.defaultInstance()); }