hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yaitskov <...@git.apache.org>
Subject [GitHub] httpcore pull request: HTTPCLIENT-1693 client request trailers
Date Sun, 25 Oct 2015 19:43:56 GMT
GitHub user yaitskov opened a pull request:

    https://github.com/apache/httpcore/pull/14

    HTTPCLIENT-1693 client request trailers

    This patch implements [HTTP 1.1 trailers](https://tools.ietf.org/html/rfc7230#section-4.1.2)
and allows a   client to send some headers after chunked body.
    
    For example client use streaming content (proxy) and cannot send data  like hash code
of transferred content in traditional headers.
      
    I opened [ticket](https://issues.apache.org/jira/browse/HTTPCLIENT-1693).
    
    Here is an example of usage without httpclient. I encountered problems because httpclient
and httpcore trunks are not compatible. So I found example in httpcore and modified it.
    Also there is a new test case for ChunkeOutputStream.
    
    ```
            HttpProcessor httpproc = HttpProcessorBuilder.create()
                    .add(new RequestContent())
                    .add(new RequestTargetHost())
                    .add(new RequestConnControl())
                    .add(new RequestUserAgent("Test/1.1"))
                    .build();
            HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
            HttpCoreContext coreContext = HttpCoreContext.create();
            HttpHost host = new HttpHost("localhost", 8080);
            coreContext.setTargetHost(host);
            DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024);
            InputStreamEntity requestBody =
                    new InputStreamEntity(
                            new ByteArrayInputStream(
                                    "This is the third test request (will be chunked)"
                                            .getBytes(Consts.UTF_8)),
                            ContentType.APPLICATION_OCTET_STREAM);
            requestBody.setChunked(true);
            Socket socket = new Socket(host.getHostName(), host.getPort());
            conn.bind(socket);
            BasicHttpRequest request = new BasicHttpRequest("POST", "/");
            request.setEntity(requestBody);
            Map<String, Callable<String>> m = new HashMap<>();
            m.put("t1", new Callable<String>() {
                public String call() throws Exception {
                    return "Hello world";
                }
            });
            request.setTrailers(m);
            httpexecutor.preProcess(request, httpproc, coreContext);
            HttpResponse response = httpexecutor.execute(request, conn, coreContext);
            httpexecutor.postProcess(response, httpproc, coreContext);
    
            System.out.println("<< Response: " + response.getStatusLine());
            System.out.println(EntityUtils.toString(response.getEntity()));
            System.out.println("==============");
            conn.close();
    ```

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/yaitskov/httpcore client-request-trailers

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/httpcore/pull/14.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #14
    
----
commit 4c08c2bd19a61a9cbcefd325074d4869a63a9a68
Author: Your Name <you@example.com>
Date:   2015-10-25T19:26:20Z

    client request trailers

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message