This answer explains how the server version header can be completely removed by using HttpConfiguration.setSendServerVersion(false).
Is there a way to preserve the header, removing only the version number?
I am using Jetty 9.
There are multiple ways to achieve this. Perhaps the easiest (but not the cleanest) is to let Jetty send the default server header, but override the default version string to whatever you like right after you start the server:
private Server startServer() {
Server server = new Server();
// ... configure connectors, whatever you like
server.start();
// and do this the important part: *after* server.start():
org.eclipse.jetty.http.HttpGenerator.setJettyVersion("Jetty");
return server;
}
This way jetty sends Server: Jetty header, without version for each http based connectors (including https).
This works because Jetty prebuilds these kind of headers on server startup in a static array.
Related
In Qt webassembly documentation there is a mention, than one can use QNetworkAccessManager for HTTP communication with the server that hosts my website. The problem is, that I can't hard-code URL for the server as it should be able to be deployed on any server. Is there a simple way to receive it somehow?
The problem is, that I can't hard-code URL for the server as it should be able to be deployed on any server. Is there a simple way to receive it somehow?
Yes. Your server program runs a QApplication, and the single instance of that class could get that URL.
In other words, you'll document that your C++ program (the executable file obtained by compilation, e.g. with GCC) foo would accept some --server-url argument, and you would start foo --server-url http://example.com/somestrangeurl/
Please notice that WebAssembly is often running inside Web browsers (that is, inside Web or HTTP clients). Most HTTP servers (e.g. lighttpd) are running on Linux OS (and you might use Wt or libonion or some other HTTP server library for them, if you have to code your HTTP server from scratch).
I want to check a http header in request, which is received on apache 2.2 and if it contains that header I would like to fire a new request to jboss whose ip is different from apache server's. Is this possible?
I have seen this doc
enter link description here
In the above link I can check if header exist, but how to create new request to another server with same header forwarded.
Any help is appreciated.
What you suggest would send a redirect response to the browser, and it would be the browser who would end up visiting your Jboss server.
I'm not sure if that's precisely what you want, but sounds like what you want is to get Apache to do that request to Jboss and then send the response to the browser. This would be the typical scenario with a web server (apache) and an application server (Jboss) where you normally don't access the application server directly.
What you want to make this work in apache is a reverse proxy.
SSL/NPN will be handled via our loadbalancer (Haproxy), so I don't really need Jetty to do this for us.
But all the examples I can see on the web only show how to do this with SSL/NPN, not without.
Here's what I've attempted so far:
Server server = new Server();
HTTPConfiguration httpConfig = .... // set up some additional http config here
PushStrategey push = new ReferrerPushStrategy();
List<ConnectionFactory> factories = new ArrayList<>();
factories.add(new HTTPSPDYServerConnectionFactory(SPDY.V3, httpConfig, push));
factories.add(new HTTPSPDYServerConnectionFactory(SPDY.V2, httpConfig, push));
factories.add(new HTTPConnectionFactory(httpConfig));
ServerConnector connector = new ServerConnector(server, factories.toArray(new ConnectionFactory[factories.size()]));
connector.setPort(port);
server.addConnector(connector);
connector.start();
....
Unfortunately, it seems something is wrong, when I try to access the server via clients like curl or my browser they hang indefinitely. What am I doing wrong?
Thanks
When you configure a ServerConnector to speak clear-text SPDY, your clients must also speak clear-text SPDY.
If you use clients like curl or the browser, they don't speak clear-text SPDY. The clients will send a HTTP request which is not understood (the server expects SPDY), and that's why your connection "hangs".
Only Chromium/Chrome has a mode where you can make it speak clear-text SPDY, using the --use-spdy=no-ssl parameter as described here.
Therefore, if you're using clear-text SPDY there is no point in configuring multiple ServerConnectionFactory because there is no way to select one based on the protocol being negotiated, because there is no protocol negotiation.
The protocol negotiation only happens when using SSL+NPN.
Your code is basically correct (apart the unnecessary multiple ServerConnectionFactory) if you really want to setup a clear-text SPDY ServerConnector; this is an example of how the same is setup in the Jetty SPDY test suite.
Finally, see also the reference documentation about SPDY.
My apache2 module written in c++ works just fine, it handles "page.xyz"-like requests from browser clients, and it can return the appropriate result.
What I need now is to use my module as a client to another server: make a HTTP (GET) request and get the response (GET https://graph.facebook.com/oauth/access_token?...).
Does apache has a magic can do this, or do I have to deal with sockets and make HTTP packets manually? What is the best way to do this?
Many thanks!
I am guessing you are on your own with the HTTP client. Probably the easiest way to make an HTTP connection is to use libcurl. On linux it should be installable from your distro's repositories.
I hate CURL it is too bulky with too many dependencies when all I need to do is quickly open a URL. I don't even need to retrieve the contents of the web page, I just need to make the GET HTTP request to the server.
What's the most minimal way I can do this and don't say CURL !##$
There are lots of choices! Try libwww -- but be warned, most people strongly prefer libcurl. It's much easier to use.
There's a very light way and I've done this myself when implementing a high-scale back end service for a large media provider in the UK.
This method is extremely operating-system specific.
open a TCP socket to the HTTP server
send a "GET /path/to/url HTTP/1.1\r\nHost: www.host.com\r\n\r\n" (the Host header is required for HTTP/1.1 and most virtual servers, don't forget the two blank lines, and a newline requires a carriage return as well for HTTP headers)
wait for the response
close the socket
If you are going to close the socket at the end of the connection you may also want to send a Connection: close\r\n as part of your headers to inform the web server that you will terminate the connection after retrieving the web page.
You may run into trouble if you're fetching an encoded or generated web page in which case you'll have to add logic to interpret the fetched data.
On Windows (Windows XP, Windows 2000 Professional with SP3 and above) you could use WinHttpReadData API. There's also an example at the bottom of that page.
More info on Windows HTTP Services on MSDN
I have used Winsock when I need as few dependencies as possible and it has worked well. You need to write more code than using a separate library or the Microsoft WinHTTP library.
The functions you need are WSAStartup, socket, connect, send, recv, closesocket and WSACleanup.
See sample code for the send function.
system("wget -q -O file.htm http://url.com");