本文整理汇总了Java中org.apache.http.HeaderIterator类的典型用法代码示例。如果您正苦于以下问题:Java HeaderIterator类的具体用法?Java HeaderIterator怎么用?Java HeaderIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HeaderIterator类属于org.apache.http包,在下文中一共展示了HeaderIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllowedMethods
import org.apache.http.HeaderIterator; //导入依赖的package包/类
public Set<String> getAllowedMethods(final HttpResponse response) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
HeaderIterator it = response.headerIterator("Allow");
Set<String> methods = new HashSet<String>();
while (it.hasNext()) {
Header header = it.nextHeader();
HeaderElement[] elements = header.getElements();
for (HeaderElement element : elements) {
methods.add(element.getName());
}
}
return methods;
}
示例2: headerIterator
import org.apache.http.HeaderIterator; //导入依赖的package包/类
@Override public HeaderIterator headerIterator() {
return new HeaderIterator() {
int index = 0;
@Override public boolean hasNext() {
return index < headers.length;
}
@Override public Header nextHeader() {
if (index >= headers.length) throw new NoSuchElementException();
return headers[index++];
}
@Override public Object next() {
return nextHeader();
}
@Override public void remove() {
throw new UnsupportedOperationException();
}
};
}
示例3: shouldSupportHeaderIteratorWithArg
import org.apache.http.HeaderIterator; //导入依赖的package包/类
@Test
public void shouldSupportHeaderIteratorWithArg() throws Exception {
HttpResponse resp =
new TestHttpResponse(304, "REDIRECTED",
new BasicHeader("Location", "http://bar.com"),
new BasicHeader("X-Zombo-Com", "http://zombo.com"),
new BasicHeader("Location", "http://foo.com"));
HeaderIterator it = resp.headerIterator("Location");
assertThat(it.hasNext()).isTrue();
assertThat(it.nextHeader().getValue()).isEqualTo("http://bar.com");
assertThat(it.hasNext()).isTrue();
assertThat(it.nextHeader().getValue()).isEqualTo("http://foo.com");
assertThat(it.hasNext()).isFalse();
}
示例4: getAllowedMethods
import org.apache.http.HeaderIterator; //导入依赖的package包/类
public Set<String> getAllowedMethods(final HttpResponse response) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
HeaderIterator it = response.headerIterator("Allow");
Set<String> methods = new HashSet<String>();
while (it.hasNext()) {
Header header = it.nextHeader();
HeaderElement[] elements = header.getElements();
for (HeaderElement element : elements) {
methods.add(element.getName());
}
}
return methods;
}
示例5: receiveRequest
import org.apache.http.HeaderIterator; //导入依赖的package包/类
public HttpRequest receiveRequest() throws HttpException, IOException {
HttpRequest request = (HttpRequest) this.requestParser.parse();
if (HEADERLOG.isDebugEnabled()) {
HEADERLOG.debug(">> " + request.getRequestLine().toString());
for (HeaderIterator it = request.headerIterator(); it.hasNext(); ) {
HEADERLOG.debug(">> " + it.nextHeader().toString());
}
}
// Prepare input stream
this.in = null;
if (request instanceof HttpEntityEnclosingRequest) {
long len = this.contentLenStrategy.determineLength(request);
if (len == ContentLengthStrategy.CHUNKED) {
this.in = new ChunkedInputStream(this.inbuffer);
} else if (len == ContentLengthStrategy.IDENTITY) {
this.in = new IdentityInputStream(this.inbuffer);
} else {
this.in = new ContentLengthInputStream(inbuffer, len);
}
}
return request;
}
示例6: buildResponseStr
import org.apache.http.HeaderIterator; //导入依赖的package包/类
/**
* Render the headers and the response content as a string.
* This could include more things such as the status code.
*
* @param response
* @return A string consisting of the HTTP Response headers nicely formatted.
*/
public String buildResponseStr(CloseableHttpResponse response) {
StringBuilder sb = new StringBuilder();
HeaderIterator hi = response.headerIterator();
while (hi.hasNext()) {
Header header = hi.nextHeader();
sb.append(header.getName()).append(": ").append(header.getValue()).append("\r\n");
}
sb.append("\r\n");
try {
sb.append(EntityUtils.toString(response.getEntity()));
} catch (IOException | IllegalStateException ex) {
// Don't care
}
return sb.toString();
}
示例7: removeHeaders
import org.apache.http.HeaderIterator; //导入依赖的package包/类
public void removeHeaders(final String name) {
if (name == null) {
return;
}
for (HeaderIterator i = this.headergroup.iterator(); i.hasNext(); ) {
Header header = i.nextHeader();
if (name.equalsIgnoreCase(header.getName())) {
i.remove();
}
}
}
示例8: BasicHeaderElementIterator
import org.apache.http.HeaderIterator; //导入依赖的package包/类
/**
* Creates a new instance of BasicHeaderElementIterator
*/
public BasicHeaderElementIterator(
final HeaderIterator headerIterator,
final HeaderValueParser parser) {
if (headerIterator == null) {
throw new IllegalArgumentException("Header iterator may not be null");
}
if (parser == null) {
throw new IllegalArgumentException("Parser may not be null");
}
this.headerIt = headerIterator;
this.parser = parser;
}
示例9: BasicTokenIterator
import org.apache.http.HeaderIterator; //导入依赖的package包/类
/**
* Creates a new instance of {@link BasicTokenIterator}.
*
* @param headerIterator the iterator for the headers to tokenize
*/
public BasicTokenIterator(final HeaderIterator headerIterator) {
if (headerIterator == null) {
throw new IllegalArgumentException
("Header iterator must not be null.");
}
this.headerIt = headerIterator;
this.searchPos = findNext(-1);
}
示例10: write
import org.apache.http.HeaderIterator; //导入依赖的package包/类
public void write(final T message) throws IOException, HttpException {
if (message == null) {
throw new IllegalArgumentException("HTTP message may not be null");
}
writeHeadLine(message);
for (HeaderIterator it = message.headerIterator(); it.hasNext(); ) {
Header header = it.nextHeader();
this.sessionBuffer.writeLine
(lineFormatter.formatHeader(this.lineBuf, header));
}
this.lineBuf.clear();
this.sessionBuffer.writeLine(this.lineBuf);
}
示例11: writeHeaders
import org.apache.http.HeaderIterator; //导入依赖的package包/类
protected static void writeHeaders(final HeaderGroup headers, final OutputStream output) throws IOException {
for (final HeaderIterator it = headers.iterator(); it.hasNext();) {
final org.apache.http.Header header = it.nextHeader();
Util.toOutputStream(BasicLineFormatter.formatHeader(header, null), output);
output.write(ByteArraySessionOutputBuffer.CRLF);
}
}
示例12: keys
import org.apache.http.HeaderIterator; //导入依赖的package包/类
public static Set<String> keys(HeaderGroup hg) {
Set<String> ret = new HashSet<>();
for (HeaderIterator it = hg.iterator(); it.hasNext();) {
Header header = it.nextHeader();
ret.add(header.getName().toLowerCase());
}
return ret;
}
示例13: getAllowedMethods
import org.apache.http.HeaderIterator; //导入依赖的package包/类
public Set<String> getAllowedMethods(final HttpResponse response) {
Args.notNull(response, "HTTP response");
final HeaderIterator it = response.headerIterator("Allow");
final Set<String> methods = new HashSet<String>();
while (it.hasNext()) {
final Header header = it.nextHeader();
final HeaderElement[] elements = header.getElements();
for (final HeaderElement element : elements) {
methods.add(element.getName());
}
}
return methods;
}
示例14: removeHeaders
import org.apache.http.HeaderIterator; //导入依赖的package包/类
public RequestBuilder removeHeaders(final String name) {
if (name == null || headergroup == null) {
return this;
}
for (final HeaderIterator i = headergroup.iterator(); i.hasNext(); ) {
final Header header = i.nextHeader();
if (name.equalsIgnoreCase(header.getName())) {
i.remove();
}
}
return this;
}
示例15: write
import org.apache.http.HeaderIterator; //导入依赖的package包/类
public void write(final HttpMessage message) throws IOException, HttpException {
Args.notNull(message, "HTTP message");
writeHeadLine(message);
for (final HeaderIterator it = message.headerIterator(); it.hasNext(); ) {
final Header header = it.nextHeader();
this.sessionBuffer.writeLine
(lineFormatter.formatHeader(this.lineBuf, header));
}
this.lineBuf.clear();
this.sessionBuffer.writeLine(this.lineBuf);
}