<commit_before>package org.jdrupes.httpcodec.test;

import static org.junit.Assert.*;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

import org.jdrupes.httpcodec.HttpRequestDecoder;
import org.jdrupes.httpcodec.RequestResult;
import org.junit.Test;

public class ProtocolErrorsTests {

	@Test
	public void testVersion() throws UnsupportedEncodingException {
		String reqText 
			= "GET / HTTP/0.8\r\n"
			+ "Host: localhost:8888\r\n"
			+ "\r\n";
		ByteBuffer buffer = ByteBuffer.wrap(reqText.getBytes("ascii"));
		HttpRequestDecoder decoder = new HttpRequestDecoder();
		RequestResult result = decoder.decode(buffer);
		assertFalse(result.hasMessage());
		assertFalse(result.hasPayloadBytes());
		assertFalse(result.hasPayloadChars());
		assertTrue(result.hasResponse());
		assertEquals(505, result.getResponse().getStatusCode());
	}

}<commit_msg>New test.<commit_after>package org.jdrupes.httpcodec.test;

import static org.junit.Assert.*;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

import org.jdrupes.httpcodec.HttpRequestDecoder;
import org.jdrupes.httpcodec.RequestResult;
import org.junit.Test;

public class ProtocolErrorsTests {

	@Test
	public void testVersion() throws UnsupportedEncodingException {
		String reqText 
			= "GET / HTTP/0.8\r\n"
			+ "Host: localhost:8888\r\n"
			+ "\r\n";
		ByteBuffer buffer = ByteBuffer.wrap(reqText.getBytes("ascii"));
		HttpRequestDecoder decoder = new HttpRequestDecoder();
		RequestResult result = decoder.decode(buffer);
		assertFalse(result.hasMessage());
		assertFalse(result.hasPayloadBytes());
		assertFalse(result.hasPayloadChars());
		assertTrue(result.hasResponse());
		assertEquals(505, result.getResponse().getStatusCode());
	}

	/**
	 * RFC 7230 3.1.1
	 * 
	 * @throws UnsupportedEncodingException
	 */
	@Test
	public void testRequestWithWhitespace()
	        throws UnsupportedEncodingException {
		String reqText 
			= "GET /tricky/Resource HTTP/1.1 HTTP/1.1\r\n"
			+ "Host: localhost:8888\r\n"
			+ "\r\n";
		ByteBuffer buffer = ByteBuffer.wrap(reqText.getBytes("ascii"));
		HttpRequestDecoder decoder = new HttpRequestDecoder();
		RequestResult result = decoder.decode(buffer);
		assertFalse(result.hasMessage());
		assertFalse(result.hasPayloadBytes());
		assertFalse(result.hasPayloadChars());
		assertTrue(result.hasResponse());
		assertEquals(400, result.getResponse().getStatusCode());
	}

}
{'fraction_non_alphanumeric': 0.129644921552436, 'fraction_numerical': 0.01486374896779521, 'mean_word_length': 5.244845360824742, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3838301', 'n_tokens_mistral': 817, 'n_tokens_neox': 744, 'n_words': 131}