Mercurial Hosting > luan
comparison src/org/eclipse/jetty/server/AbstractHttpConnection.java @ 972:5ee36654b383
simplify AbstractHttpConnection
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sat, 15 Oct 2016 22:42:05 -0600 |
| parents | 866f2e801618 |
| children | 7422ca1ae146 |
comparison
equal
deleted
inserted
replaced
| 971:f997df37cec1 | 972:5ee36654b383 |
|---|---|
| 46 import org.eclipse.jetty.http.Parser; | 46 import org.eclipse.jetty.http.Parser; |
| 47 import org.eclipse.jetty.io.AbstractConnection; | 47 import org.eclipse.jetty.io.AbstractConnection; |
| 48 import org.eclipse.jetty.io.Buffer; | 48 import org.eclipse.jetty.io.Buffer; |
| 49 import org.eclipse.jetty.io.BufferCache.CachedBuffer; | 49 import org.eclipse.jetty.io.BufferCache.CachedBuffer; |
| 50 import org.eclipse.jetty.io.Buffers; | 50 import org.eclipse.jetty.io.Buffers; |
| 51 import org.eclipse.jetty.io.Connection; | |
| 52 import org.eclipse.jetty.io.EndPoint; | 51 import org.eclipse.jetty.io.EndPoint; |
| 53 import org.eclipse.jetty.io.EofException; | 52 import org.eclipse.jetty.io.EofException; |
| 54 import org.eclipse.jetty.io.RuntimeIOException; | 53 import org.eclipse.jetty.io.RuntimeIOException; |
| 55 import org.eclipse.jetty.util.QuotedStringTokenizer; | 54 import org.eclipse.jetty.util.QuotedStringTokenizer; |
| 56 import org.eclipse.jetty.util.StringUtil; | 55 import org.eclipse.jetty.util.StringUtil; |
| 92 */ | 91 */ |
| 93 public abstract class AbstractHttpConnection extends AbstractConnection | 92 public abstract class AbstractHttpConnection extends AbstractConnection |
| 94 { | 93 { |
| 95 private static final Logger LOG = LoggerFactory.getLogger(AbstractHttpConnection.class); | 94 private static final Logger LOG = LoggerFactory.getLogger(AbstractHttpConnection.class); |
| 96 | 95 |
| 97 private static final int UNKNOWN = -2; | |
| 98 private static final ThreadLocal<AbstractHttpConnection> __currentConnection = new ThreadLocal<AbstractHttpConnection>(); | 96 private static final ThreadLocal<AbstractHttpConnection> __currentConnection = new ThreadLocal<AbstractHttpConnection>(); |
| 99 | 97 |
| 100 private int _requests; | 98 private int _requests; |
| 101 | 99 |
| 102 protected final Connector _connector; | 100 private final Connector _connector; |
| 103 protected final Server _server; | 101 private final Server _server; |
| 104 protected final HttpURI _uri; | 102 protected final HttpURI _uri = StringUtil.__UTF8.equals(URIUtil.__CHARSET)?new HttpURI():new EncodedHttpURI(URIUtil.__CHARSET); |
| 105 | 103 |
| 106 protected final Parser _parser; | 104 protected final HttpParser _parser; |
| 107 protected final HttpFields _requestFields; | 105 protected final HttpFields _requestFields = new HttpFields(); |
| 108 protected final Request _request; | 106 private final Request _request; |
| 109 protected volatile ServletInputStream _in; | 107 private volatile ServletInputStream _in; |
| 110 | 108 |
| 111 protected final Generator _generator; | 109 protected final HttpGenerator _generator; |
| 112 protected final HttpFields _responseFields; | 110 final HttpFields _responseFields = new HttpFields(); |
| 113 protected final Response _response; | 111 protected final Response _response; |
| 114 protected volatile Output _out; | 112 private volatile Output _out; |
| 115 protected volatile OutputWriter _writer; | 113 private volatile HttpWriter _writer; |
| 116 protected volatile PrintWriter _printWriter; | 114 private volatile PrintWriter _printWriter; |
| 117 | 115 |
| 118 int _include; | 116 private int _version = -2; // UNKNOWN |
| 119 | |
| 120 private Object _associatedObject; // associated object | |
| 121 | |
| 122 private int _version = UNKNOWN; | |
| 123 | 117 |
| 124 private String _charset; | 118 private String _charset; |
| 125 private boolean _expect = false; | 119 private boolean _expect = false; |
| 126 private boolean _expect100Continue = false; | 120 private boolean _expect100Continue = false; |
| 127 private boolean _expect102Processing = false; | 121 private boolean _expect102Processing = false; |
| 128 private boolean _head = false; | 122 private boolean _head = false; |
| 129 private boolean _host = false; | 123 private boolean _host = false; |
| 130 private boolean _delayedHandling=false; | 124 private boolean _delayedHandling = false; |
| 131 private boolean _earlyEOF = false; | 125 private boolean _earlyEOF = false; |
| 132 | 126 |
| 133 /* ------------------------------------------------------------ */ | |
| 134 public static AbstractHttpConnection getCurrentConnection() | 127 public static AbstractHttpConnection getCurrentConnection() |
| 135 { | 128 { |
| 136 return __currentConnection.get(); | 129 return __currentConnection.get(); |
| 137 } | 130 } |
| 138 | 131 |
| 139 /* ------------------------------------------------------------ */ | |
| 140 protected static void setCurrentConnection(AbstractHttpConnection connection) | 132 protected static void setCurrentConnection(AbstractHttpConnection connection) |
| 141 { | 133 { |
| 142 __currentConnection.set(connection); | 134 __currentConnection.set(connection); |
| 143 } | 135 } |
| 144 | 136 |
| 145 /* ------------------------------------------------------------ */ | 137 protected AbstractHttpConnection(Connector connector, EndPoint endpoint) |
| 146 public AbstractHttpConnection(Connector connector, EndPoint endpoint, Server server) | |
| 147 { | 138 { |
| 148 super(endpoint); | 139 super(endpoint); |
| 149 _uri = StringUtil.__UTF8.equals(URIUtil.__CHARSET)?new HttpURI():new EncodedHttpURI(URIUtil.__CHARSET); | |
| 150 _connector = connector; | 140 _connector = connector; |
| 151 HttpBuffers ab = (HttpBuffers)_connector; | 141 HttpBuffers ab = _connector; |
| 152 _parser = newHttpParser(ab.getRequestBuffers(), endpoint, new RequestHandler()); | 142 _parser = new HttpParser(ab.getRequestBuffers(), endpoint, new RequestHandler()); |
| 153 _requestFields = new HttpFields(); | |
| 154 _responseFields = new HttpFields(); | |
| 155 _request = new Request(this); | 143 _request = new Request(this); |
| 156 _response = new Response(this); | 144 _response = new Response(this); |
| 157 _generator = newHttpGenerator(ab.getResponseBuffers(), endpoint); | 145 _generator = new HttpGenerator(ab.getResponseBuffers(), endpoint); |
| 158 _server = server; | 146 _server = connector.server; |
| 159 } | 147 } |
| 160 | 148 |
| 161 /* ------------------------------------------------------------ */ | 149 public final Connector getConnector() |
| 162 protected AbstractHttpConnection(Connector connector, EndPoint endpoint, Server server, | |
| 163 Parser parser, Generator generator, Request request) | |
| 164 { | |
| 165 super(endpoint); | |
| 166 | |
| 167 _uri = URIUtil.__CHARSET.equals(StringUtil.__UTF8)?new HttpURI():new EncodedHttpURI(URIUtil.__CHARSET); | |
| 168 _connector = connector; | |
| 169 _parser = parser; | |
| 170 _requestFields = new HttpFields(); | |
| 171 _responseFields = new HttpFields(); | |
| 172 _request = request; | |
| 173 _response = new Response(this); | |
| 174 _generator = generator; | |
| 175 _server = server; | |
| 176 } | |
| 177 | |
| 178 protected HttpParser newHttpParser(Buffers requestBuffers, EndPoint endpoint, HttpParser.EventHandler requestHandler) | |
| 179 { | |
| 180 return new HttpParser(requestBuffers, endpoint, requestHandler); | |
| 181 } | |
| 182 | |
| 183 protected HttpGenerator newHttpGenerator(Buffers responseBuffers, EndPoint endPoint) | |
| 184 { | |
| 185 return new HttpGenerator(responseBuffers, endPoint); | |
| 186 } | |
| 187 | |
| 188 /* ------------------------------------------------------------ */ | |
| 189 /** | |
| 190 * @return the parser used by this connection | |
| 191 */ | |
| 192 public Parser getParser() | |
| 193 { | |
| 194 return _parser; | |
| 195 } | |
| 196 | |
| 197 /* ------------------------------------------------------------ */ | |
| 198 /** | |
| 199 * @return the number of requests handled by this connection | |
| 200 */ | |
| 201 public int getRequests() | |
| 202 { | |
| 203 return _requests; | |
| 204 } | |
| 205 | |
| 206 /* ------------------------------------------------------------ */ | |
| 207 public Server getServer() | |
| 208 { | |
| 209 return _server; | |
| 210 } | |
| 211 | |
| 212 /* ------------------------------------------------------------ */ | |
| 213 /** | |
| 214 * @return Returns the associatedObject. | |
| 215 */ | |
| 216 public Object getAssociatedObject() | |
| 217 { | |
| 218 return _associatedObject; | |
| 219 } | |
| 220 | |
| 221 /* ------------------------------------------------------------ */ | |
| 222 /** | |
| 223 * @param associatedObject The associatedObject to set. | |
| 224 */ | |
| 225 public void setAssociatedObject(Object associatedObject) | |
| 226 { | |
| 227 _associatedObject = associatedObject; | |
| 228 } | |
| 229 | |
| 230 /* ------------------------------------------------------------ */ | |
| 231 /** | |
| 232 * @return Returns the connector. | |
| 233 */ | |
| 234 public Connector getConnector() | |
| 235 { | 150 { |
| 236 return _connector; | 151 return _connector; |
| 237 } | 152 } |
| 238 | 153 |
| 239 /* ------------------------------------------------------------ */ | 154 public final Request getRequest() |
| 240 /** | |
| 241 * @return Returns the requestFields. | |
| 242 */ | |
| 243 public HttpFields getRequestFields() | |
| 244 { | |
| 245 return _requestFields; | |
| 246 } | |
| 247 | |
| 248 /* ------------------------------------------------------------ */ | |
| 249 /** | |
| 250 * @return Returns the responseFields. | |
| 251 */ | |
| 252 public HttpFields getResponseFields() | |
| 253 { | |
| 254 return _responseFields; | |
| 255 } | |
| 256 | |
| 257 /* ------------------------------------------------------------ */ | |
| 258 /** | |
| 259 * Find out if the request supports CONFIDENTIAL security. | |
| 260 * @param request the incoming HTTP request | |
| 261 * @return the result of calling {@link Connector#isConfidential(Request)}, or false | |
| 262 * if there is no connector | |
| 263 */ | |
| 264 public boolean isConfidential(Request request) | |
| 265 { | |
| 266 return _connector != null && _connector.isConfidential(request); | |
| 267 } | |
| 268 | |
| 269 /* ------------------------------------------------------------ */ | |
| 270 /** | |
| 271 * @return Returns the request. | |
| 272 */ | |
| 273 public Request getRequest() | |
| 274 { | 155 { |
| 275 return _request; | 156 return _request; |
| 276 } | 157 } |
| 277 | 158 |
| 278 /* ------------------------------------------------------------ */ | 159 public final Response getResponse() |
| 279 /** | |
| 280 * @return Returns the response. | |
| 281 */ | |
| 282 public Response getResponse() | |
| 283 { | 160 { |
| 284 return _response; | 161 return _response; |
| 285 } | 162 } |
| 286 | 163 |
| 287 /* ------------------------------------------------------------ */ | 164 /* ------------------------------------------------------------ */ |
| 294 * | 171 * |
| 295 * @return The input stream for this connection. | 172 * @return The input stream for this connection. |
| 296 * The stream will be created if it does not already exist. | 173 * The stream will be created if it does not already exist. |
| 297 * @throws IOException if the input stream cannot be retrieved | 174 * @throws IOException if the input stream cannot be retrieved |
| 298 */ | 175 */ |
| 299 public ServletInputStream getInputStream() throws IOException | 176 public final ServletInputStream getInputStream() throws IOException |
| 300 { | 177 { |
| 301 // If the client is expecting 100 CONTINUE, then send it now. | 178 // If the client is expecting 100 CONTINUE, then send it now. |
| 302 if (_expect100Continue) | 179 if (_expect100Continue) |
| 303 { | 180 { |
| 304 // is content missing? | 181 // is content missing? |
| 305 if (((HttpParser)_parser).getHeaderBuffer()==null || ((HttpParser)_parser).getHeaderBuffer().length()<2) | 182 if (_parser.getHeaderBuffer()==null || _parser.getHeaderBuffer().length()<2) |
| 306 { | 183 { |
| 307 if (_generator.isCommitted()) | 184 if (_generator.isCommitted()) |
| 308 throw new IllegalStateException("Committed before 100 Continues"); | 185 throw new IllegalStateException("Committed before 100 Continues"); |
| 309 | 186 |
| 310 ((HttpGenerator)_generator).send1xx(HttpStatus.CONTINUE_100); | 187 _generator.send1xx(HttpStatus.CONTINUE_100); |
| 311 } | 188 } |
| 312 _expect100Continue=false; | 189 _expect100Continue=false; |
| 313 } | 190 } |
| 314 | 191 |
| 315 if (_in == null) | 192 if (_in == null) |
| 319 | 196 |
| 320 /* ------------------------------------------------------------ */ | 197 /* ------------------------------------------------------------ */ |
| 321 /** | 198 /** |
| 322 * @return The output stream for this connection. The stream will be created if it does not already exist. | 199 * @return The output stream for this connection. The stream will be created if it does not already exist. |
| 323 */ | 200 */ |
| 324 public ServletOutputStream getOutputStream() | 201 public final ServletOutputStream getOutputStream() |
| 325 { | 202 { |
| 326 if (_out == null) | 203 if (_out == null) |
| 327 _out = new Output(); | 204 _out = new Output(); |
| 328 return _out; | 205 return _out; |
| 329 } | 206 } |
| 332 /** | 209 /** |
| 333 * @param encoding the PrintWriter encoding | 210 * @param encoding the PrintWriter encoding |
| 334 * @return A {@link PrintWriter} wrapping the {@link #getOutputStream output stream}. The writer is created if it | 211 * @return A {@link PrintWriter} wrapping the {@link #getOutputStream output stream}. The writer is created if it |
| 335 * does not already exist. | 212 * does not already exist. |
| 336 */ | 213 */ |
| 337 public PrintWriter getPrintWriter(String encoding) | 214 public final PrintWriter getPrintWriter(String encoding) |
| 338 { | 215 { |
| 339 getOutputStream(); | 216 getOutputStream(); |
| 340 if (_writer==null) | 217 if (_writer==null) |
| 341 { | 218 { |
| 342 _writer=new OutputWriter(); | 219 _writer = new HttpWriter(_out); |
| 343 _printWriter = new PrintWriter(_writer) | 220 _printWriter = new PrintWriter(_writer) |
| 344 { | 221 { |
| 345 public void close() | 222 public void close() |
| 346 { | 223 { |
| 347 synchronized (lock) | 224 synchronized (lock) |
| 360 } | 237 } |
| 361 _writer.setCharacterEncoding(encoding); | 238 _writer.setCharacterEncoding(encoding); |
| 362 return _printWriter; | 239 return _printWriter; |
| 363 } | 240 } |
| 364 | 241 |
| 365 /* ------------------------------------------------------------ */ | 242 public final boolean isEarlyEOF() |
| 366 public boolean isResponseCommitted() | |
| 367 { | |
| 368 return _generator.isCommitted(); | |
| 369 } | |
| 370 | |
| 371 /* ------------------------------------------------------------ */ | |
| 372 public boolean isEarlyEOF() | |
| 373 { | 243 { |
| 374 return _earlyEOF; | 244 return _earlyEOF; |
| 375 } | 245 } |
| 376 | 246 |
| 377 /* ------------------------------------------------------------ */ | 247 protected void reset() |
| 378 public void reset() | |
| 379 { | 248 { |
| 380 _parser.reset(); | 249 _parser.reset(); |
| 381 _parser.returnBuffers(); // TODO maybe only on unhandle | 250 _parser.returnBuffers(); // TODO maybe only on unhandle |
| 382 _requestFields.clear(); | 251 _requestFields.clear(); |
| 383 _request.recycle(); | 252 _request.recycle(); |
| 384 _generator.reset(); | 253 _generator.reset(); |
| 385 _generator.returnBuffers();// TODO maybe only on unhandle | 254 _generator.returnBuffers();// TODO maybe only on unhandle |
| 386 _responseFields.clear(); | 255 _responseFields.clear(); |
| 387 _response.recycle(); | 256 _response.recycle(); |
| 388 _uri.clear(); | 257 _uri.clear(); |
| 389 _writer=null; | 258 _writer = null; |
| 390 _earlyEOF = false; | 259 _earlyEOF = false; |
| 391 } | 260 } |
| 392 | 261 |
| 393 protected void handleRequest() throws IOException | 262 private void handleRequest() throws IOException |
| 394 { | 263 { |
| 395 boolean error = false; | 264 boolean error = false; |
| 396 | 265 |
| 397 try | 266 try |
| 398 { | 267 { |
| 511 _request.setHandled(true); | 380 _request.setHandled(true); |
| 512 } | 381 } |
| 513 } | 382 } |
| 514 | 383 |
| 515 | 384 |
| 516 public void commitResponse(boolean last) throws IOException | 385 public final void commitResponse(boolean last) throws IOException |
| 517 { | 386 { |
| 518 if (!_generator.isCommitted()) | 387 if (!_generator.isCommitted()) |
| 519 { | 388 { |
| 520 _generator.setResponse(_response.getStatus(), _response.getReason()); | 389 _generator.setResponse(_response.getStatus(), _response.getReason()); |
| 521 try | 390 try |
| 541 } | 410 } |
| 542 if (last) | 411 if (last) |
| 543 _generator.complete(); | 412 _generator.complete(); |
| 544 } | 413 } |
| 545 | 414 |
| 546 /* ------------------------------------------------------------ */ | 415 public final void completeResponse() throws IOException |
| 547 public void completeResponse() throws IOException | |
| 548 { | 416 { |
| 549 if (!_generator.isCommitted()) | 417 if (!_generator.isCommitted()) |
| 550 { | 418 { |
| 551 _generator.setResponse(_response.getStatus(), _response.getReason()); | 419 _generator.setResponse(_response.getStatus(), _response.getReason()); |
| 552 try | 420 try |
| 568 } | 436 } |
| 569 | 437 |
| 570 _generator.complete(); | 438 _generator.complete(); |
| 571 } | 439 } |
| 572 | 440 |
| 573 /* ------------------------------------------------------------ */ | 441 public final void flushResponse() throws IOException |
| 574 public void flushResponse() throws IOException | |
| 575 { | 442 { |
| 576 try | 443 try |
| 577 { | 444 { |
| 578 commitResponse(Generator.MORE); | 445 commitResponse(Generator.MORE); |
| 579 _generator.flushBuffer(); | 446 _generator.flushBuffer(); |
| 582 { | 449 { |
| 583 throw (e instanceof EofException) ? e:new EofException(e); | 450 throw (e instanceof EofException) ? e:new EofException(e); |
| 584 } | 451 } |
| 585 } | 452 } |
| 586 | 453 |
| 587 /* ------------------------------------------------------------ */ | 454 public final boolean isIdle() |
| 588 public Generator getGenerator() | |
| 589 { | |
| 590 return _generator; | |
| 591 } | |
| 592 | |
| 593 /* ------------------------------------------------------------ */ | |
| 594 public boolean isIncluding() | |
| 595 { | |
| 596 return _include>0; | |
| 597 } | |
| 598 | |
| 599 /* ------------------------------------------------------------ */ | |
| 600 public void include() | |
| 601 { | |
| 602 _include++; | |
| 603 } | |
| 604 | |
| 605 /* ------------------------------------------------------------ */ | |
| 606 public void included() | |
| 607 { | |
| 608 _include--; | |
| 609 if (_out!=null) | |
| 610 _out.reopen(); | |
| 611 } | |
| 612 | |
| 613 public boolean isIdle() | |
| 614 { | 455 { |
| 615 return _generator.isIdle() && (_parser.isIdle() || _delayedHandling); | 456 return _generator.isIdle() && (_parser.isIdle() || _delayedHandling); |
| 616 } | 457 } |
| 617 | 458 |
| 618 /* ------------------------------------------------------------ */ | 459 public final boolean isExpecting102Processing() |
| 619 /** | |
| 620 * @see org.eclipse.jetty.io.Connection#isSuspended() | |
| 621 */ | |
| 622 public boolean isSuspended() | |
| 623 { | |
| 624 return false; | |
| 625 } | |
| 626 | |
| 627 public boolean isExpecting100Continues() | |
| 628 { | |
| 629 return _expect100Continue; | |
| 630 } | |
| 631 | |
| 632 public boolean isExpecting102Processing() | |
| 633 { | 460 { |
| 634 return _expect102Processing; | 461 return _expect102Processing; |
| 635 } | 462 } |
| 636 | 463 |
| 637 public int getMaxIdleTime() | 464 public final int getMaxIdleTime() |
| 638 { | 465 { |
| 639 if (_connector.isLowResources() && _endp.getMaxIdleTime()==_connector.getMaxIdleTime()) | 466 if (_connector.isLowResources() && _endp.getMaxIdleTime()==_connector.getMaxIdleTime()) |
| 640 return 0; | 467 return 0; |
| 641 if (_endp.getMaxIdleTime()>0) | 468 if (_endp.getMaxIdleTime()>0) |
| 642 return _endp.getMaxIdleTime(); | 469 return _endp.getMaxIdleTime(); |
| 643 return _connector.getMaxIdleTime(); | 470 return _connector.getMaxIdleTime(); |
| 644 } | 471 } |
| 645 | 472 |
| 473 @Override | |
| 646 public String toString() | 474 public String toString() |
| 647 { | 475 { |
| 648 return String.format("%s,g=%s,p=%s,r=%d", | 476 return String.format("%s,g=%s,p=%s,r=%d", |
| 649 super.toString(), | 477 super.toString(), |
| 650 _generator, | 478 _generator, |
| 651 _parser, | 479 _parser, |
| 652 _requests); | 480 _requests); |
| 653 } | 481 } |
| 654 | 482 |
| 655 /* ------------------------------------------------------------ */ | 483 private void startRequest(Buffer method, Buffer uri, Buffer version) throws IOException |
| 656 protected void startRequest(Buffer method, Buffer uri, Buffer version) throws IOException | |
| 657 { | 484 { |
| 658 uri=uri.asImmutableBuffer(); | 485 uri=uri.asImmutableBuffer(); |
| 659 | 486 |
| 660 _host = false; | 487 _host = false; |
| 661 _expect = false; | 488 _expect = false; |
| 662 _expect100Continue=false; | 489 _expect100Continue = false; |
| 663 _expect102Processing=false; | 490 _expect102Processing=false; |
| 664 _delayedHandling=false; | 491 _delayedHandling=false; |
| 665 _charset=null; | 492 _charset=null; |
| 666 | 493 |
| 667 if(_request.getTimeStamp()==0) | 494 if(_request.getTimeStamp()==0) |
| 668 _request.setTimeStamp(System.currentTimeMillis()); | 495 _request.setTimeStamp(System.currentTimeMillis()); |
| 669 _request.setMethod(method.toString()); | 496 _request.setMethod(method.toString()); |
| 670 | 497 |
| 671 try | 498 try |
| 672 { | 499 { |
| 673 _head=false; | 500 _head = false; |
| 674 switch (HttpMethods.CACHE.getOrdinal(method)) | 501 switch (HttpMethods.CACHE.getOrdinal(method)) |
| 675 { | 502 { |
| 676 case HttpMethods.CONNECT_ORDINAL: | 503 case HttpMethods.CONNECT_ORDINAL: |
| 677 _uri.parseConnect(uri.array(), uri.getIndex(), uri.length()); | 504 _uri.parseConnect(uri.array(), uri.getIndex(), uri.length()); |
| 678 break; | 505 break; |
| 679 | 506 |
| 680 case HttpMethods.HEAD_ORDINAL: | 507 case HttpMethods.HEAD_ORDINAL: |
| 681 _head=true; | 508 _head = true; |
| 682 _uri.parse(uri.array(), uri.getIndex(), uri.length()); | 509 _uri.parse(uri.array(), uri.getIndex(), uri.length()); |
| 683 break; | 510 break; |
| 684 | 511 |
| 685 default: | 512 default: |
| 686 _uri.parse(uri.array(), uri.getIndex(), uri.length()); | 513 _uri.parse(uri.array(), uri.getIndex(), uri.length()); |
| 689 _request.setUri(_uri); | 516 _request.setUri(_uri); |
| 690 | 517 |
| 691 if (version==null) | 518 if (version==null) |
| 692 { | 519 { |
| 693 _request.setProtocol(HttpVersions.HTTP_0_9); | 520 _request.setProtocol(HttpVersions.HTTP_0_9); |
| 694 _version=HttpVersions.HTTP_0_9_ORDINAL; | 521 _version = HttpVersions.HTTP_0_9_ORDINAL; |
| 695 } | 522 } |
| 696 else | 523 else |
| 697 { | 524 { |
| 698 version= HttpVersions.CACHE.get(version); | 525 version = HttpVersions.CACHE.get(version); |
| 699 if (version==null) | 526 if (version==null) |
| 700 throw new HttpException(HttpStatus.BAD_REQUEST_400,null); | 527 throw new HttpException(HttpStatus.BAD_REQUEST_400,null); |
| 701 _version = HttpVersions.CACHE.getOrdinal(version); | 528 _version = HttpVersions.CACHE.getOrdinal(version); |
| 702 if (_version <= 0) _version = HttpVersions.HTTP_1_0_ORDINAL; | 529 if (_version <= 0) _version = HttpVersions.HTTP_1_0_ORDINAL; |
| 703 _request.setProtocol(version.toString()); | 530 _request.setProtocol(version.toString()); |
| 710 throw (HttpException)e; | 537 throw (HttpException)e; |
| 711 throw new HttpException(HttpStatus.BAD_REQUEST_400,null,e); | 538 throw new HttpException(HttpStatus.BAD_REQUEST_400,null,e); |
| 712 } | 539 } |
| 713 } | 540 } |
| 714 | 541 |
| 715 /* ------------------------------------------------------------ */ | 542 private void parsedHeader(Buffer name, Buffer value) throws IOException |
| 716 protected void parsedHeader(Buffer name, Buffer value) throws IOException | |
| 717 { | 543 { |
| 718 int ho = HttpHeaders.CACHE.getOrdinal(name); | 544 int ho = HttpHeaders.CACHE.getOrdinal(name); |
| 719 switch (ho) | 545 switch (ho) |
| 720 { | 546 { |
| 721 case HttpHeaders.HOST_ORDINAL: | 547 case HttpHeaders.HOST_ORDINAL: |
| 728 { | 554 { |
| 729 value = HttpHeaderValues.CACHE.lookup(value); | 555 value = HttpHeaderValues.CACHE.lookup(value); |
| 730 switch(HttpHeaderValues.CACHE.getOrdinal(value)) | 556 switch(HttpHeaderValues.CACHE.getOrdinal(value)) |
| 731 { | 557 { |
| 732 case HttpHeaderValues.CONTINUE_ORDINAL: | 558 case HttpHeaderValues.CONTINUE_ORDINAL: |
| 733 _expect100Continue=_generator instanceof HttpGenerator; | 559 _expect100Continue = true; |
| 734 break; | 560 break; |
| 735 | 561 |
| 736 case HttpHeaderValues.PROCESSING_ORDINAL: | 562 case HttpHeaderValues.PROCESSING_ORDINAL: |
| 737 _expect102Processing=_generator instanceof HttpGenerator; | 563 _expect102Processing = true; |
| 738 break; | 564 break; |
| 739 | 565 |
| 740 default: | 566 default: |
| 741 String[] values = value.toString().split(","); | 567 String[] values = value.toString().split(","); |
| 742 for (int i=0;values!=null && i<values.length;i++) | 568 for (int i=0;values!=null && i<values.length;i++) |
| 743 { | 569 { |
| 744 CachedBuffer cb=HttpHeaderValues.CACHE.get(values[i].trim()); | 570 CachedBuffer cb=HttpHeaderValues.CACHE.get(values[i].trim()); |
| 745 if (cb==null) | 571 if (cb==null) |
| 746 _expect=true; | 572 _expect = true; |
| 747 else | 573 else |
| 748 { | 574 { |
| 749 switch(cb.getOrdinal()) | 575 switch(cb.getOrdinal()) |
| 750 { | 576 { |
| 751 case HttpHeaderValues.CONTINUE_ORDINAL: | 577 case HttpHeaderValues.CONTINUE_ORDINAL: |
| 752 _expect100Continue=_generator instanceof HttpGenerator; | 578 _expect100Continue = true; |
| 753 break; | 579 break; |
| 754 case HttpHeaderValues.PROCESSING_ORDINAL: | 580 case HttpHeaderValues.PROCESSING_ORDINAL: |
| 755 _expect102Processing=_generator instanceof HttpGenerator; | 581 _expect102Processing = true; |
| 756 break; | 582 break; |
| 757 default: | 583 default: |
| 758 _expect=true; | 584 _expect = true; |
| 759 } | 585 } |
| 760 } | 586 } |
| 761 } | 587 } |
| 762 } | 588 } |
| 763 } | 589 } |
| 775 } | 601 } |
| 776 | 602 |
| 777 _requestFields.add(name, value); | 603 _requestFields.add(name, value); |
| 778 } | 604 } |
| 779 | 605 |
| 780 /* ------------------------------------------------------------ */ | 606 private void headerComplete() throws IOException |
| 781 protected void headerComplete() throws IOException | |
| 782 { | 607 { |
| 783 // Handle idle race | 608 // Handle idle race |
| 784 if (_endp.isOutputShutdown()) | 609 if (_endp.isOutputShutdown()) |
| 785 { | 610 { |
| 786 _endp.close(); | 611 _endp.close(); |
| 842 | 667 |
| 843 if(_charset!=null) | 668 if(_charset!=null) |
| 844 _request.setCharacterEncodingUnchecked(_charset); | 669 _request.setCharacterEncodingUnchecked(_charset); |
| 845 | 670 |
| 846 // Either handle now or wait for first content | 671 // Either handle now or wait for first content |
| 847 if ((((HttpParser)_parser).getContentLength()<=0 && !((HttpParser)_parser).isChunking())||_expect100Continue) | 672 if ((_parser.getContentLength()<=0 && !_parser.isChunking())||_expect100Continue) |
| 848 handleRequest(); | 673 handleRequest(); |
| 849 else | 674 else |
| 850 _delayedHandling=true; | 675 _delayedHandling = true; |
| 851 } | 676 } |
| 852 | 677 |
| 853 /* ------------------------------------------------------------ */ | 678 private void content(Buffer buffer) throws IOException |
| 854 protected void content(Buffer buffer) throws IOException | |
| 855 { | 679 { |
| 856 if (_delayedHandling) | 680 if (_delayedHandling) |
| 857 { | 681 { |
| 858 _delayedHandling=false; | 682 _delayedHandling=false; |
| 859 handleRequest(); | 683 handleRequest(); |
| 860 } | 684 } |
| 861 } | 685 } |
| 862 | 686 |
| 863 /* ------------------------------------------------------------ */ | 687 private void messageComplete(long contentLength) throws IOException |
| 864 public void messageComplete(long contentLength) throws IOException | |
| 865 { | 688 { |
| 866 if (_delayedHandling) | 689 if (_delayedHandling) |
| 867 { | 690 { |
| 868 _delayedHandling=false; | 691 _delayedHandling=false; |
| 869 handleRequest(); | 692 handleRequest(); |
| 870 } | 693 } |
| 871 } | 694 } |
| 872 | 695 |
| 873 /* ------------------------------------------------------------ */ | 696 private void earlyEOF() |
| 874 public void earlyEOF() | |
| 875 { | 697 { |
| 876 _earlyEOF = true; | 698 _earlyEOF = true; |
| 877 } | 699 } |
| 878 | 700 |
| 879 /* ------------------------------------------------------------ */ | 701 |
| 880 /* ------------------------------------------------------------ */ | |
| 881 /* ------------------------------------------------------------ */ | |
| 882 private class RequestHandler extends HttpParser.EventHandler | 702 private class RequestHandler extends HttpParser.EventHandler |
| 883 { | 703 { |
| 884 /* | |
| 885 * | |
| 886 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#startRequest(org.eclipse.io.Buffer, | |
| 887 * org.eclipse.io.Buffer, org.eclipse.io.Buffer) | |
| 888 */ | |
| 889 @Override | 704 @Override |
| 890 public void startRequest(Buffer method, Buffer uri, Buffer version) throws IOException | 705 public void startRequest(Buffer method, Buffer uri, Buffer version) throws IOException |
| 891 { | 706 { |
| 892 AbstractHttpConnection.this.startRequest(method, uri, version); | 707 AbstractHttpConnection.this.startRequest(method, uri, version); |
| 893 } | 708 } |
| 894 | 709 |
| 895 /* | |
| 896 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#parsedHeaderValue(org.eclipse.io.Buffer) | |
| 897 */ | |
| 898 @Override | 710 @Override |
| 899 public void parsedHeader(Buffer name, Buffer value) throws IOException | 711 public void parsedHeader(Buffer name, Buffer value) throws IOException |
| 900 { | 712 { |
| 901 AbstractHttpConnection.this.parsedHeader(name, value); | 713 AbstractHttpConnection.this.parsedHeader(name, value); |
| 902 } | 714 } |
| 903 | 715 |
| 904 /* | |
| 905 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#headerComplete() | |
| 906 */ | |
| 907 @Override | 716 @Override |
| 908 public void headerComplete() throws IOException | 717 public void headerComplete() throws IOException |
| 909 { | 718 { |
| 910 AbstractHttpConnection.this.headerComplete(); | 719 AbstractHttpConnection.this.headerComplete(); |
| 911 } | 720 } |
| 912 | 721 |
| 913 /* ------------------------------------------------------------ */ | |
| 914 /* | |
| 915 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#content(int, org.eclipse.io.Buffer) | |
| 916 */ | |
| 917 @Override | 722 @Override |
| 918 public void content(Buffer ref) throws IOException | 723 public void content(Buffer ref) throws IOException |
| 919 { | 724 { |
| 920 AbstractHttpConnection.this.content(ref); | 725 AbstractHttpConnection.this.content(ref); |
| 921 } | 726 } |
| 922 | 727 |
| 923 /* ------------------------------------------------------------ */ | |
| 924 /* | |
| 925 * (non-Javadoc) | |
| 926 * | |
| 927 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#messageComplete(int) | |
| 928 */ | |
| 929 @Override | 728 @Override |
| 930 public void messageComplete(long contentLength) throws IOException | 729 public void messageComplete(long contentLength) throws IOException |
| 931 { | 730 { |
| 932 AbstractHttpConnection.this.messageComplete(contentLength); | 731 AbstractHttpConnection.this.messageComplete(contentLength); |
| 933 } | 732 } |
| 934 | 733 |
| 935 /* ------------------------------------------------------------ */ | |
| 936 /* | |
| 937 * (non-Javadoc) | |
| 938 * | |
| 939 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#startResponse(org.eclipse.io.Buffer, int, | |
| 940 * org.eclipse.io.Buffer) | |
| 941 */ | |
| 942 @Override | 734 @Override |
| 943 public void startResponse(Buffer version, int status, Buffer reason) | 735 public void startResponse(Buffer version, int status, Buffer reason) |
| 944 { | 736 { |
| 945 if (LOG.isDebugEnabled()) | 737 if (LOG.isDebugEnabled()) |
| 946 LOG.debug("Bad request!: "+version+" "+status+" "+reason); | 738 LOG.debug("Bad request!: "+version+" "+status+" "+reason); |
| 947 } | 739 } |
| 948 | 740 |
| 949 /* ------------------------------------------------------------ */ | |
| 950 /* | |
| 951 * (non-Javadoc) | |
| 952 * | |
| 953 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#earlyEOF() | |
| 954 */ | |
| 955 @Override | 741 @Override |
| 956 public void earlyEOF() | 742 public void earlyEOF() |
| 957 { | 743 { |
| 958 AbstractHttpConnection.this.earlyEOF(); | 744 AbstractHttpConnection.this.earlyEOF(); |
| 959 } | 745 } |
| 960 } | 746 } |
| 961 | 747 |
| 962 /* ------------------------------------------------------------ */ | 748 |
| 963 /* ------------------------------------------------------------ */ | 749 public final class Output extends HttpOutput |
| 964 /* ------------------------------------------------------------ */ | |
| 965 public class Output extends HttpOutput | |
| 966 { | 750 { |
| 967 Output() | 751 Output() |
| 968 { | 752 { |
| 969 super(AbstractHttpConnection.this); | 753 super(AbstractHttpConnection.this); |
| 970 } | 754 } |
| 977 public void close() throws IOException | 761 public void close() throws IOException |
| 978 { | 762 { |
| 979 if (isClosed()) | 763 if (isClosed()) |
| 980 return; | 764 return; |
| 981 | 765 |
| 982 if (!isIncluding() && !super._generator.isCommitted()) | 766 if (!super._generator.isCommitted()) |
| 983 commitResponse(Generator.LAST); | 767 commitResponse(Generator.LAST); |
| 984 else | 768 else |
| 985 flushResponse(); | 769 flushResponse(); |
| 986 | 770 |
| 987 super.close(); | 771 super.close(); |
| 1079 | 863 |
| 1080 | 864 |
| 1081 } | 865 } |
| 1082 } | 866 } |
| 1083 | 867 |
| 1084 /* ------------------------------------------------------------ */ | |
| 1085 /* ------------------------------------------------------------ */ | |
| 1086 /* ------------------------------------------------------------ */ | |
| 1087 public class OutputWriter extends HttpWriter | |
| 1088 { | |
| 1089 OutputWriter() | |
| 1090 { | |
| 1091 super(AbstractHttpConnection.this._out); | |
| 1092 } | |
| 1093 } | |
| 1094 | |
| 1095 | |
| 1096 } | 868 } |
