public SimpleRequest readRequest() throws IOException { try { String line = null; do { line = HttpParser.readLine(in, HTTP_ELEMENT_CHARSET); } while (line != null && line.length() == 0); if (line == null) { setKeepAlive(false); return null; } SimpleRequest request = new SimpleRequest( RequestLine.parseLine(line), HttpParser.parseHeaders(this.in, HTTP_ELEMENT_CHARSET), this.in); return request; } catch (IOException e) { close(); throw e; } }
public SimpleResponse readResponse() throws IOException { try { String line = null; do { line = HttpParser.readLine(in, HTTP_ELEMENT_CHARSET); } while (line != null && line.length() == 0); if (line == null) { setKeepAlive(false); return null; } SimpleResponse response = new SimpleResponse( new StatusLine(line), HttpParser.parseHeaders(this.in, HTTP_ELEMENT_CHARSET), this.in); return response; } catch (IOException e) { close(); throw e; } }
private CaptureSearchResult adaptWARCHTTPResponse(CaptureSearchResult result, WARCRecord rec) throws IOException { ArchiveRecordHeader header = rec.getHeader(); // need to parse the documents HTTP message and headers here: WARCReader // does not implement this... yet.. byte [] statusBytes = HttpParser.readRawLine(rec); int eolCharCount = getEolCharsCount(statusBytes); if (eolCharCount <= 0) { throw new RecoverableIOException("Failed to read http status where one " + " was expected: " + ((statusBytes == null) ? "(null)" : new String(statusBytes))); } String statusLine = EncodingUtil.getString(statusBytes, 0, statusBytes.length - eolCharCount, ARCConstants.DEFAULT_ENCODING); if ((statusLine == null) || !StatusLine.startsWithHTTP(statusLine)) { throw new RecoverableIOException("Failed parse of http status line."); } StatusLine status = new StatusLine(statusLine); result.setHttpCode(String.valueOf(status.getStatusCode())); Header[] headers = HttpParser.parseHeaders(rec, ARCConstants.DEFAULT_ENCODING); annotater.annotateHTTPContent(result,rec,headers,header.getMimetype()); return result; }
private Header[] getHttpHeaders(ArchiveRecord nativeRecord) throws IOException { if (nativeRecord instanceof ARCRecord) { return ((ARCRecord) nativeRecord).getHttpHeaders(); } else if (nativeRecord instanceof WARCRecord) { WARCRecord warcRecord = (WARCRecord) nativeRecord; if (warcRecord.hasContentHeaders()) { Header[] headers = HttpParser.parseHeaders(nativeRecord, DEFAULT_ENCODING); return headers; } } return new Header[0]; }
private void skipHeaders(ArchiveRecord record) throws IOException { HttpParser.parseHeaders(record, WARCConstants.DEFAULT_ENCODING); }