C
C#16mo ago
PatrickG

❔ how to tell if a TCP request is a HTTP request

I am making a little proof of concept for a service that listens to TCP port when it receives a request it returns the same text as an answer for now I can also send request via a browser and I receive it but i need to apply special header and stuff to reply to HTTP request When a request is sent from browser it looks like this: GET /OMEGALUL HTTP/1.1 HOST: LOCALHOST:13000 CONNECTION: KEEP-ALIVE CACHE-CONTROL: MAX-AGE=0 SEC-CH-UA: "GOOGLE CHROME";V="111", "NOT(A:BRAND";V="8", "CHROMIUM";V="111" SEC-CH-UA-MOBILE: ?0 SEC-CH-UA-PLATFORM: "WINDOWS" UPGRADE-INSECURE-REQUESTS: 1 2023-03-24 09:06:03.570 -04:00 [INF] USER-AGENT: MOZILLA/5.0 (WINDOWS NT 10.0; WIN64; X64) APPLEWEBKIT/537.36 (KHTML, LIKE GECKO) CHROME/111.0.0.0 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-EXCHAN 2023-03-24 09:06:03.570 -04:00 [INF] GE;V=B3;Q=0.7 SEC-FETCH-SITE: NONE SEC-FETCH-MODE: NAVIGATE SEC-FETCH-USER: ?1 SEC-FETCH-DEST: DOCUMENT ACCEPT-ENCODING: GZIP, DEFLATE, BR ACCEPT-LANGUAGE: EN-US,EN;Q=0.9,FR;Q=0.8 is it safe to say that if request contains "HTTP/1.1" it is a http request and should be answered differently?
8 Replies
Jimmacle
Jimmacle16mo ago
is there a reason you're trying to do this from scratch instead of using ASP.NET Core?
PatrickG
PatrickG16mo ago
because i want to respond to plain TCP calls as well as http
Jimmacle
Jimmacle16mo ago
i'd just run 2 different listeners tbh one port for http, one for whatever protocol you're implementing
PatrickG
PatrickG16mo ago
hmm yea that could work
Jimmacle
Jimmacle16mo ago
it will be a lot less trouble than implementing a HTTP server yourself
canton7
canton716mo ago
Also, the normal way to tell what sort of TCP traffic you're receiving is.... to see what port it's on. That's the convention: if it's on port 80 it's HTTP, 443 is HTTPS, etc
PatrickG
PatrickG16mo ago
oh right, thanks
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.