Mercurial Hosting > luan
comparison src/org/eclipse/jetty/http/HttpParser.java @ 1025:cf0367978d8b
remove View.CaseInsensitive
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 02 Nov 2016 23:46:43 -0600 |
parents | 3718afd99988 |
children | 2ea54e6117c3 |
comparison
equal
deleted
inserted
replaced
1024:be50ffc0ad5c | 1025:cf0367978d8b |
---|---|
65 private Buffer _header; // Buffer for header data (and small _content) | 65 private Buffer _header; // Buffer for header data (and small _content) |
66 private Buffer _body; // Buffer for large content | 66 private Buffer _body; // Buffer for large content |
67 private Buffer _buffer; // The current buffer in use (either _header or _content) | 67 private Buffer _buffer; // The current buffer in use (either _header or _content) |
68 private String _cached; | 68 private String _cached; |
69 private String _tok0; // Saved token: header name, request method or response version | 69 private String _tok0; // Saved token: header name, request method or response version |
70 private final View.CaseInsensitive _tok1 = new View.CaseInsensitive(); // Saved token: header value, request URI or response code | 70 private String _tok1; // Saved token: header value, request URI or response code |
71 private String _multiLineValue; | 71 private String _multiLineValue; |
72 private int _responseStatus; // If >0 then we are parsing a response | 72 private int _responseStatus; // If >0 then we are parsing a response |
73 private boolean _persistent; | 73 private boolean _persistent; |
74 | 74 |
75 protected final View _contentView = new View(); // View of the content in the buffer for {@link Input} | 75 protected final View _contentView = new View(); // View of the content in the buffer for {@link Input} |
322 break; | 322 break; |
323 | 323 |
324 case STATE_STATUS: | 324 case STATE_STATUS: |
325 if (ch == HttpTokens.SPACE) | 325 if (ch == HttpTokens.SPACE) |
326 { | 326 { |
327 _tok1.update(_buffer.markIndex(), _buffer.getIndex() - 1); | 327 // _tok1.update(_buffer.markIndex(), _buffer.getIndex() - 1); |
328 _tok1 = _buffer.peek(_buffer.markIndex(), _buffer.getIndex() - 1 - _buffer.markIndex()).toString(); | |
328 _state=STATE_SPACE2; | 329 _state=STATE_SPACE2; |
329 continue; | 330 continue; |
330 } | 331 } |
331 else if (ch>='0' && ch<='9') | 332 else if (ch>='0' && ch<='9') |
332 { | 333 { |
337 { | 338 { |
338 _eol=ch; | 339 _eol=ch; |
339 _state=STATE_HEADER; | 340 _state=STATE_HEADER; |
340 // _tok0.setPutIndex(_tok0.getIndex()); | 341 // _tok0.setPutIndex(_tok0.getIndex()); |
341 _tok0 = ""; | 342 _tok0 = ""; |
342 _tok1.setPutIndex(_tok1.getIndex()); | 343 // _tok1.setPutIndex(_tok1.getIndex()); |
344 _tok1 = ""; | |
343 _multiLineValue=null; | 345 _multiLineValue=null; |
344 continue; | 346 continue; |
345 } | 347 } |
346 // not a digit, so must be a URI | 348 // not a digit, so must be a URI |
347 _state=STATE_URI; | 349 _state=STATE_URI; |
349 break; | 351 break; |
350 | 352 |
351 case STATE_URI: | 353 case STATE_URI: |
352 if (ch == HttpTokens.SPACE) | 354 if (ch == HttpTokens.SPACE) |
353 { | 355 { |
354 _tok1.update(_buffer.markIndex(), _buffer.getIndex() - 1); | 356 // _tok1.update(_buffer.markIndex(), _buffer.getIndex() - 1); |
357 _tok1 = _buffer.peek(_buffer.markIndex(), _buffer.getIndex() - 1 - _buffer.markIndex()).toString(); | |
355 _state=STATE_SPACE2; | 358 _state=STATE_SPACE2; |
356 continue; | 359 continue; |
357 } | 360 } |
358 else if (ch < HttpTokens.SPACE && ch>=0) | 361 else if (ch < HttpTokens.SPACE && ch>=0) |
359 { | 362 { |
360 // HTTP/0.9 | 363 // HTTP/0.9 |
361 _handler.startRequest(_tok0, _buffer.sliceFromMark(), null); | 364 _handler.startRequest(_tok0, _buffer.sliceFromMark().toString(), null); |
362 _persistent=false; | 365 _persistent=false; |
363 _state=STATE_SEEKING_EOF; | 366 _state=STATE_SEEKING_EOF; |
364 _handler.headerComplete(); | 367 _handler.headerComplete(); |
365 _handler.messageComplete(_contentPosition); | 368 _handler.messageComplete(_contentPosition); |
366 return 1; | 369 return 1; |
379 { | 382 { |
380 _eol=ch; | 383 _eol=ch; |
381 _state=STATE_HEADER; | 384 _state=STATE_HEADER; |
382 // _tok0.setPutIndex(_tok0.getIndex()); | 385 // _tok0.setPutIndex(_tok0.getIndex()); |
383 _tok0 = ""; | 386 _tok0 = ""; |
384 _tok1.setPutIndex(_tok1.getIndex()); | 387 // _tok1.setPutIndex(_tok1.getIndex()); |
388 _tok1 = ""; | |
385 _multiLineValue=null; | 389 _multiLineValue=null; |
386 } | 390 } |
387 else | 391 else |
388 { | 392 { |
389 // HTTP/0.9 | 393 // HTTP/0.9 |
409 _eol=ch; | 413 _eol=ch; |
410 _persistent = HttpVersions.CACHE.getOrdinal(version) >= HttpVersions.HTTP_1_1_ORDINAL; | 414 _persistent = HttpVersions.CACHE.getOrdinal(version) >= HttpVersions.HTTP_1_1_ORDINAL; |
411 _state=STATE_HEADER; | 415 _state=STATE_HEADER; |
412 // _tok0.setPutIndex(_tok0.getIndex()); | 416 // _tok0.setPutIndex(_tok0.getIndex()); |
413 _tok0 = ""; | 417 _tok0 = ""; |
414 _tok1.setPutIndex(_tok1.getIndex()); | 418 // _tok1.setPutIndex(_tok1.getIndex()); |
419 _tok1 = ""; | |
415 _multiLineValue=null; | 420 _multiLineValue=null; |
416 continue; | 421 continue; |
417 } | 422 } |
418 break; | 423 break; |
419 | 424 |
435 // handler last header if any | 440 // handler last header if any |
436 if (_cached!=null || _tok0.length() > 0 || _tok1.length() > 0 || _multiLineValue != null) | 441 if (_cached!=null || _tok0.length() > 0 || _tok1.length() > 0 || _multiLineValue != null) |
437 { | 442 { |
438 String header = _cached!=null ? _cached : _tok0; | 443 String header = _cached!=null ? _cached : _tok0; |
439 _cached = null; | 444 _cached = null; |
440 String value = _multiLineValue == null ? _tok1.toString() : _multiLineValue; | 445 String value = _multiLineValue == null ? _tok1 : _multiLineValue; |
441 | 446 |
442 int ho = HttpHeaders.CACHE.getOrdinal(header); | 447 int ho = HttpHeaders.CACHE.getOrdinal(header); |
443 if (ho >= 0) | 448 if (ho >= 0) |
444 { | 449 { |
445 int vo; | 450 int vo; |
511 } | 516 } |
512 | 517 |
513 _handler.parsedHeader(header, value); | 518 _handler.parsedHeader(header, value); |
514 // _tok0.setPutIndex(_tok0.getIndex()); | 519 // _tok0.setPutIndex(_tok0.getIndex()); |
515 _tok0 = ""; | 520 _tok0 = ""; |
516 _tok1.setPutIndex(_tok1.getIndex()); | 521 // _tok1.setPutIndex(_tok1.getIndex()); |
522 _tok1 = ""; | |
517 _multiLineValue=null; | 523 _multiLineValue=null; |
518 } | 524 } |
519 _buffer.setMarkIndex(-1); | 525 _buffer.setMarkIndex(-1); |
520 | 526 |
521 // now handle ch | 527 // now handle ch |
678 case HttpTokens.CARRIAGE_RETURN: | 684 case HttpTokens.CARRIAGE_RETURN: |
679 case HttpTokens.LINE_FEED: | 685 case HttpTokens.LINE_FEED: |
680 if (_length > 0) | 686 if (_length > 0) |
681 { | 687 { |
682 if (_tok1.length() == 0) | 688 if (_tok1.length() == 0) |
683 _tok1.update(_buffer.markIndex(), _buffer.markIndex() + _length); | 689 // _tok1.update(_buffer.markIndex(), _buffer.markIndex() + _length); |
690 _tok1 = _buffer.peek(_buffer.markIndex(), _length).toString(); | |
684 else | 691 else |
685 { | 692 { |
686 // Continuation line! | 693 // Continuation line! |
687 if (_multiLineValue == null) _multiLineValue=_tok1.toString(StringUtil.__ISO_8859_1); | 694 if (_multiLineValue == null) _multiLineValue = _tok1; |
688 _tok1.update(_buffer.markIndex(), _buffer.markIndex() + _length); | 695 // _tok1.update(_buffer.markIndex(), _buffer.markIndex() + _length); |
689 _multiLineValue += " " + _tok1.toString(StringUtil.__ISO_8859_1); | 696 _tok1 = _buffer.peek(_buffer.markIndex(), _length).toString(); |
697 _multiLineValue += " " + _tok1; | |
690 } | 698 } |
691 } | 699 } |
692 _eol=ch; | 700 _eol=ch; |
693 _state=STATE_HEADER; | 701 _state=STATE_HEADER; |
694 break; | 702 break; |
711 case HttpTokens.CARRIAGE_RETURN: | 719 case HttpTokens.CARRIAGE_RETURN: |
712 case HttpTokens.LINE_FEED: | 720 case HttpTokens.LINE_FEED: |
713 if (_length > 0) | 721 if (_length > 0) |
714 { | 722 { |
715 if (_tok1.length() == 0) | 723 if (_tok1.length() == 0) |
716 _tok1.update(_buffer.markIndex(), _buffer.markIndex() + _length); | 724 // _tok1.update(_buffer.markIndex(), _buffer.markIndex() + _length); |
725 _tok1 = _buffer.peek(_buffer.markIndex(), _length).toString(); | |
717 else | 726 else |
718 { | 727 { |
719 // Continuation line! | 728 // Continuation line! |
720 if (_multiLineValue == null) _multiLineValue=_tok1.toString(StringUtil.__ISO_8859_1); | 729 if (_multiLineValue == null) _multiLineValue = _tok1; |
721 _tok1.update(_buffer.markIndex(), _buffer.markIndex() + _length); | 730 // _tok1.update(_buffer.markIndex(), _buffer.markIndex() + _length); |
722 _multiLineValue += " " + _tok1.toString(StringUtil.__ISO_8859_1); | 731 _tok1 = _buffer.peek(_buffer.markIndex(), _length).toString(); |
732 _multiLineValue += " " + _tok1; | |
723 } | 733 } |
724 } | 734 } |
725 _eol=ch; | 735 _eol=ch; |
726 _state=STATE_HEADER; | 736 _state=STATE_HEADER; |
727 break; | 737 break; |
1065 _header = _buffers.getHeader(); | 1075 _header = _buffers.getHeader(); |
1066 //System.out.println("qqqqqqqqqqqqqqqq k "+_tok0); | 1076 //System.out.println("qqqqqqqqqqqqqqqq k "+_tok0); |
1067 // _tok0.update(_header); | 1077 // _tok0.update(_header); |
1068 _tok0 = ""; | 1078 _tok0 = ""; |
1069 //System.out.println("qqqqqqqqqqqqqqqq l "+_tok0); | 1079 //System.out.println("qqqqqqqqqqqqqqqq l "+_tok0); |
1070 _tok1.update(_header); | 1080 // _tok1.update(_header); |
1081 _tok1 = ""; | |
1071 } | 1082 } |
1072 return _header; | 1083 return _header; |
1073 } | 1084 } |
1074 | 1085 |
1075 public Buffer blockForContent(long maxIdleTime) throws IOException | 1086 public Buffer blockForContent(long maxIdleTime) throws IOException |
1145 public void parsedHeader(String name, String value) throws IOException; | 1156 public void parsedHeader(String name, String value) throws IOException; |
1146 | 1157 |
1147 /** | 1158 /** |
1148 * This is the method called by parser when the HTTP request line is parsed | 1159 * This is the method called by parser when the HTTP request line is parsed |
1149 */ | 1160 */ |
1150 public abstract void startRequest(String method, Buffer url, String version) | 1161 public abstract void startRequest(String method, String url, String version) |
1151 throws IOException; | 1162 throws IOException; |
1152 | 1163 |
1153 public void earlyEOF(); | 1164 public void earlyEOF(); |
1154 } | 1165 } |
1155 | 1166 |