okhttp
okhttp copied to clipboard
Removing the limitation of 256KB for header size
This allows users to not be restricted to the limitation of 256KB for the size of the header, in order to solve #8472 :
How to reproduce
Python3 server code
import socket
import random
import string
def generate_random_string(length):
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=256 * 1024 - 48))
# Création d'un socket TCP
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server_socket:
server_socket.bind(('127.0.0.1', 8080))
server_socket.listen()
while True:
conn, addr = server_socket.accept()
with conn:
response = (
"HTTP/1.1 200 OK\n"
"Content-Type: text/plain\n"
f"MyHeader:{random_string}\n"
"Content-Length: 14\n"
"\n"
"Erreur de requête"
)
conn.sendall(response.encode('utf-8'))
Kotlin Client code after/before the PR (Comment/Uncomment lines 10/11)
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.internal.http1.HeadersReader;
public class OkHttpTest {
private static final String ENDPOINT = "http://127.0.0.1:8080";
public static void main(String... args) {
OkHttpClient client = new OkHttpClient.Builder().build();
//OkHttpClient client = new OkHttpClient.Builder().headerSizeLimit(HeadersReader.HEADER_NO_LIMIT).build();
try {
Request request = new Request.Builder()
.url(ENDPOINT)
.build();
try (Response response = client.newCall(request).execute()) {
ResponseBody body = response.body();
System.out.println(body.string());
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
Before, you will get an EOFException
, after, everything works fine