Mercurial Hosting > luan
comparison src/org/eclipse/jetty/server/Request.java @ 972:5ee36654b383
simplify AbstractHttpConnection
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 15 Oct 2016 22:42:05 -0600 |
parents | 8db5996c8c89 |
children | d35b0a3a7a4a |
comparison
equal
deleted
inserted
replaced
971:f997df37cec1 | 972:5ee36654b383 |
---|---|
131 private static final String __ASYNC_FWD = "org.eclipse.asyncfwd"; | 131 private static final String __ASYNC_FWD = "org.eclipse.asyncfwd"; |
132 private static final Collection __defaultLocale = Collections.singleton(Locale.getDefault()); | 132 private static final Collection __defaultLocale = Collections.singleton(Locale.getDefault()); |
133 private static final int __NONE = 0, _STREAM = 1, __READER = 2; | 133 private static final int __NONE = 0, _STREAM = 1, __READER = 2; |
134 | 134 |
135 | 135 |
136 /* ------------------------------------------------------------ */ | |
137 public static Request getRequest(HttpServletRequest request) | 136 public static Request getRequest(HttpServletRequest request) |
138 { | 137 { |
139 if (request instanceof Request) | 138 if (request instanceof Request) |
140 return (Request)request; | 139 return (Request)request; |
141 | 140 |
433 /* | 432 /* |
434 * @see javax.servlet.ServletRequest#getContentLength() | 433 * @see javax.servlet.ServletRequest#getContentLength() |
435 */ | 434 */ |
436 public int getContentLength() | 435 public int getContentLength() |
437 { | 436 { |
438 return (int)_connection.getRequestFields().getLongField(HttpHeaders.CONTENT_LENGTH_BUFFER); | 437 return (int)_connection._requestFields.getLongField(HttpHeaders.CONTENT_LENGTH_BUFFER); |
439 } | 438 } |
440 | 439 |
441 public long getContentRead() | 440 public long getContentRead() |
442 { | 441 { |
443 if (_connection == null || _connection.getParser() == null) | 442 if (_connection == null) |
444 return -1; | 443 return -1; |
445 | 444 |
446 return ((HttpParser)_connection.getParser()).getContentRead(); | 445 return _connection._parser.getContentRead(); |
447 } | 446 } |
448 | 447 |
449 /* ------------------------------------------------------------ */ | 448 /* ------------------------------------------------------------ */ |
450 /* | 449 /* |
451 * @see javax.servlet.ServletRequest#getContentType() | 450 * @see javax.servlet.ServletRequest#getContentType() |
452 */ | 451 */ |
453 public String getContentType() | 452 public String getContentType() |
454 { | 453 { |
455 return _connection.getRequestFields().getStringField(HttpHeaders.CONTENT_TYPE_BUFFER); | 454 return _connection._requestFields.getStringField(HttpHeaders.CONTENT_TYPE_BUFFER); |
456 } | 455 } |
457 | 456 |
458 /* ------------------------------------------------------------ */ | 457 /* ------------------------------------------------------------ */ |
459 /** | 458 /** |
460 * @return The current {@link Context context} used for this request, or <code>null</code> if {@link #setContext} has not yet been called. | 459 * @return The current {@link Context context} used for this request, or <code>null</code> if {@link #setContext} has not yet been called. |
482 if (_cookiesExtracted) | 481 if (_cookiesExtracted) |
483 return _cookies == null?null:_cookies.getCookies(); | 482 return _cookies == null?null:_cookies.getCookies(); |
484 | 483 |
485 _cookiesExtracted = true; | 484 _cookiesExtracted = true; |
486 | 485 |
487 Enumeration enm = _connection.getRequestFields().getValues(HttpHeaders.COOKIE_BUFFER); | 486 Enumeration enm = _connection._requestFields.getValues(HttpHeaders.COOKIE_BUFFER); |
488 | 487 |
489 // Handle no cookies | 488 // Handle no cookies |
490 if (enm != null) | 489 if (enm != null) |
491 { | 490 { |
492 if (_cookies == null) | 491 if (_cookies == null) |
506 /* | 505 /* |
507 * @see javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String) | 506 * @see javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String) |
508 */ | 507 */ |
509 public long getDateHeader(String name) | 508 public long getDateHeader(String name) |
510 { | 509 { |
511 return _connection.getRequestFields().getDateField(name); | 510 return _connection._requestFields.getDateField(name); |
512 } | 511 } |
513 | 512 |
514 /* ------------------------------------------------------------ */ | 513 /* ------------------------------------------------------------ */ |
515 public DispatcherType getDispatcherType() | 514 public DispatcherType getDispatcherType() |
516 { | 515 { |
521 /* | 520 /* |
522 * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String) | 521 * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String) |
523 */ | 522 */ |
524 public String getHeader(String name) | 523 public String getHeader(String name) |
525 { | 524 { |
526 return _connection.getRequestFields().getStringField(name); | 525 return _connection._requestFields.getStringField(name); |
527 } | 526 } |
528 | 527 |
529 /* ------------------------------------------------------------ */ | 528 /* ------------------------------------------------------------ */ |
530 /* | 529 /* |
531 * @see javax.servlet.http.HttpServletRequest#getHeaderNames() | 530 * @see javax.servlet.http.HttpServletRequest#getHeaderNames() |
532 */ | 531 */ |
533 public Enumeration getHeaderNames() | 532 public Enumeration getHeaderNames() |
534 { | 533 { |
535 return _connection.getRequestFields().getFieldNames(); | 534 return _connection._requestFields.getFieldNames(); |
536 } | 535 } |
537 | 536 |
538 /* ------------------------------------------------------------ */ | 537 /* ------------------------------------------------------------ */ |
539 /* | 538 /* |
540 * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String) | 539 * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String) |
541 */ | 540 */ |
542 public Enumeration getHeaders(String name) | 541 public Enumeration getHeaders(String name) |
543 { | 542 { |
544 Enumeration e = _connection.getRequestFields().getValues(name); | 543 Enumeration e = _connection._requestFields.getValues(name); |
545 if (e == null) | 544 if (e == null) |
546 return Collections.enumeration(Collections.EMPTY_LIST); | 545 return Collections.enumeration(Collections.EMPTY_LIST); |
547 return e; | 546 return e; |
548 } | 547 } |
549 | 548 |
572 /* | 571 /* |
573 * @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String) | 572 * @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String) |
574 */ | 573 */ |
575 public int getIntHeader(String name) | 574 public int getIntHeader(String name) |
576 { | 575 { |
577 return (int)_connection.getRequestFields().getLongField(name); | 576 return (int)_connection._requestFields.getLongField(name); |
578 } | 577 } |
579 | 578 |
580 /* ------------------------------------------------------------ */ | 579 /* ------------------------------------------------------------ */ |
581 /* | 580 /* |
582 * @see javax.servlet.ServletRequest#getLocalAddr() | 581 * @see javax.servlet.ServletRequest#getLocalAddr() |
590 /* | 589 /* |
591 * @see javax.servlet.ServletRequest#getLocale() | 590 * @see javax.servlet.ServletRequest#getLocale() |
592 */ | 591 */ |
593 public Locale getLocale() | 592 public Locale getLocale() |
594 { | 593 { |
595 Enumeration enm = _connection.getRequestFields().getValues( "Accept-Language", ", \t" ); | 594 Enumeration enm = _connection._requestFields.getValues( "Accept-Language", ", \t" ); |
596 | 595 |
597 // handle no locale | 596 // handle no locale |
598 if (enm == null || !enm.hasMoreElements()) | 597 if (enm == null || !enm.hasMoreElements()) |
599 return Locale.getDefault(); | 598 return Locale.getDefault(); |
600 | 599 |
627 * @see javax.servlet.ServletRequest#getLocales() | 626 * @see javax.servlet.ServletRequest#getLocales() |
628 */ | 627 */ |
629 public Enumeration getLocales() | 628 public Enumeration getLocales() |
630 { | 629 { |
631 | 630 |
632 Enumeration enm = _connection.getRequestFields().getValues( "Accept-Language", ", \t" ); | 631 Enumeration enm = _connection._requestFields.getValues( "Accept-Language", ", \t" ); |
633 | 632 |
634 // handle no locale | 633 // handle no locale |
635 if (enm == null || !enm.hasMoreElements()) | 634 if (enm == null || !enm.hasMoreElements()) |
636 return Collections.enumeration(__defaultLocale); | 635 return Collections.enumeration(__defaultLocale); |
637 | 636 |
1009 _port = _uri.getPort(); | 1008 _port = _uri.getPort(); |
1010 if (_serverName != null) | 1009 if (_serverName != null) |
1011 return _serverName; | 1010 return _serverName; |
1012 | 1011 |
1013 // Return host from header field | 1012 // Return host from header field |
1014 Buffer hostPort = _connection.getRequestFields().get(HttpHeaders.HOST_BUFFER); | 1013 Buffer hostPort = _connection._requestFields.get(HttpHeaders.HOST_BUFFER); |
1015 if (hostPort != null) | 1014 if (hostPort != null) |
1016 { | 1015 { |
1017 loop: for (int i = hostPort.putIndex(); i-- > hostPort.getIndex();) | 1016 loop: for (int i = hostPort.putIndex(); i-- > hostPort.getIndex();) |
1018 { | 1017 { |
1019 char ch = (char)(0xff & hostPort.peek(i)); | 1018 char ch = (char)(0xff & hostPort.peek(i)); |
1253 /* | 1252 /* |
1254 * @see javax.servlet.ServletRequest#isSecure() | 1253 * @see javax.servlet.ServletRequest#isSecure() |
1255 */ | 1254 */ |
1256 public boolean isSecure() | 1255 public boolean isSecure() |
1257 { | 1256 { |
1258 return _connection.isConfidential(this); | 1257 return _connection.getConnector().isConfidential(); |
1259 } | 1258 } |
1260 | 1259 |
1261 /* ------------------------------------------------------------ */ | 1260 /* ------------------------------------------------------------ */ |
1262 /* | 1261 /* |
1263 * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String) | 1262 * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String) |
1488 /* | 1487 /* |
1489 * @see javax.servlet.ServletRequest#getContentType() | 1488 * @see javax.servlet.ServletRequest#getContentType() |
1490 */ | 1489 */ |
1491 public void setContentType(String contentType) | 1490 public void setContentType(String contentType) |
1492 { | 1491 { |
1493 _connection.getRequestFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,contentType); | 1492 _connection._requestFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,contentType); |
1494 | 1493 |
1495 } | 1494 } |
1496 | 1495 |
1497 /* ------------------------------------------------------------ */ | 1496 /* ------------------------------------------------------------ */ |
1498 /** | 1497 /** |