/** * <p>Convenience method to call {@link #put(String, List)} with a singleton list that contains the specified * value.</p> * * @param key The key of the entry to put. * @param value The value to put. * @return The previous value associated with <code>key</code>, or <code>null</code> if there was no mapping for * <code>key</code>. */ public List<String> put(String key, String value) { return h.put(key, value); }
@Override public List<String> put(String key, List<String> value) { return h.put(key, value); }
public void setHeaders(String name, List<String> values) { headerFields.put(name, values); headerBlacklist.remove(name); }
public void setHeaders(String name, String value) { headerFields.put(name, value); headerBlacklist.remove(name); }
@Override public void putAll(Map<? extends String, ? extends List<String>> values) { for (Entry<? extends String, ? extends List<String>> entry : values.entrySet()) { put(entry.getKey(), entry.getValue()); } }
/** * <p>Adds the given value to the entry of the specified key. If no entry exists for the given key, a new one is * created containing only the given value.</p> * * @param key The key with which the specified value is to be associated. * @param value The value to be added to the list associated with the specified key. */ public void add(String key, String value) { List<String> lst = content.get(key); if (lst != null) { lst.add(value); } else { put(key, value); } }
/** * <p>Adds the given values to the entry of the specified key. If no entry exists for the given key, a new one is * created containing only the given values.</p> * * @param key The key with which the specified value is to be associated. * @param values The values to be added to the list associated with the specified key. */ public void add(String key, List<String> values) { List<String> lst = content.get(key); if (lst != null) { lst.addAll(values); } else { put(key, values); } }
@Override public void setHeaders(String name, String value) { parent.headers().put(name, value); }
@Override public void setHeaders(String name, List<String> values) { parent.headers().put(name, values); }
@Override public void setHeader(String name, String value) { parent.headers().put(name, value); }
@Override public void setHeaders(String name, String value) { parent.headers().put(name, value); }
@Override public void setHeaders(String name, List<String> values) { parent.headers().put(name, values); }
public void encodeCookieHeader(List<Cookie> cookies) { headers().put(HttpHeaders.Names.COOKIE, Cookie.toCookieHeader(cookies)); }
private void addResponseHeaders(HttpResponse httpResponse, long startTime) { if ( ! httpResponse.headers().containsKey(CONTENT_TYPE) && httpResponse.getContentType() != null) { StringBuilder s = new StringBuilder(httpResponse.getContentType()); if (httpResponse.getCharacterEncoding() != null) { s.append("; charset=").append(httpResponse.getCharacterEncoding()); } httpResponse.headers().put(CONTENT_TYPE, s.toString()); } addDateHeader(httpResponse, startTime); }
/** Write HTTP response using given handler */ public static void write(HttpResponse response, ResponseHandler handler) { response.headers().put("Content-Type", response.getContentType()); try (FastContentWriter writer = ResponseDispatch.newInstance(response.getJdiscResponse()) .connectFastWriter(handler)) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { response.render(out); } catch (IOException e) { throw new UncheckedIOException(e); } writer.write(out.toByteArray()); } }
public MockResponseHandler sendRequest(String uri, HttpRequest.Method method, ByteBuffer body, String contentType) { responseHandler = new MockResponseHandler(); Request request = HttpRequest.newServerRequest(driver, URI.create(uri), method); request.context().put("contextVariable", 37); // TODO: Add a method for accepting a Request instead request.headers().put(com.yahoo.jdisc.http.HttpHeaders.Names.CONTENT_TYPE, contentType); ContentChannel requestContent = request.connect(responseHandler); requestContent.write(body, null); requestContent.close(null); request.release(); return responseHandler; }