src/java.net.http/share/classes/jdk/internal/net/http/Http1HeaderParser.java
author mbaesken
Thu, 28 Nov 2019 13:02:39 +0100
changeset 59323 ae2eb76c486d
parent 55392 444b2d3471e9
permissions -rw-r--r--
8234821: remove unused functions from libjli Reviewed-by: clanger, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
     1
/*
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48535
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
     4
 *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    10
 *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    15
 * accompanied this code).
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    16
 *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    20
 *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    23
 * questions.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    24
 */
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    25
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48535
diff changeset
    26
package jdk.internal.net.http;
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    27
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    28
import java.net.ProtocolException;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    29
import java.nio.ByteBuffer;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    30
import java.util.ArrayList;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    31
import java.util.HashMap;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    32
import java.util.List;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    33
import java.util.Locale;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    34
import java.util.Map;
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48535
diff changeset
    35
import java.net.http.HttpHeaders;
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    36
import static java.lang.String.format;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    37
import static java.util.Objects.requireNonNull;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    38
import static jdk.internal.net.http.common.Utils.ACCEPT_ALL;
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    39
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    40
class Http1HeaderParser {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    41
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    42
    private static final char CR = '\r';
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    43
    private static final char LF = '\n';
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    44
    private static final char HT = '\t';
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    45
    private static final char SP = ' ';
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    46
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    47
    private StringBuilder sb = new StringBuilder();
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    48
    private String statusLine;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    49
    private int responseCode;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    50
    private HttpHeaders headers;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    51
    private Map<String,List<String>> privateMap = new HashMap<>();
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    52
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    53
    enum State { INITIAL,
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    54
                 STATUS_LINE,
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    55
                 STATUS_LINE_FOUND_CR,
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    56
                 STATUS_LINE_FOUND_LF,
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    57
                 STATUS_LINE_END,
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    58
                 STATUS_LINE_END_CR,
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    59
                 STATUS_LINE_END_LF,
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    60
                 HEADER,
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    61
                 HEADER_FOUND_CR,
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    62
                 HEADER_FOUND_LF,
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    63
                 HEADER_FOUND_CR_LF,
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    64
                 HEADER_FOUND_CR_LF_CR,
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    65
                 FINISHED }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    66
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    67
    private State state = State.INITIAL;
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    68
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    69
    /** Returns the status-line. */
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    70
    String statusLine() { return statusLine; }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    71
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    72
    /** Returns the response code. */
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    73
    int responseCode() { return responseCode; }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    74
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    75
    /** Returns the headers, possibly empty. */
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    76
    HttpHeaders headers() {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    77
        assert state == State.FINISHED : "Unexpected state " + state;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    78
        return headers;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    79
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    80
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    81
    /** A current-state message suitable for inclusion in an exception detail message. */
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    82
    public String currentStateMessage() {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    83
        String stateName = state.name();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    84
        String msg;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    85
        if (stateName.contains("INITIAL")) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    86
            return format("HTTP/1.1 header parser received no bytes");
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    87
        } else if (stateName.contains("STATUS")) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    88
            msg = format("parsing HTTP/1.1 status line, receiving [%s]", sb.toString());
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    89
        } else if (stateName.contains("HEADER")) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    90
            String headerName = sb.toString();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    91
            if (headerName.indexOf(':') != -1)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    92
                headerName = headerName.substring(0, headerName.indexOf(':')+1) + "...";
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    93
            msg = format("parsing HTTP/1.1 header, receiving [%s]", headerName);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    94
        } else {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    95
            msg =format("HTTP/1.1 parser receiving [%s]", state, sb.toString());
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    96
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    97
        return format("%s, parser state [%s]", msg , state);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
    98
    }
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
    99
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   100
    /**
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   101
     * Parses HTTP/1.X status-line and headers from the given bytes. Must be
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   102
     * called successive times, with additional data, until returns true.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   103
     *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   104
     * All given ByteBuffers will be consumed, until ( possibly ) the last one
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   105
     * ( when true is returned ), which may not be fully consumed.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   106
     *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   107
     * @param input the ( partial ) header data
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   108
     * @return true iff the end of the headers block has been reached
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   109
     */
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   110
    boolean parse(ByteBuffer input) throws ProtocolException {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   111
        requireNonNull(input, "null input");
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   112
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   113
        while (canContinueParsing(input)) {
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   114
            switch (state) {
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   115
                case INITIAL:
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   116
                    state = State.STATUS_LINE;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   117
                    break;
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   118
                case STATUS_LINE:
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   119
                    readResumeStatusLine(input);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   120
                    break;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   121
                // fallthrough
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   122
                case STATUS_LINE_FOUND_CR:
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   123
                case STATUS_LINE_FOUND_LF:
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   124
                    readStatusLineFeed(input);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   125
                    break;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   126
                case STATUS_LINE_END:
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   127
                    maybeStartHeaders(input);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   128
                    break;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   129
                // fallthrough
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   130
                case STATUS_LINE_END_CR:
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   131
                case STATUS_LINE_END_LF:
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   132
                    maybeEndHeaders(input);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   133
                    break;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   134
                case HEADER:
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   135
                    readResumeHeader(input);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   136
                    break;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   137
                // fallthrough
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   138
                case HEADER_FOUND_CR:
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   139
                case HEADER_FOUND_LF:
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   140
                    resumeOrLF(input);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   141
                    break;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   142
                case HEADER_FOUND_CR_LF:
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   143
                    resumeOrSecondCR(input);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   144
                    break;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   145
                case HEADER_FOUND_CR_LF_CR:
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   146
                    resumeOrEndHeaders(input);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   147
                    break;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   148
                default:
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   149
                    throw new InternalError(
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   150
                            "Unexpected state: " + String.valueOf(state));
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   151
            }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   152
        }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   153
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   154
        return state == State.FINISHED;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   155
    }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   156
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   157
    private boolean canContinueParsing(ByteBuffer buffer) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   158
        // some states don't require any input to transition
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   159
        // to the next state.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   160
        switch (state) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   161
            case FINISHED: return false;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   162
            case STATUS_LINE_FOUND_LF: return true;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   163
            case STATUS_LINE_END_LF: return true;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   164
            case HEADER_FOUND_LF: return true;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   165
            default: return buffer.hasRemaining();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   166
        }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   167
    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   168
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   169
    private void readResumeStatusLine(ByteBuffer input) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   170
        char c = 0;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   171
        while (input.hasRemaining() && (c =(char)input.get()) != CR) {
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   172
            if (c == LF) break;
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   173
            sb.append(c);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   174
        }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   175
        if (c == CR) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   176
            state = State.STATUS_LINE_FOUND_CR;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   177
        } else if (c == LF) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   178
            state = State.STATUS_LINE_FOUND_LF;
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   179
        }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   180
    }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   181
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   182
    private void readStatusLineFeed(ByteBuffer input) throws ProtocolException {
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   183
        char c = state == State.STATUS_LINE_FOUND_LF ? LF : (char)input.get();
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   184
        if (c != LF) {
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   185
            throw protocolException("Bad trailing char, \"%s\", when parsing status line, \"%s\"",
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   186
                                    c, sb.toString());
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   187
        }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   188
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   189
        statusLine = sb.toString();
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   190
        sb = new StringBuilder();
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   191
        if (!statusLine.startsWith("HTTP/1.")) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   192
            throw protocolException("Invalid status line: \"%s\"", statusLine);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   193
        }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   194
        if (statusLine.length() < 12) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   195
            throw protocolException("Invalid status line: \"%s\"", statusLine);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   196
        }
