org.apache.http.message.BufferedHeader Java Examples
The following examples show how to use
org.apache.http.message.BufferedHeader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JolokiaClientFactory.java From hawkular-agent with Apache License 2.0 | 6 votes |
@Override public Header authenticate(Credentials credentials, HttpRequest request, HttpContext context) throws AuthenticationException { Args.notNull(credentials, "Credentials"); Args.notNull(request, "HTTP request"); // the bearer token is stored in the password field, not credentials.getUserPrincipal().getName() String bearerToken = credentials.getPassword(); CharArrayBuffer buffer = new CharArrayBuffer(64); if (isProxy()) { buffer.append("Proxy-Authorization"); } else { buffer.append("Authorization"); } buffer.append(": Bearer "); buffer.append(bearerToken); return new BufferedHeader(buffer); }
Example #2
Source File: HeadersBuilder.java From cs-actions with Apache License 2.0 | 6 votes |
public List<Header> buildHeaders() { ArrayList<Header> headersArr = new ArrayList<>(); if (!StringUtils.isEmpty(headers)) { BufferedReader in = new BufferedReader(new StringReader(headers)); String str; try { while ((str = in.readLine()) != null) { CharArrayBuffer charArrayBuffer = new CharArrayBuffer(str.length()); charArrayBuffer.append(str); headersArr.add(new BufferedHeader(charArrayBuffer)); } } catch (IOException e) { throw new IllegalArgumentException(e); } } if (entityContentType != null) { headersArr.add(entityContentType); } else if (contentType != null && !contentType.toString().isEmpty()) { headersArr.add(new BasicHeader("Content-Type", contentType.toString())); } return headersArr; }
Example #3
Source File: HeadersBuilderTest.java From cs-actions with Apache License 2.0 | 6 votes |
@Test public void build() { ContentType contentType = ContentType.parse(CONTENT_TYPE); List<Header> headers = new HeadersBuilder() .setHeaders("header1:value1\nheader2:value2") .setContentType(contentType) .buildHeaders(); assertEquals(3, headers.size()); assertThat(headers.get(0), instanceOf(BufferedHeader.class)); BufferedHeader basicHeader = (BufferedHeader) headers.get(1); assertEquals("header2", basicHeader.getName()); assertEquals("value2", basicHeader.getValue()); BasicHeader contentTypeHeader = (BasicHeader) headers.get(2); assertEquals("Content-Type", contentTypeHeader.getName()); assertEquals(CONTENT_TYPE, contentTypeHeader.getValue()); }
Example #4
Source File: HtmlUnitBrowserCompatCookieSpec.java From htmlunit with Apache License 2.0 | 5 votes |
@Override public List<Header> formatCookies(final List<Cookie> cookies) { Collections.sort(cookies, COOKIE_COMPARATOR); final CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size()); buffer.append(SM.COOKIE); buffer.append(": "); for (int i = 0; i < cookies.size(); i++) { final Cookie cookie = cookies.get(i); if (i > 0) { buffer.append("; "); } final String cookieName = cookie.getName(); final String cookieValue = cookie.getValue(); if (cookie.getVersion() > 0 && !isQuoteEnclosed(cookieValue)) { HtmlUnitBrowserCompatCookieHeaderValueFormatter.INSTANCE.formatHeaderElement( buffer, new BasicHeaderElement(cookieName, cookieValue), false); } else { // Netscape style cookies do not support quoted values buffer.append(cookieName); buffer.append("="); if (cookieValue != null) { buffer.append(cookieValue); } } } final List<Header> headers = new ArrayList<>(1); headers.add(new BufferedHeader(buffer)); return headers; }