You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/10/25 20:44:27 UTC

[jira] [Commented] (HTTPCLIENT-1693) Send HTTP trailers in request

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1693?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14973405#comment-14973405 ] 

ASF GitHub Bot commented on HTTPCLIENT-1693:
--------------------------------------------

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 <yo...@example.com>
Date:   2015-10-25T19:26:20Z

    client request trailers

----


> Send HTTP trailers in request
> -----------------------------
>
>                 Key: HTTPCLIENT-1693
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1693
>             Project: HttpComponents HttpClient
>          Issue Type: New Feature
>          Components: HttpClient
>            Reporter: Daneel Yaitskov
>
> Currently HTTP client doesn't support sending trailers to a web server.
> The section https://tools.ietf.org/html/rfc7230#section-4.4 is need to be implemented.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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