@Override public void startResponse(Buffer version, int status, Buffer reason) throws IOException { HttpExchange exchange = _exchange; if (exchange==null) { LOG.warn("No exchange for response"); _endp.close(); return; } switch(status) { case HttpStatus.CONTINUE_100: case HttpStatus.PROCESSING_102: // TODO check if appropriate expect was sent in the request. exchange.setEventListener(new NonFinalResponseListener(exchange)); break; case HttpStatus.OK_200: // handle special case for CONNECT 200 responses if (HttpMethods.CONNECT.equalsIgnoreCase(exchange.getMethod())) _parser.setHeadResponse(true); break; } _http11 = HttpVersions.HTTP_1_1_BUFFER.equals(version); _status=status; exchange.getEventListener().onResponseStatus(version,status,reason); exchange.setStatus(HttpExchange.STATUS_PARSING_HEADERS); }
@Override public boolean startResponse(HttpVersion version, int status, String reason) { HttpExchange exchange = getHttpExchange(); if (exchange == null) return false; String method = exchange.getRequest().getMethod(); parser.setHeadResponse(HttpMethod.HEAD.is(method) || (HttpMethod.CONNECT.is(method) && status == HttpStatus.OK_200)); exchange.getResponse().version(version).status(status).reason(reason); return !responseBegin(exchange); }
/** * Parse one HTTP request or response * @param rawHTTP Raw HTTP to parse * @return Any unparsed data in the rawHTTP (eg pipelined requests) * @throws IOException */ public byte[] parse(byte[] rawHTTP, boolean isHeadResponse) throws IOException { _charset = _defaultCharset; ByteArrayBuffer buf = new ByteArrayBuffer(rawHTTP); View view = new View(buf); PH ph = new PH(); HttpParser parser = new HttpParser(view,ph); parser.setHeadResponse(isHeadResponse); parser.parse(); if (ph.isEarlyEOF()) throw new EofException(); return view.asArray(); }
_parser.setHeadResponse(HttpMethods.HEAD.equalsIgnoreCase(method));
parser.setHeadResponse(head); try(ByteArrayOutputStream2 bout = new ByteArrayOutputStream2();)
/** * Parse one HTTP request or response * @param rawHTTP Raw HTTP to parse * @return Any unparsed data in the rawHTTP (eg pipelined requests) * @throws IOException */ public String parse(String rawHTTP, boolean isHeadResponse) throws IOException { _charset = _defaultCharset; ByteArrayBuffer buf = new ByteArrayBuffer(getByteArray(rawHTTP)); View view = new View(buf); PH ph = new PH(); HttpParser parser = new HttpParser(view,ph); parser.setHeadResponse(isHeadResponse); parser.parse(); if (ph.isEarlyEOF()) throw new EofException(); return getString(view.asArray()); }
@Override public boolean startResponse(HttpVersion version, int status, String reason) { if (updateState(State.IDLE, State.RECEIVE)) { HttpExchange exchange = connection.getExchange(); // The exchange may be null if it failed concurrently if (exchange != null) { HttpConversation conversation = exchange.getConversation(); HttpResponse response = exchange.getResponse(); parser.setHeadResponse(exchange.getRequest().getMethod() == HttpMethod.HEAD); response.version(version).status(status).reason(reason); // Probe the protocol handlers HttpClient client = connection.getHttpClient(); ProtocolHandler protocolHandler = client.findProtocolHandler(exchange.getRequest(), response); Response.Listener handlerListener = null; if (protocolHandler != null) { handlerListener = protocolHandler.getResponseListener(); LOG.debug("Found protocol handler {}", protocolHandler); } exchange.getConversation().updateResponseListeners(handlerListener); LOG.debug("Receiving {}", response); ResponseNotifier notifier = connection.getDestination().getResponseNotifier(); notifier.notifyBegin(conversation.getResponseListeners(), response); } } return false; }
@Override public boolean startResponse(HttpVersion version, int status, String reason) { if (updateState(State.IDLE, State.RECEIVE)) { HttpExchange exchange = connection.getExchange(); // The exchange may be null if it failed concurrently if (exchange != null) { HttpConversation conversation = exchange.getConversation(); HttpResponse response = exchange.getResponse(); parser.setHeadResponse(exchange.getRequest().getMethod() == HttpMethod.HEAD); response.version(version).status(status).reason(reason); // Probe the protocol handlers HttpClient client = connection.getHttpClient(); ProtocolHandler protocolHandler = client.findProtocolHandler(exchange.getRequest(), response); Response.Listener handlerListener = null; if (protocolHandler != null) { handlerListener = protocolHandler.getResponseListener(); LOG.debug("Found protocol handler {}", protocolHandler); } exchange.getConversation().updateResponseListeners(handlerListener); LOG.debug("Receiving {}", response); ResponseNotifier notifier = connection.getDestination().getResponseNotifier(); notifier.notifyBegin(conversation.getResponseListeners(), response); } } return false; }