< prev index next >

src/java.net.http/share/classes/jdk/internal/net/http/Http1HeaderParser.java

Print this page




 177         } else if (c == LF) {
 178             state = State.STATUS_LINE_FOUND_LF;
 179         }
 180     }
 181 
 182     private void readStatusLineFeed(ByteBuffer input) throws ProtocolException {
 183         char c = state == State.STATUS_LINE_FOUND_LF ? LF : (char)input.get();
 184         if (c != LF) {
 185             throw protocolException("Bad trailing char, \"%s\", when parsing status line, \"%s\"",
 186                                     c, sb.toString());
 187         }
 188 
 189         statusLine = sb.toString();
 190         sb = new StringBuilder();
 191         if (!statusLine.startsWith("HTTP/1.")) {
 192             throw protocolException("Invalid status line: \"%s\"", statusLine);
 193         }
 194         if (statusLine.length() < 12) {
 195             throw protocolException("Invalid status line: \"%s\"", statusLine);
 196         }
 197         try {
 198             responseCode = Integer.parseInt(statusLine.substring(9, 12));
 199         } catch (NumberFormatException nfe) {
 200             throw protocolException("Invalid status line: \"%s\"", statusLine);
 201         }
 202         // response code expected to be a 3-digit integer (RFC-2616, section 6.1.1)
 203         if (responseCode < 100) {
 204             throw protocolException("Invalid status line: \"%s\"", statusLine);
 205         }
 206 
 207         state = State.STATUS_LINE_END;
 208     }
 209 
 210     private void maybeStartHeaders(ByteBuffer input) {
 211         assert state == State.STATUS_LINE_END;
 212         assert sb.length() == 0;
 213         char c = (char)input.get();
 214         if (c == CR) {
 215             state = State.STATUS_LINE_END_CR;
 216         } else if (c == LF) {
 217             state = State.STATUS_LINE_END_LF;
 218         } else {
 219             sb.append(c);
 220             state = State.HEADER;
 221         }
 222     }
 223 
 224     private void maybeEndHeaders(ByteBuffer input) throws ProtocolException {
 225         assert state == State.STATUS_LINE_END_CR || state == State.STATUS_LINE_END_LF;




 177         } else if (c == LF) {
 178             state = State.STATUS_LINE_FOUND_LF;
 179         }
 180     }
 181 
 182     private void readStatusLineFeed(ByteBuffer input) throws ProtocolException {
 183         char c = state == State.STATUS_LINE_FOUND_LF ? LF : (char)input.get();
 184         if (c != LF) {
 185             throw protocolException("Bad trailing char, \"%s\", when parsing status line, \"%s\"",
 186                                     c, sb.toString());
 187         }
 188 
 189         statusLine = sb.toString();
 190         sb = new StringBuilder();
 191         if (!statusLine.startsWith("HTTP/1.")) {
 192             throw protocolException("Invalid status line: \"%s\"", statusLine);
 193         }
 194         if (statusLine.length() < 12) {
 195             throw protocolException("Invalid status line: \"%s\"", statusLine);
 196         }
 197         responseCode = Integer.parseInt(statusLine.substring(9, 12));








 198 
 199         state = State.STATUS_LINE_END;
 200     }
 201 
 202     private void maybeStartHeaders(ByteBuffer input) {
 203         assert state == State.STATUS_LINE_END;
 204         assert sb.length() == 0;
 205         char c = (char)input.get();
 206         if (c == CR) {
 207             state = State.STATUS_LINE_END_CR;
 208         } else if (c == LF) {
 209             state = State.STATUS_LINE_END_LF;
 210         } else {
 211             sb.append(c);
 212             state = State.HEADER;
 213         }
 214     }
 215 
 216     private void maybeEndHeaders(ByteBuffer input) throws ProtocolException {
 217         assert state == State.STATUS_LINE_END_CR || state == State.STATUS_LINE_END_LF;


< prev index next >