55392
444b2d3471e9 8217705: HttpClient - wrong exception type when bad status line is received
jpai
parents: 50681
diff changeset
   197
        try {
444b2d3471e9 8217705: HttpClient - wrong exception type when bad status line is received
jpai
parents: 50681
diff changeset
   198
            responseCode = Integer.parseInt(statusLine.substring(9, 12));
444b2d3471e9 8217705: HttpClient - wrong exception type when bad status line is received
jpai
parents: 50681
diff changeset
   199
        } catch (NumberFormatException nfe) {
444b2d3471e9 8217705: HttpClient - wrong exception type when bad status line is received
jpai
parents: 50681
diff changeset
   200
            throw protocolException("Invalid status line: \"%s\"", statusLine);
444b2d3471e9 8217705: HttpClient - wrong exception type when bad status line is received
jpai
parents: 50681
diff changeset
   201
        }
444b2d3471e9 8217705: HttpClient - wrong exception type when bad status line is received
jpai
parents: 50681
diff changeset
   202
        // response code expected to be a 3-digit integer (RFC-2616, section 6.1.1)
444b2d3471e9 8217705: HttpClient - wrong exception type when bad status line is received
jpai
parents: 50681
diff changeset
   203
        if (responseCode < 100) {
444b2d3471e9 8217705: HttpClient - wrong exception type when bad status line is received
jpai
parents: 50681
diff changeset
   204
            throw protocolException("Invalid status line: \"%s\"", statusLine);
444b2d3471e9 8217705: HttpClient - wrong exception type when bad status line is received
jpai
parents: 50681
diff changeset
   205
        }
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   206
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   207
        state = State.STATUS_LINE_END;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   208
    }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   209
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   210
    private void maybeStartHeaders(ByteBuffer input) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   211
        assert state == State.STATUS_LINE_END;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   212
        assert sb.length() == 0;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   213
        char c = (char)input.get();
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   214
        if (c == CR) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   215
            state = State.STATUS_LINE_END_CR;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   216
        } else if (c == LF) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   217
            state = State.STATUS_LINE_END_LF;
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   218
        } else {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   219
            sb.append(c);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   220
            state = State.HEADER;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   221
        }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   222
    }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   223
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   224
    private void maybeEndHeaders(ByteBuffer input) throws ProtocolException {
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   225
        assert state == State.STATUS_LINE_END_CR || state == State.STATUS_LINE_END_LF;
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   226
        assert sb.length() == 0;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   227
        char c = state == State.STATUS_LINE_END_LF ? LF : (char)input.get();
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   228
        if (c == LF) {
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   229
            headers = HttpHeaders.of(privateMap, ACCEPT_ALL);
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   230
            privateMap = null;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   231
            state = State.FINISHED;  // no headers
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   232
        } else {
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   233
            throw protocolException("Unexpected \"%s\", after status line CR", c);
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   234
        }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   235
    }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   236
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   237
    private void readResumeHeader(ByteBuffer input) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   238
        assert state == State.HEADER;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   239
        assert input.hasRemaining();
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   240
        while (input.hasRemaining()) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   241
            char c = (char)input.get();
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   242
            if (c == CR) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   243
                state = State.HEADER_FOUND_CR;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   244
                break;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   245
            } else if (c == LF) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   246
                state = State.HEADER_FOUND_LF;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   247
                break;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   248
            }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   249
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   250
            if (c == HT)
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   251
                c = SP;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   252
            sb.append(c);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   253
        }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   254
    }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   255
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   256
    private void addHeaderFromString(String headerString) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   257
        assert sb.length() == 0;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   258
        int idx = headerString.indexOf(':');
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   259
        if (idx == -1)
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   260
            return;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   261
        String name = headerString.substring(0, idx).trim();
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   262
        if (name.isEmpty())
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   263
            return;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   264
        String value = headerString.substring(idx + 1, headerString.length()).trim();
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   265
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   266
        privateMap.computeIfAbsent(name.toLowerCase(Locale.US),
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   267
                                   k -> new ArrayList<>()).add(value);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   268
    }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   269
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   270
    private void resumeOrLF(ByteBuffer input) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   271
        assert state == State.HEADER_FOUND_CR || state == State.HEADER_FOUND_LF;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   272
        char c = state == State.HEADER_FOUND_LF ? LF : (char)input.get();
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   273
        if (c == LF) {
48535
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   274
            // header value will be flushed by
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   275
            // resumeOrSecondCR if next line does not
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   276
            // begin by SP or HT
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   277
            state = State.HEADER_FOUND_CR_LF;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   278
        } else if (c == SP || c == HT) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   279
            sb.append(SP); // parity with MessageHeaders
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   280
            state = State.HEADER;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   281
        } else {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   282
            sb = new StringBuilder();
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   283
            sb.append(c);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   284
            state = State.HEADER;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   285
        }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   286
    }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   287
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   288
    private void resumeOrSecondCR(ByteBuffer input) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   289
        assert state == State.HEADER_FOUND_CR_LF;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   290
        char c = (char)input.get();
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   291
        if (c == CR || c == LF) {
48535
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   292
            if (sb.length() > 0) {
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   293
                // no continuation line - flush
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   294
                // previous header value.
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   295
                String headerString = sb.toString();
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   296
                sb = new StringBuilder();
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   297
                addHeaderFromString(headerString);
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   298
            }
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   299
            if (c == CR) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   300
                state = State.HEADER_FOUND_CR_LF_CR;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   301
            } else {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   302
                state = State.FINISHED;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   303
                headers = HttpHeaders.of(privateMap, ACCEPT_ALL);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   304
                privateMap = null;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   305
            }
