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;
    }
@Test
    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);
        }
    }