Sometimes if we start a local webserver, or if we use other online pages, we would like to find out what webserver it is, and it is possible to do it right inside of the webpage. We can fetch something, and look at the response header by res.headers.get("Server")
:
fetch("foo.txt").then((res) => {
document.querySelector(
"#server-note"
).innerHTML = `The server is ${JSON.stringify(res.headers.get("Server"))}`;
});
Demo: https://jsfiddle.net/KennethKinLum/80td3s4f/
The server for
Webserver | in the header |
---|---|
Node.js's live-server
|
nothing (null)
|
Ruby's ruby -run -e httpd . -p 8080
|
WEBrick/1.4.2 (Ruby/2.6.3/2019-04-16) |
Python 2's python -m SimpleHTTPServer 8080
|
SimpleHTTP/0.6 Python/2.7.16 |
Python 3's python3 -m http.server 8080
|
SimpleHTTP/0.6 Python/3.8.2 |
JSFiddle | nginx |
Codesandbox | cloudflare |
macOS Big Sur's webserver | Apache/2.4.46 (Unix) |
It is possible to tell the user-agent as well, using navigator.userAgent
.
Top comments (0)