48535
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   306
        } else if (c == SP || c == HT) {
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   307
            assert sb.length() != 0;
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   308
            sb.append(SP); // continuation line
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   309
            state = State.HEADER;
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   310
        } else {
48535
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   311
            if (sb.length() > 0) {
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   312
                // no continuation line - flush
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   313
                // previous header value.
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   314
                String headerString = sb.toString();
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   315
                sb = new StringBuilder();
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   316
                addHeaderFromString(headerString);
5f9977540ac9 8195138: The asynchronous Http1HeaderParser doesn't handle all line folds correctly
dfuchs
parents: 48083
diff changeset
   317
            }
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   318
            sb.append(c);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   319
            state = State.HEADER;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   320
        }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   321
    }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   322
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   323
    private void resumeOrEndHeaders(ByteBuffer input) throws ProtocolException {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   324
        assert state == State.HEADER_FOUND_CR_LF_CR;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   325
        char c = (char)input.get();
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   326
        if (c == LF) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   327
            state = State.FINISHED;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49765
diff changeset
   328
            headers = HttpHeaders.of(privateMap, ACCEPT_ALL);
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   329
            privateMap = null;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   330
        } else {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   331
            throw protocolException("Unexpected \"%s\", after CR LF CR", c);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   332
        }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   333
    }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   334
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   335
    private ProtocolException protocolException(String format, Object... args) {
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   336
        return new ProtocolException(format(format, args));
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   337
    }
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents:
diff changeset
   338
}