[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpclient-commons-dev
Subject:    [jira] [Resolved] (HTTPCORE-633) DefaultHttpRequestWriter with SessionOutputBufferImpl
From:       "Oleg Kalnichevski (Jira)" <jira () apache ! org>
Date:       2020-06-25 17:08:00
Message-ID: JIRA.13313464.1593096122000.334992.1593104880202 () Atlassian ! JIRA
[Download RAW message or body]


     [ https://issues.apache.org/jira/browse/HTTPCORE-633?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel \
]

Oleg Kalnichevski resolved HTTPCORE-633.
----------------------------------------
    Resolution: Not A Bug

> DefaultHttpRequestWriter with SessionOutputBufferImpl
> -----------------------------------------------------
> 
> Key: HTTPCORE-633
> URL: https://issues.apache.org/jira/browse/HTTPCORE-633
> Project: HttpComponents HttpCore
> Issue Type: Bug
> Components: HttpCore
> Affects Versions: 5.0.1
> Environment: Windows 10
> OpenJDK 8 (RedHat 1.8.0.252-2)
> Maven + JUnit 5.6.2
> Reporter: Molnár Gergely
> Priority: Minor
> 
> Fail to read correct a header value: Connection: Keep-Alive if the puffer size of \
> the SessionOutputBufferImpl is not 1 (e.g.: 16) Existing parser test: 
> https://github.com/apache/httpcomponents-core/blob/master/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestRequestParser.java
>  No existing writer test!!
> Code:
> {code:java}
> public class HttpCoreApiIT {
> @Test
> public void parseWriteTest() throws Exception {
> // ----------- prepare parse --------
> String rawGet = "GET /home.html HTTP/1.1\r\n" + 
> "User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)\r\n" + 
> "Host: example.com\r\n" + 
> "Accept-Language: en-us\r\n" + 
> "Accept-Encoding: gzip, deflate\r\n" + 
> "Connection: Keep-Alive\r\n" + 
> "\r\n";
> int bufferSize = 16;
> SessionInputBuffer inBuffer = new SessionInputBufferImpl(bufferSize, \
> StandardCharsets.US_ASCII.newDecoder()); HttpMessageParser<ClassicHttpRequest> \
> reqParser = new DefaultHttpRequestParser(); Charset charset = \
> StandardCharsets.US_ASCII; // try
> ClassicHttpRequest request = reqParser.parse(inBuffer,
> new ByteArrayInputStream(rawGet.getBytes(StandardCharsets.UTF_8)));
> // test
> assertEquals("GET", request.getMethod());
> assertEquals("/home.html", request.getPath());
> assertEquals(5, request.getHeaders().length);
> assertEquals("example.com", request.getHeader("host").getValue());
> assertEquals("en-us", request.getHeader("Accept-Language").getValue());
> assertEquals("gzip, deflate", request.getHeader("Accept-Encoding").getValue());
> assertEquals("Mozilla/4.0 (compatible; MSIE5.01; Windows NT)", \
> request.getHeader("User-Agent").getValue()); assertEquals("Keep-Alive", \
> request.getHeader("Connection").getValue()); 
> 
> // ----------- prepare write --------
> SessionOutputBuffer outBuffer = new SessionOutputBufferImpl(bufferSize, \
> charset.newEncoder()); HttpMessageWriter<ClassicHttpRequest> reqWriter = new \
> DefaultHttpRequestWriter(); // try
> ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
> reqWriter.write(request, outBuffer, outputStream);
> //outBuffer.flush(outputStream); // not documented, but needed
> // prepare test with tested parser
> SessionInputBuffer otherInBuffer = new SessionInputBufferImpl(bufferSize, \
> charset.newDecoder()); ClassicHttpRequest otherRequest = \
> reqParser.parse(otherInBuffer, new \
> ByteArrayInputStream(outputStream.toByteArray())); outputStream.close();
> // test
> assertEquals("GET", otherRequest.getMethod());
> assertEquals("/home.html", otherRequest.getPath());
> assertEquals(5, otherRequest.getHeaders().length);
> assertEquals("example.com", otherRequest.getHeader("host").getValue());
> assertEquals("en-us", otherRequest.getHeader("Accept-Language").getValue());
> assertEquals("gzip, deflate", \
> otherRequest.getHeader("Accept-Encoding").getValue()); assertEquals("Mozilla/4.0 \
> (compatible; MSIE5.01; Windows NT)", \
> otherRequest.getHeader("User-Agent").getValue()); assertEquals("Keep-Alive", \
> otherRequest.getHeader("Connection").getValue()); }
> }
> {code}
> outBuffer.flush(outputStream);  solve the problem, but that is not documented.
> [ERROR] Failures: 
> [ERROR]   HttpCoreApiIT.parseWriteTest:82 expected: <Keep-Alive> but was: <Keep>
> Part 2:
> Does the DefaultHttpRequestParser handle well this raw request (HTTP Proxy tunnel):
> {code:java}
> String rawGet = "CONNECT example.com:80 HTTP/1.1\r\n" + 
> "Host: example.com:80\r\n" + 
> "Proxy-Authorization: basic aGVsbG86d29ybGQ=\r\n" + 
> "\r\n";
> {code}
> the request.getAuthority() return null, but expected: new \
> URIAuthority("example.com", 80);



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic