Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ public void execute() throws IOException {
read = this.inputStream.read(buf, this.rlen, HTTPSession.BUFSIZE - this.rlen);
}

if(this.splitbyte == 0 && this.rlen == HTTPSession.BUFSIZE){
throw new ResponseException(Status.BAD_REQUEST, "BAD REQUEST: Request header is too large.");
}

if (this.splitbyte < this.rlen) {
this.inputStream.reset();
this.inputStream.skip(this.splitbyte);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
* %%
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*
* 3. Neither the name of the nanohttpd nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Expand All @@ -33,11 +33,11 @@
* #L%
*/

import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.junit.Test;

public class BadRequestTest extends HttpServerTest {

@Test
Expand Down Expand Up @@ -67,4 +67,17 @@ public void testMissingURI() throws IOException {
assertResponse(outputStream, expected);
}

@Test
public void testTooLargerURI() throws IOException {
StringBuilder request = new StringBuilder("GET http://example.com HTTP/1.1\r\n");
for(int i = 0; i < 1000; i++){
request.append("header"+i+": abcdefghijklmnopqrstuvwxyz\r\n");
}
ByteArrayOutputStream outputStream = invokeServer(request.toString());
String[] expected = new String[]{
"HTTP/1.1 400 Bad Request"
};
assertResponse(outputStream, expected);
}

}