Search in sources :

Example 1 with FormattedHeader

use of org.apache.hc.core5.http.FormattedHeader in project httpcomponents-core by apache.

the class AbstractMessageWriter method write.

@Override
public void write(final T message, final SessionOutputBuffer buffer, final OutputStream outputStream) throws IOException, HttpException {
    Args.notNull(message, "HTTP message");
    Args.notNull(buffer, "Session output buffer");
    Args.notNull(outputStream, "Output stream");
    writeHeadLine(message, this.lineBuf);
    buffer.writeLine(this.lineBuf, outputStream);
    for (final Iterator<Header> it = message.headerIterator(); it.hasNext(); ) {
        final Header header = it.next();
        if (header instanceof FormattedHeader) {
            final CharArrayBuffer chbuffer = ((FormattedHeader) header).getBuffer();
            buffer.writeLine(chbuffer, outputStream);
        } else {
            this.lineBuf.clear();
            lineFormatter.formatHeader(this.lineBuf, header);
            buffer.writeLine(this.lineBuf, outputStream);
        }
    }
    this.lineBuf.clear();
    buffer.writeLine(this.lineBuf, outputStream);
}
Also used : FormattedHeader(org.apache.hc.core5.http.FormattedHeader) Header(org.apache.hc.core5.http.Header) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) FormattedHeader(org.apache.hc.core5.http.FormattedHeader)

Example 2 with FormattedHeader

use of org.apache.hc.core5.http.FormattedHeader in project httpcomponents-core by apache.

the class MessageSupport method parseTokens.

public static Set<String> parseTokens(final Header header) {
    Args.notNull(header, "Header");
    if (header instanceof FormattedHeader) {
        final CharArrayBuffer buf = ((FormattedHeader) header).getBuffer();
        final ParserCursor cursor = new ParserCursor(0, buf.length());
        cursor.updatePos(((FormattedHeader) header).getValuePos());
        return parseTokens(buf, cursor);
    }
    final String value = header.getValue();
    final ParserCursor cursor = new ParserCursor(0, value.length());
    return parseTokens(value, cursor);
}
Also used : CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) FormattedHeader(org.apache.hc.core5.http.FormattedHeader)

Example 3 with FormattedHeader

use of org.apache.hc.core5.http.FormattedHeader in project httpcomponents-core by apache.

the class ChunkedOutputStream method writeTrailers.

private void writeTrailers() throws IOException {
    final List<? extends Header> trailers = this.trailerSupplier != null ? this.trailerSupplier.get() : null;
    if (trailers != null) {
        for (int i = 0; i < trailers.size(); i++) {
            final Header header = trailers.get(i);
            if (header instanceof FormattedHeader) {
                final CharArrayBuffer chbuffer = ((FormattedHeader) header).getBuffer();
                this.buffer.writeLine(chbuffer, this.outputStream);
            } else {
                this.lineBuffer.clear();
                BasicLineFormatter.INSTANCE.formatHeader(this.lineBuffer, header);
                this.buffer.writeLine(this.lineBuffer, this.outputStream);
            }
        }
    }
}
Also used : FormattedHeader(org.apache.hc.core5.http.FormattedHeader) Header(org.apache.hc.core5.http.Header) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) FormattedHeader(org.apache.hc.core5.http.FormattedHeader)

Example 4 with FormattedHeader

use of org.apache.hc.core5.http.FormattedHeader in project httpcomponents-core by apache.

the class AbstractHeaderElementIterator method bufferHeaderValue.

private void bufferHeaderValue() {
    this.cursor = null;
    this.buffer = null;
    while (this.headerIt.hasNext()) {
        final Header h = this.headerIt.next();
        if (h instanceof FormattedHeader) {
            this.buffer = ((FormattedHeader) h).getBuffer();
            this.cursor = new ParserCursor(0, this.buffer.length());
            this.cursor.updatePos(((FormattedHeader) h).getValuePos());
            break;
        }
        final String value = h.getValue();
        if (value != null) {
            this.buffer = value;
            this.cursor = new ParserCursor(0, value.length());
            break;
        }
    }
}
Also used : FormattedHeader(org.apache.hc.core5.http.FormattedHeader) Header(org.apache.hc.core5.http.Header) FormattedHeader(org.apache.hc.core5.http.FormattedHeader)

Example 5 with FormattedHeader

use of org.apache.hc.core5.http.FormattedHeader in project httpcomponents-core by apache.

the class AbstractMessageWriter method write.

@Override
public void write(final T message, final SessionOutputBuffer sessionBuffer) throws IOException, HttpException {
    Args.notNull(message, "HTTP message");
    Args.notNull(sessionBuffer, "Session output buffer");
    writeHeadLine(message, this.lineBuf);
    sessionBuffer.writeLine(this.lineBuf);
    for (final Iterator<Header> it = message.headerIterator(); it.hasNext(); ) {
        final Header header = it.next();
        if (header instanceof FormattedHeader) {
            final CharArrayBuffer buffer = ((FormattedHeader) header).getBuffer();
            sessionBuffer.writeLine(buffer);
        } else {
            this.lineBuf.clear();
            this.lineFormatter.formatHeader(this.lineBuf, header);
            sessionBuffer.writeLine(this.lineBuf);
        }
    }
    this.lineBuf.clear();
    sessionBuffer.writeLine(this.lineBuf);
}
Also used : FormattedHeader(org.apache.hc.core5.http.FormattedHeader) Header(org.apache.hc.core5.http.Header) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) FormattedHeader(org.apache.hc.core5.http.FormattedHeader)

Aggregations

FormattedHeader (org.apache.hc.core5.http.FormattedHeader)6 Header (org.apache.hc.core5.http.Header)5 CharArrayBuffer (org.apache.hc.core5.util.CharArrayBuffer)5