comparison src/org/eclipse/jetty/http/HttpParser.java @ 1019:f126d30e04a4

start replacing BufferCache with StringCache
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 31 Oct 2016 03:33:42 -0600
parents d2c3ff33387c
children 6be43ef1eb96
comparison
equal deleted inserted replaced
1018:4dc1e1a18661 1019:f126d30e04a4
65 private final EndPoint _endp; 65 private final EndPoint _endp;
66 private Buffer _header; // Buffer for header data (and small _content) 66 private Buffer _header; // Buffer for header data (and small _content)
67 private Buffer _body; // Buffer for large content 67 private Buffer _body; // Buffer for large content
68 private Buffer _buffer; // The current buffer in use (either _header or _content) 68 private Buffer _buffer; // The current buffer in use (either _header or _content)
69 private CachedBuffer _cached; 69 private CachedBuffer _cached;
70 private final View.CaseInsensitive _tok0 = new View.CaseInsensitive(); // Saved token: header name, request method or response version 70 private String _tok0; // Saved token: header name, request method or response version
71 private final View.CaseInsensitive _tok1 = new View.CaseInsensitive(); // Saved token: header value, request URI or response code 71 private final View.CaseInsensitive _tok1 = new View.CaseInsensitive(); // Saved token: header value, request URI or response code
72 private String _multiLineValue; 72 private String _multiLineValue;
73 private int _responseStatus; // If >0 then we are parsing a response 73 private int _responseStatus; // If >0 then we are parsing a response
74 private boolean _persistent; 74 private boolean _persistent;
75 75
170 170
171 if (_state == STATE_END) 171 if (_state == STATE_END)
172 return 0; 172 return 0;
173 173
174 if (_buffer==null) 174 if (_buffer==null)
175 _buffer=getHeaderBuffer(); 175 _buffer = getHeaderBuffer();
176 176
177 177
178 if (_state == STATE_CONTENT && _contentPosition == _contentLength) 178 if (_state == STATE_CONTENT && _contentPosition == _contentLength)
179 { 179 {
180 _state=STATE_END; 180 _state=STATE_END;
288 break; 288 break;
289 289
290 case STATE_FIELD0: 290 case STATE_FIELD0:
291 if (ch == HttpTokens.SPACE) 291 if (ch == HttpTokens.SPACE)
292 { 292 {
293 _tok0.update(_buffer.markIndex(), _buffer.getIndex() - 1); 293 //System.out.println("qqqqqqqqqqqqqqqq a "+_tok0);
294 _responseStatus = HttpVersions.CACHE.get(_tok0)==null?-1:0; 294 // _tok0.update(_buffer.markIndex(), _buffer.getIndex() - 1);
295 _tok0 = _buffer.peek(_buffer.markIndex(), _buffer.getIndex() - 1 - _buffer.markIndex()).toString();
296 //System.out.println("qqqqqqqqqqqqqqqq b "+_tok0);
297 _responseStatus = !HttpVersions.CACHE.contains(_tok0)?-1:0;
295 _state=STATE_SPACE1; 298 _state=STATE_SPACE1;
296 continue; 299 continue;
297 } 300 }
298 else if (ch < HttpTokens.SPACE && ch>=0) 301 else if (ch < HttpTokens.SPACE && ch>=0)
299 { 302 {
333 } 336 }
334 else if (ch < HttpTokens.SPACE && ch>=0) 337 else if (ch < HttpTokens.SPACE && ch>=0)
335 { 338 {
336 _eol=ch; 339 _eol=ch;
337 _state=STATE_HEADER; 340 _state=STATE_HEADER;
338 _tok0.setPutIndex(_tok0.getIndex()); 341 // _tok0.setPutIndex(_tok0.getIndex());
342 _tok0 = "";
339 _tok1.setPutIndex(_tok1.getIndex()); 343 _tok1.setPutIndex(_tok1.getIndex());
340 _multiLineValue=null; 344 _multiLineValue=null;
341 continue; 345 continue;
342 } 346 }
343 // not a digit, so must be a URI 347 // not a digit, so must be a URI
353 continue; 357 continue;
354 } 358 }
355 else if (ch < HttpTokens.SPACE && ch>=0) 359 else if (ch < HttpTokens.SPACE && ch>=0)
356 { 360 {
357 // HTTP/0.9 361 // HTTP/0.9
358 _handler.startRequest(HttpMethods.CACHE.lookup(_tok0), _buffer.sliceFromMark(), null); 362 _handler.startRequest(_tok0, _buffer.sliceFromMark(), null);
359 _persistent=false; 363 _persistent=false;
360 _state=STATE_SEEKING_EOF; 364 _state=STATE_SEEKING_EOF;
361 _handler.headerComplete(); 365 _handler.headerComplete();
362 _handler.messageComplete(_contentPosition); 366 _handler.messageComplete(_contentPosition);
363 return 1; 367 return 1;
374 { 378 {
375 if (_responseStatus>0) 379 if (_responseStatus>0)
376 { 380 {
377 _eol=ch; 381 _eol=ch;
378 _state=STATE_HEADER; 382 _state=STATE_HEADER;
379 _tok0.setPutIndex(_tok0.getIndex()); 383 // _tok0.setPutIndex(_tok0.getIndex());
384 _tok0 = "";
380 _tok1.setPutIndex(_tok1.getIndex()); 385 _tok1.setPutIndex(_tok1.getIndex());
381 _multiLineValue=null; 386 _multiLineValue=null;
382 } 387 }
383 else 388 else
384 { 389 {
385 // HTTP/0.9 390 // HTTP/0.9
386 _handler.startRequest(HttpMethods.CACHE.lookup(_tok0), _tok1, null); 391 _handler.startRequest(_tok0, _tok1, null);
387 _persistent=false; 392 _persistent=false;
388 _state=STATE_SEEKING_EOF; 393 _state=STATE_SEEKING_EOF;
389 _handler.headerComplete(); 394 _handler.headerComplete();
390 _handler.messageComplete(_contentPosition); 395 _handler.messageComplete(_contentPosition);
391 return 1; 396 return 1;
394 break; 399 break;
395 400
396 case STATE_FIELD2: 401 case STATE_FIELD2:
397 if (ch == HttpTokens.CARRIAGE_RETURN || ch == HttpTokens.LINE_FEED) 402 if (ch == HttpTokens.CARRIAGE_RETURN || ch == HttpTokens.LINE_FEED)
398 { 403 {
399 Buffer version; 404 String version;
400 if (_responseStatus>0) 405 if (_responseStatus > 0)
401 // _handler.startResponse(version=HttpVersions.CACHE.lookup(_tok0), _responseStatus,_buffer.sliceFromMark()); 406 // _handler.startResponse(version=HttpVersions.CACHE.lookup(_tok0), _responseStatus,_buffer.sliceFromMark());
402 version = HttpVersions.CACHE.lookup(_tok0); 407 version = _tok0;
403 else 408 else
404 _handler.startRequest(HttpMethods.CACHE.lookup(_tok0), _tok1, version=HttpVersions.CACHE.lookup(_buffer.sliceFromMark())); 409 _handler.startRequest(_tok0, _tok1, version=_buffer.sliceFromMark().toString());
405 _eol=ch; 410 _eol=ch;
406 _persistent=HttpVersions.CACHE.getOrdinal(version)>=HttpVersions.HTTP_1_1_ORDINAL; 411 _persistent = HttpVersions.CACHE.getOrdinal(version) >= HttpVersions.HTTP_1_1_ORDINAL;
407 _state=STATE_HEADER; 412 _state=STATE_HEADER;
408 _tok0.setPutIndex(_tok0.getIndex()); 413 // _tok0.setPutIndex(_tok0.getIndex());
414 _tok0 = "";
409 _tok1.setPutIndex(_tok1.getIndex()); 415 _tok1.setPutIndex(_tok1.getIndex());
410 _multiLineValue=null; 416 _multiLineValue=null;
411 continue; 417 continue;
412 } 418 }
413 break; 419 break;
505 } 511 }
506 } 512 }
507 } 513 }
508 514
509 _handler.parsedHeader(header, value); 515 _handler.parsedHeader(header, value);
510 _tok0.setPutIndex(_tok0.getIndex()); 516 // _tok0.setPutIndex(_tok0.getIndex());
517 _tok0 = "";
511 _tok1.setPutIndex(_tok1.getIndex()); 518 _tok1.setPutIndex(_tok1.getIndex());
512 _multiLineValue=null; 519 _multiLineValue=null;
513 } 520 }
514 _buffer.setMarkIndex(-1); 521 _buffer.setMarkIndex(-1);
515 522
594 case STATE_HEADER_NAME: 601 case STATE_HEADER_NAME:
595 switch(ch) 602 switch(ch)
596 { 603 {
597 case HttpTokens.CARRIAGE_RETURN: 604 case HttpTokens.CARRIAGE_RETURN:
598 case HttpTokens.LINE_FEED: 605 case HttpTokens.LINE_FEED:
599 if (_length > 0) 606 if (_length > 0) {
600 _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length); 607 //System.out.println("qqqqqqqqqqqqqqqq c "+_tok0);
608 // _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
609 _tok0 = _buffer.peek(_buffer.markIndex(), _length).toString();
610 //System.out.println("qqqqqqqqqqqqqqqq d "+_tok0);
611 }
601 _eol=ch; 612 _eol=ch;
602 _state=STATE_HEADER; 613 _state=STATE_HEADER;
603 break; 614 break;
604 case HttpTokens.COLON: 615 case HttpTokens.COLON:
605 if (_length > 0 && _cached==null) 616 if (_length > 0 && _cached==null) {
606 _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length); 617 //System.out.println("qqqqqqqqqqqqqqqq e "+_tok0);
618 // _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
619 _tok0 = _buffer.peek(_buffer.markIndex(), _length).toString();
620 //System.out.println("qqqqqqqqqqqqqqqq f "+_tok0);
621 }
607 _length=-1; 622 _length=-1;
608 _state=STATE_HEADER_VALUE; 623 _state=STATE_HEADER_VALUE;
609 break; 624 break;
610 case HttpTokens.SPACE: 625 case HttpTokens.SPACE:
611 case HttpTokens.TAB: 626 case HttpTokens.TAB:
625 case STATE_HEADER_IN_NAME: 640 case STATE_HEADER_IN_NAME:
626 switch(ch) 641 switch(ch)
627 { 642 {
628 case HttpTokens.CARRIAGE_RETURN: 643 case HttpTokens.CARRIAGE_RETURN:
629 case HttpTokens.LINE_FEED: 644 case HttpTokens.LINE_FEED:
630 if (_length > 0) 645 if (_length > 0) {
631 _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length); 646 //System.out.println("qqqqqqqqqqqqqqqq g "+_tok0);
647 // _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
648 _tok0 = _buffer.peek(_buffer.markIndex(),_length).toString();
649 //System.out.println("qqqqqqqqqqqqqqqq h "+_tok0);
650 }
632 _eol=ch; 651 _eol=ch;
633 _state=STATE_HEADER; 652 _state=STATE_HEADER;
634 break; 653 break;
635 case HttpTokens.COLON: 654 case HttpTokens.COLON:
636 if (_length > 0 && _cached==null) 655 if (_length > 0 && _cached==null) {
637 _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length); 656 //System.out.println("qqqqqqqqqqqqqqqq i "+_tok0);
657 // _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
658 _tok0 = _buffer.peek(_buffer.markIndex(),_length).toString();
659 //System.out.println("qqqqqqqqqqqqqqqq j "+_tok0);
660 }
638 _length=-1; 661 _length=-1;
639 _state=STATE_HEADER_VALUE; 662 _state=STATE_HEADER_VALUE;
640 break; 663 break;
641 case HttpTokens.SPACE: 664 case HttpTokens.SPACE:
642 case HttpTokens.TAB: 665 case HttpTokens.TAB:
1039 public Buffer getHeaderBuffer() 1062 public Buffer getHeaderBuffer()
1040 { 1063 {
1041 if (_header == null) 1064 if (_header == null)
1042 { 1065 {
1043 _header = _buffers.getHeader(); 1066 _header = _buffers.getHeader();
1044 _tok0.update(_header); 1067 //System.out.println("qqqqqqqqqqqqqqqq k "+_tok0);
1068 // _tok0.update(_header);
1069 _tok0 = "";
1070 //System.out.println("qqqqqqqqqqqqqqqq l "+_tok0);
1045 _tok1.update(_header); 1071 _tok1.update(_header);
1046 } 1072 }
1047 return _header; 1073 return _header;
1048 } 1074 }
1049 1075
1120 public void parsedHeader(Buffer name, Buffer value) throws IOException; 1146 public void parsedHeader(Buffer name, Buffer value) throws IOException;
1121 1147
1122 /** 1148 /**
1123 * This is the method called by parser when the HTTP request line is parsed 1149 * This is the method called by parser when the HTTP request line is parsed
1124 */ 1150 */
1125 public abstract void startRequest(Buffer method, Buffer url, Buffer version) 1151 public abstract void startRequest(String method, Buffer url, String version)
1126 throws IOException; 1152 throws IOException;
1127 1153
1128 public void earlyEOF(); 1154 public void earlyEOF();
1129 } 1155 }
1130 1156