HttpRequest extends CertainlyCloneable<HttpRequest> { public HttpRequest merge(HttpRequest r) { HttpRequest copy = clone(); if (r.scheme != null) copy.scheme = r.scheme; if (r.host != null) copy.host = r.host; if (r.port != 0) copy.port = r.port; if (r.path != null) copy.path = r.path; for (KeyValuePair h : r.headers) { boolean containsElement = false; for (KeyValuePair h2 : copy.headers) { containsElement |= (h.key.equals(h2.key)); } if (!containsElement) copy.headers.add(h); } for (KeyValuePair h : r.urlOptions) { boolean containsElement = false; for (KeyValuePair h2 : copy.urlOptions) { containsElement |= (h.key.equals(h2.key)); } if (!containsElement) copy.urlOptions.add(h); } if (r.timeoutMillis != 0) copy.timeoutMillis = r.timeoutMillis; if (r.postContent != null) copy.postContent = r.postContent; if (r.httpOperation != null) copy.httpOperation = r.httpOperation; return copy; } HttpRequest(); String getScheme(); String getHost(); int getPort(); String getPath(); List<KeyValuePair> getUrlOptions(); String getOption(String key, String defaultValue); List<KeyValuePair> getHeaders(); String getHeader(String key, String defaultValue); long getTimeoutMillis(); Object getPostContent(); HttpOp getHttpOperation(); HttpRequest setScheme(String scheme); HttpRequest setHost(String hostname); HttpRequest setPort(int port); HttpRequest setPath(String path); HttpRequest addUrlOption(String key, String value); HttpRequest setUrlOptions(List<KeyValuePair> options); HttpRequest addHttpHeader(String key, String value); HttpRequest setTimeout(long timeoutMillis); HttpRequest setPostContent(Object content); HttpRequest setHttpOperation(HttpOp op); HttpRequest merge(HttpRequest r); @Override HttpRequest clone(); @Override String toString(); String toString(boolean verbose); void verifyComplete(); boolean equals(Object o);  }
@Test public void testMerge() { { HttpRequest base = new HttpRequest() .setHttpOperation(HttpRequest.HttpOp.POST) .addUrlOption("hmm", "arg") .addHttpHeader("x-foo", "bar"); HttpRequest req = new HttpRequest() .addUrlOption("hmm", "arg") .addHttpHeader("x-foo", "bar"); HttpRequest merged = base.merge(req); HttpRequest expected = new HttpRequest() .setHttpOperation(HttpRequest.HttpOp.POST) .addUrlOption("hmm", "arg") .addHttpHeader("x-foo", "bar"); assertEquals(expected, merged); } { HttpRequest base = new HttpRequest() .setHttpOperation(HttpRequest.HttpOp.POST) .addHttpHeader("x-foo", "bar") .addUrlOption("hmm", "arg"); HttpRequest req = new HttpRequest() .setHttpOperation(HttpRequest.HttpOp.PUT) .setPath("/gohere") .addHttpHeader("Content-Type", "whatevah") .addUrlOption("tit", "tat") .setPostContent("foo"); HttpRequest merged = base.merge(req); HttpRequest expected = new HttpRequest() .setHttpOperation(HttpRequest.HttpOp.PUT) .setPath("/gohere") .addHttpHeader("x-foo", "bar") .addHttpHeader("Content-Type", "whatevah") .addUrlOption("hmm", "arg") .addUrlOption("tit", "tat") .setPostContent("foo"); assertEquals(expected, merged); } }