@Override public Request header(final String name, final Object value) { return new BaseRequest( this.wire, this.home, this.hdrs.with(new ImmutableHeader(name, value.toString())), this.mtd, this.content, this.connect, this.read ); }
/** * Public ctor. * @param key The name of it * @param value The value */ public ImmutableHeader(final String key, final String value) { this.left = ImmutableHeader.normalize(key); this.right = value; }
/** * Normalize key. * @param key The key to normalize * @return Normalized key */ public static String normalize(final String key) { final char[] chars = key.toCharArray(); chars[0] = ImmutableHeader.upper(chars[0]); for (int pos = 1; pos < chars.length; ++pos) { if (chars[pos - 1] == '-') { chars[pos] = ImmutableHeader.upper(chars[pos]); } } return new String(chars); }
/** * Make a similar request, with the provided HTTP header. * @param name Name of the header * @param value Value of it * @return New request */ public FakeRequest withHeader(final String name, final String value) { return new FakeRequest( this.code, this.phrase, this.hdrs.with(new ImmutableHeader(name, value)), this.content ); }
@Override public Request reset(final String name) { final Collection<Map.Entry<String, String>> headers = new LinkedList<>(); final String key = ImmutableHeader.normalize(name); for (final Map.Entry<String, String> header : this.hdrs) { if (!header.getKey().equals(key)) { headers.add(header); } } return new BaseRequest( this.wire, this.home, headers, this.mtd, this.content, this.connect, this.read ); }
/** * Make a copy of this answer, with an extra header. * @param name Name of the header * @param value ImmutableHeader value * @return New answer */ public MkAnswer.Simple withHeader(final String name, final String value) { return new MkAnswer.Simple( this.code, this.hdrs.with(new ImmutableHeader(name, value)), this.content ); } /**
/** * Fetch headers from the request. * @param request Request * @return Headers */ private static ArrayMap<String, List<String>> headers( final GrizzlyRequest request) { final ConcurrentMap<String, List<String>> headers = new ConcurrentHashMap<String, List<String>>(0); final Enumeration<?> names = request.getHeaderNames(); while (names.hasMoreElements()) { final String name = names.nextElement().toString(); headers.put( ImmutableHeader.normalize(name), GrizzlyQuery.headers(request, name) ); } return new ArrayMap<>(headers); }
/** * Make a list of all hdrs. * @param list Apache HTTP hdrs * @return Body in UTF-8 */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private Array<Map.Entry<String, String>> headers(final Header... list) { final Collection<Map.Entry<String, String>> headers = new LinkedList<>(); for (final Header header : list) { headers.add( new ImmutableHeader( header.getName(), header.getValue() ) ); } return new Array<Map.Entry<String, String>>(headers); } };
/** * Get headers from response. * @param fields ImmutableHeader fields * @return Headers */ private Array<Map.Entry<String, String>> headers( final Map<String, List<String>> fields) { final Collection<Map.Entry<String, String>> headers = new LinkedList<Map.Entry<String, String>>(); for (final Map.Entry<String, List<String>> field : fields.entrySet()) { if (field.getKey() == null) { continue; } for (final String value : field.getValue()) { headers.add(new ImmutableHeader(field.getKey(), value)); } } return new Array<>(headers); } /**
@Override public Response send(final Request req, final String home, final String method, final Collection<Map.Entry<String, String>> headers, final InputStream content, final int connect, final int read) throws IOException { final Collection<Map.Entry<String, String>> hdrs = new LinkedList<Map.Entry<String, String>>(); boolean absent = true; for (final Map.Entry<String, String> header : headers) { hdrs.add(header); if (header.getKey().equals(HttpHeaders.USER_AGENT)) { absent = false; } } if (absent) { hdrs.add( new ImmutableHeader( HttpHeaders.USER_AGENT, UserAgentWire.AGENT ) ); } return this.origin.send( req, home, method, hdrs, content, connect, read ); } }
new ImmutableHeader( HttpHeaders.COOKIE, text.toString()
final String[] parts = info.split(":", 2); hdrs.add( new ImmutableHeader( HttpHeaders.AUTHORIZATION, Logger.format(