@Test public void testHeaderTooLarge() { String v = "GET /ok?x=a&y=b+c&z=123 HTTP/1.1\r\n" + "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryQ3pdBTBXxEFUWDML\r\n" + "\r\n"; long p = TestUtils.toMemory(v); try (HttpHeaderParser hp = new HttpHeaderParser(64, pool)) { hp.parse(p, p + v.length(), true); Assert.fail(); } catch (HttpException e) { TestUtils.assertContains(e.getMessage(), "header is too large"); } finally { Unsafe.free(p, v.length()); } }
public long parse(long ptr, long hi, boolean _method) { long p; if (_method && needMethod) { int l = parseMethod(ptr, hi); p = ptr + l; } else { p = ptr; } DirectByteCharSequence v; while (p < hi) { if (_wptr == this.hi) { throw HttpException.instance("header is too large"); } char b = (char) Unsafe.getUnsafe().getByte(p++); if (b == '\r') { continue; } Unsafe.getUnsafe().putByte(_wptr++, (byte) b); switch (b) { case ':': if (headerName == null) { headerName = pool.next().of(_lo, _wptr - 1); _lo = _wptr + 1; } break; case '\n': if (headerName == null) { incomplete = false; parseKnownHeaders(); return p; } v = pool.next().of(_lo, _wptr - 1); _lo = _wptr; headers.put(headerName, v); headerName = null; break; default: break; } } return p; }
HttpHeaderParser implements Mutable, Closeable, HttpRequestHeader { public long parse(long ptr, long hi, boolean _method) { long p; if (_method && needMethod) { int l = parseMethod(ptr, hi); p = ptr + l; } else { p = ptr; } DirectByteCharSequence v; while (p < hi) { if (_wptr == this.hi) { throw HttpException.instance("header is too large"); } char b = (char) Unsafe.getUnsafe().getByte(p++); if (b == '\r') { continue; } Unsafe.getUnsafe().putByte(_wptr++, (byte) b); switch (b) { case ':': if (headerName == null) { headerName = pool.next().of(_lo, _wptr - 1); _lo = _wptr + 1; } break; case '\n': if (headerName == null) { incomplete = false; parseKnownHeaders(); return p; } v = pool.next().of(_lo, _wptr - 1); _lo = _wptr; headers.put(headerName, v); headerName = null; break; default: break; } } return p; } }
HttpHeaderParser implements Mutable, Closeable, HttpRequestHeader { public long parse(long ptr, long hi, boolean _method) { long p; if (_method && needMethod) { int l = parseMethod(ptr, hi); p = ptr + l; } else { p = ptr; } DirectByteCharSequence v; while (p < hi) { if (_wptr == this.hi) { throw HttpException.instance("header is too large"); } char b = (char) Unsafe.getUnsafe().getByte(p++); if (b == '\r') { continue; } Unsafe.getUnsafe().putByte(_wptr++, (byte) b); switch (b) { case ':': if (headerName == null) { headerName = pool.next().of(_lo, _wptr - 1); _lo = _wptr + 1; } break; case '\n': if (headerName == null) { incomplete = false; parseKnownHeaders(); return p; } v = pool.next().of(_lo, _wptr - 1); _lo = _wptr; headers.put(headerName, v); headerName = null; break; default: break; } } return p; } HttpHeaderParser(int bufferLen, ObjectPool<DirectByteCharSequence> pool); }
HttpHeaderParser implements Mutable, Closeable, HttpRequestHeader { public long parse(long ptr, long hi, boolean _method) { long p; if (_method && needMethod) { int l = parseMethod(ptr, hi); p = ptr + l; } else { p = ptr; } DirectByteCharSequence v; while (p < hi) { if (_wptr == this.hi) { throw HttpException.instance("header is too large"); } char b = (char) Unsafe.getUnsafe().getByte(p++); if (b == '\r') { continue; } Unsafe.getUnsafe().putByte(_wptr++, (byte) b); switch (b) { case ':': if (headerName == null) { headerName = pool.next().of(_lo, _wptr - 1); _lo = _wptr + 1; } break; case '\n': if (headerName == null) { incomplete = false; parseKnownHeaders(); return p; } v = pool.next().of(_lo, _wptr - 1); _lo = _wptr; headers.put(headerName, v); headerName = null; break; default: break; } } return p; } HttpHeaderParser(int bufferLen, ObjectPool<DirectByteCharSequence> pool); @Override final void clear(); @Override void close(); @Override DirectByteCharSequence getBoundary(); @Override DirectByteCharSequence getCharset(); @Override CharSequence getContentDisposition(); @Override CharSequence getContentDispositionFilename(); @Override CharSequence getContentDispositionName(); @Override CharSequence getContentType(); @Override DirectByteCharSequence getHeader(CharSequence name); @Override ObjList<CharSequence> getHeaderNames(); @Override CharSequence getMethod(); @Override CharSequence getMethodLine(); @Override CharSequence getUrl(); @Override DirectByteCharSequence getUrlParam(CharSequence name); boolean isIncomplete(); long parse(long ptr, long hi, boolean _method); int size(); }
HttpHeaderParser implements Mutable, Closeable, HttpRequestHeader { public long parse(long ptr, long hi, boolean _method) { long p; if (_method && needMethod) { int l = parseMethod(ptr, hi); p = ptr + l; } else { p = ptr; } DirectByteCharSequence v; while (p < hi) { if (_wptr == this.hi) { throw HttpException.instance("header is too large"); } char b = (char) Unsafe.getUnsafe().getByte(p++); if (b == '\r') { continue; } Unsafe.getUnsafe().putByte(_wptr++, (byte) b); switch (b) { case ':': if (headerName == null) { headerName = pool.next().of(_lo, _wptr - 1); _lo = _wptr + 1; } break; case '\n': if (headerName == null) { incomplete = false; parseKnownHeaders(); return p; } v = pool.next().of(_lo, _wptr - 1); _lo = _wptr; headers.put(headerName, v); headerName = null; break; default: break; } } return p; } HttpHeaderParser(int bufferLen, ObjectPool<DirectByteCharSequence> pool); @Override final void clear(); @Override void close(); @Override DirectByteCharSequence getBoundary(); @Override DirectByteCharSequence getCharset(); @Override CharSequence getContentDisposition(); @Override CharSequence getContentDispositionFilename(); @Override CharSequence getContentDispositionName(); @Override CharSequence getContentType(); @Override DirectByteCharSequence getHeader(CharSequence name); @Override ObjList<CharSequence> getHeaderNames(); @Override CharSequence getMethod(); @Override CharSequence getMethodLine(); @Override CharSequence getUrl(); @Override DirectByteCharSequence getUrlParam(CharSequence name); boolean isIncomplete(); long parse(long ptr, long hi, boolean _method); int size();  }