| 54 | } |
| 55 | |
| 56 | public class FirstLine implements NioReader.State { |
| 57 | private final HttpRequest headers = new HttpRequest(writer.getRemoteAddress()); |
| 58 | |
| 59 | @Override |
| 60 | public NioReader.State processBytes(ByteBuffer buffer) { |
| 61 | final int startPosition = buffer.position(); |
| 62 | while (buffer.remaining() > 0) { |
| 63 | if (isCurrentCharEol(buffer)) { |
| 64 | addFirstLine(buffer.array(), startPosition, buffer.position() - startPosition); |
| 65 | return new HeaderLine(headers); |
| 66 | } else { |
| 67 | buffer.position(buffer.position() + 1); |
| 68 | } |
| 69 | } |
| 70 | buffer.position(startPosition); |
| 71 | return null; |
| 72 | } |
| 73 | |
| 74 | private void addFirstLine(byte[] array, int startPosition, int length) { |
| 75 | int first = find(array, startPosition, length, ' '); |
| 76 | int firstLength = first - startPosition; |
| 77 | headers.method = new String(array, startPosition, firstLength, ascii); |
| 78 | int second = find(array, first + 1, length - firstLength, ' '); |
| 79 | int secondLength = second - first - 1; |
| 80 | headers.setRequestUri(URI.create(new String(array, startPosition + firstLength + 1, secondLength, ascii))); |
| 81 | headers.protocolVersion = new String(array, startPosition + firstLength + secondLength + 2, length - firstLength - secondLength - 2, ascii); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | public NioReader.State dispatchHttpRequest(HttpRequest headers) { |
| 86 | if (!sessionInit) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…