Skip to content

Commit

Permalink
NUTCH-2560 protocol-http throws an error when an http header spans ov…
Browse files Browse the repository at this point in the history
…er multiple lines

- add unit test to verify that multi-line headers are correctly parsed
  • Loading branch information
sebastian-nagel committed Jun 11, 2018
1 parent d163512 commit a2771dc
Showing 1 changed file with 19 additions and 0 deletions.
Expand Up @@ -19,6 +19,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.BufferedReader;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -62,6 +63,7 @@ public void setUp() throws Exception {
conf = new Configuration();
conf.addResource("nutch-default.xml");
conf.addResource("nutch-site-test.xml");
conf.setBoolean("store.http.headers", true);

http = new Http();
http.setConf(conf);
Expand Down Expand Up @@ -239,6 +241,23 @@ public void testNoStatusLine() throws Exception {
new String(fetched.getContent(), StandardCharsets.UTF_8));
}

/**
* NUTCH-2560 protocol-http throws an error when an http header spans over
* multiple lines
*/
@Test
public void testMultiLineHeader() throws Exception {
setUp();
launchServer(responseHeader
+ "Set-Cookie: UserID=JohnDoe;\r\n Max-Age=3600;\r\n Version=1\r\n"
+ simpleContent);
Response fetched = fetchPage("/", 200);
LOG.info("Headers: {}", fetched.getHeaders());
assertNotNull("Failed to set multi-line \"Set-Cookie\" header.", fetched.getHeader("Set-Cookie"));
assertTrue("Failed to set multi-line \"Set-Cookie\" header.",
fetched.getHeader("Set-Cookie").contains("Version=1"));
}

/**
* NUTCH-2561 protocol-http can be made to read arbitrarily large HTTP
* responses
Expand Down

0 comments on commit a2771dc

Please sign in to comment.