2020年12月20日星期日

Browser sending Empty Request to own Server

I have been coding my own Webserver in Java recently because I thought it was neat having one and yesterday I stumbled upon a problem that I still havent fixed. My browser (ungoogled Chromium) seems to send some empty requests or something like that to the Server. I have implemented a Request Handler that is supposed to read the GET Request and extract the requested ressource. It works like this : it takes the request for example : "GET /index.html HTTP/1.1" and puts it in an Array with the String.split(" "); method the Array then looks like this : ["GET", "/index.html", "HTTP/1.1"] Then I store the second value of the array, in this case "/index.html" in a variable that I can then use to locate the requested file and serve it to the User. For debugging purposes I also print out the full requests sent by the user, that looks like this

GET, /index.html, HTTP/1.1 Host:, localhost:8080 Connection:, keep-alive Cache-Control:, max-age=0 Upgrade-Insecure-Requests:, 1 DNT:, 1 User-Agent:, Mozilla/5.0, (X11;, Linux, x86_64), AppleWebKit/537.36, (KHTML,, like, Gecko), Chrome/86.0.4240.111, Safari/537.36 Accept:, text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9 Sec-Fetch-Site:, same-origin Sec-Fetch-Mode:, navigate Sec-Fetch-Dest:, document Referer:, http://localhost:8080/index.html Accept-Encoding:, gzip,, deflate,, br Accept-Language:, en-US,en;q=0.9

However, sometimes the Request is just empty, It prints exactly this : [] It then throws an ArrayIndexOutOfBoundsException obviously. This is pretty annoying because it works perfectly fine with the Linux "curl" command (curl localhost:8080/index.html) I have already tried to solve the issue by using wireshark and looking for some weird stuff but none of my attempts to fix this issue have worked sadly. I hope I could provide enough information for anyone to help me with my Issue, I've been trying to solve this for 2 days now and i'd be super grateful if someone helps me. Thanks

Sorry for the poor text formation, this is my first stackoverflow question

https://stackoverflow.com/questions/65386563/browser-sending-empty-request-to-own-server December 21, 2020 at 09:40AM

没有评论:

发表评论