Can I send resources with HTTP/2 Server Push? - http2

My webapp, written in Go, deployed on Google App Engine Standard, has handlers to generate HTML for each page (server-side rendering). It would be nice for performance if I could in certain cases (cautiously) pre-emptively send CSS and JS resources along with the HTML response, with HTTP/2 Server Push.
Is it possible with the Go runtime of App Engine?
(Another way of putting this: does the ResponseWriter in App Engine implement the http.Pusher interface?)

This doesn't seem to be possible out-of-the-box right now:
if _, ok := w.(http.Pusher); ok {
fmt.Fprintln(w, "This ResponseWriter is a Pusher :)")
} else {
fmt.Fprintln(w, "This ResponseWriter is NOT a Pusher :(")
}
produces
This ResponseWriter is NOT a Pusher :(
(in production, and in the local dev server as well)

Related

ColdFusion API and Websockets

I am hoping someone can point me in the right direction. I have a CF2021 Server which uses a Node.js websocket server and CF pages (via javascript) as a client. Messages from user to user work as expected, so no issue there.
This CF Server also has a custom API built using CFML that handles and routes inbound SMS messages. My question is; what would be the best way to send the SMS message (by now its json) to the Node.js websocket to it can send it to the user(s).
I tried using the same javascript that the browser client uses, but it appears that the CFML API script is "browser-less", so that doesn't work, or should it?
I thought something like Apache Groovy may be the solution, but I am having difficulties with any websocket example I have found.
Any suggestions would be greatly appreciated.
thanks in advance
Flow matters.
If you want to handle an incoming message by delivering it to all currently logged in users who are subscribed to messages of the current sort: set up your message handler to deliver using lucee/adobe-coldfusion websockets. Be forewarned, Lucee takes some setup time, but once running, it is a great solution.
If you don't need immediate delivery, or you need a super simple solution: I actually have had some success with "Long Polling" you just have to remember to use "flush" early in the request, before any pause/sleep, then loop your message lookup requests for new data, with a 1-5 second delay between each loop. Once new data is found, I like to return the request to the client, close that polling request and start a new polling request using the client side. I typically won't poll for more than 60 seconds. Even if the returned json object is empty.

How to subscribe websocket by Chrome extensions?

I am try to implement a basic web socket app by following this tutorial:https://spring.io/guides/gs/messaging-stomp-websocket/
However, in that tutorial there was a client UI implementation. I don't want to use UI. Instead of the UI, I want to use a websocket client extension in Chrome for sending and seeing messages.
All codes same with the tutorial(except the UI part since I'dont want UI), so I don't rewrite all codes here.
I am able to connect and send message to the url: ws://localhost:8081/gs-guide-websocket for example,
However, I can't get response with this url: ws://localhost:8081/topic/greetings. (I use this URL for getting responses by subscribing it. Because this topic/greetings path used in the UI side of that tutorial for subscription)
The Chrome extension that I used is Simple WebSocket Client.
Why I couldn't subscribe the ws://localhost:8081/topic/greetings url? and How can I get messages from the server by using the Chrome client websocket extensions?
Your application works with STOMP and SockJs, this plugin does not support that. It only works with ws. In this example, you can write a simple ws endpoint for your application:
example simple ws endpoint

How exactly Angular flows between Client and Server?

I was exploring about Angular 8 Recently and I am new to this technology. Here is what I understood..
You build your spring rest API project, and deploy that .war file on the web server (Like tomcat)
You build your Angular client application
.ts files will be translated to equivalent .js files
The build process create a 'dist' folder. The dist folder will have .js and .html files with angular tags and directives.
You deploy dist folder on a server where node.js is installed
You go to browser and ask for index.html file
Server sends all the files in the 'dist' folder to the client, up on initial request. We now have entire client app in the browser
For all the subsequent requests, the client app will make a webservcie call to spring app through Ajax requests
Javascript will use DOM to update the part of the page with new data.
For all this to work, browser must support angular directives and must also know how to render custom components
Please help me understand!
Via HttpCLient
Most front-end applications communicate with backend services over the
HTTP protocol. Modern browsers support two different APIs for making
HTTP requests: the XMLHttpRequest interface and the fetch() API.
The HttpClient in #angular/common/http offers a simplified client HTTP
API for Angular applications that rests on the XMLHttpRequest interface exposed by browsers.
In the example below, we are creating a post call, params for this post are the posted object, the url, and httpOptions(Headers, httpParms etc ...)
addHero (hero: Hero): Observable<Hero> {
return this.http.post<Hero>(this.heroesUrl, hero, httpOptions)
.pipe(
catchError(this.handleError('addHero', hero))
);
}
addHero (hero: Hero): Observable<Hero> {
return this.http.post<Hero>(this.heroesUrl, hero, httpOptions)
.pipe(
catchError(this.handleError('addHero', hero))
);
}
Just like when you post from Postman, you should configure your call with the right parameters.
You call should be in a Service that will be injected in application, module, or component.

How could detect if client close the connection on rails 4.2

I am working on an API application on Rails 4.2.0. Wonder if there any way I could tell if the client closes the connection after they made API call to the server.
Tried session and cookie, seems they do not design for it.
Every HTTP requests ends up being closed when it's complete, as that's how the HTTP request-response cycle works. It's extremely rare to have connections hanging open as long-polling fell out of style once WebSocket was standardized.
After the client has made a call you can assume that request has completed and they've disconnected. There's no way of knowing if they will make additional requests or not, it's entirely up to the client.
In response to your comment on what you are actually trying to do, the only way I can think of would be via javascript using onunload. Here is a very basic example.
<body onunload="handleOnClose()">
<script>
function handleOnClose()
{
// send something to your backend
}
</script>
</body>
For more info see this SO question

Fiddler not showing websocket protocol using ws prefix

I use fiddler to review many of the http and https communications from our application. We have a websocket implementation connected to a phoenix/elixir server using the ws prefix. So our url looks like ws://{ip}:4000/socket/websocket. None of the communications from our application to this end point are visible in Fiddler.
I can see all http and https traffic we're doing, but not the websocket calls. The websocket connections are working and the app is sending and receiving messages correctly, but I'd like to be able to see the messages to monitor this part of the application.
Any idea how to make the ws prefix visible in Fiddler?
Script Language C#
public static void OnWebSocketMessage(WebSocketMessage oMsg) {
// Log Message to the LOG tab
FiddlerObject.log(oMsg.ToString());
}
JScript.Net
static function OnWebSocketMessage(oMsg: WebSocketMessage) {
// Log Message to the LOG tab
FiddlerApplication.Log.LogString(oMsg.ToString());
}
add above code to FiddlerScript, you will see log on the fiddler log tab.
(Source)

Resources