I am trying to set up an event stream using MVC.NET, Nginx and Fastcgi. The streaming works fine for me using xsp4, but I have not been able to get it to work through Nginx and Fastcgi. My goal is to open an EventSource stream and to downstream data to my website.
I have tried adding the 'ngx_http_upstream_keepalive' module - http://wiki.nginx.org/HttpUpstreamKeepaliveModule - which is funny because there is "Note - this This will not work with HTTP upstreams" in the module description. But wait, isn't that the name of the module? Anyways, maybe I'm confused here. I have also tried adding 'proxy_buffering off' to my nginx.conf, which also hasn't helped.
I understand this should be fairly easy to do, but I am at a loss. Is there some property I can add to my nginx.conf to make this work? Or is there something to add to the Response in .NET?
Please help me StackOverflow!
Based on what I have read here:
http://wiki.nginx.org/X-accel
you need to turn off X-Accel-Buffering. Here is some example code:
public ActionResult Stream(string id)
{
Response.ContentType = "text/event-stream";
Response.Buffer = false;
Response.BufferOutput = false;
Response.Headers["X-Accel-Buffering"] = "no";
return View();
}
Hopefully the code above fixes your problem.
Related
I have a simple Dart HTTPServer running which serves requests by virDir.serveRequest(request); which works for the URL 192.168.1.200:8080/index.html but serves a 404 Not Found if I use 192.168.1.200:8080 or 192.168.1.200:8080/. I, probably naively, though that the default was automatic. BTW this is all new to me.
I didn't notice any default settings in HTMLServer, how is this accomplished?
(edit)
I've been able to detect the use using the default and compute the correct file name but don't understand how to deliver it to the browser:
_processRequest(newPath, request) { // new path is index.html
File file = new File(newPath);
file.exists().then((found) {
if(found) {
file.openRead().pipe(request.response); // probably dies here
}
else {
_send404(request.response);
}
});
}
[edit]
Still unable to serve the index.html file. I've tried using VirtualDirector.serveFile() but can't make it work when I try to handle the default index.html file. I've been attempting to follow an example.
final HTTP_ROOT_PATH = Platform.script.resolve('../web').toFilePath();
final virDir = new VirtualDirectory(HTTP_ROOT_PATH)
..jailRoot = false // process links will work
..followLinks = true
..allowDirectoryListing = true;
var dir = new Directory(virDir.root);
var indexUri = new Uri.file(dir.path).resolve('/index.html');
virDir.serveFile(new File(indexUri.toFilePath()), request);
When I run this and print indexUri.toFilePath() the output is '/index.html'
My code is in /srv/fireimager/bin and /srv/fireimager/web with the latter the virtual directory root. When I detect that the user has not specified /index.html in the url it doesn't work, there's no error emitted, and the javascript console shows nothing so nothing is served to the browser.
I obviously don't understand how to use VirtualDirectly.serveFiler.
Your default page or index.html is not assumed by your browser but by the server.
What you will want to do is check to see what your request ends with. In my server, I check to see if it ends with a "/". If it does end with a "/", I open and send my default page.
Also, you will want to make sure you check your request to make sure it's not trying to access areas it it not suppose to. Check for ".." in your path segments. If you have any, you probably want to kill the connection.
FileHelperEngine engine = new FileHelperEngine(typeof(OrderCsvRow));
var writer = new StreamWriter(Response.OutputStream);
engine.WriteStream(writer, someOrders);
When I output the orders as a string it comes out fine. when I use Response.OutputSteam as in the code snipped the response it truncated towards the end - always at the same place.
How do I fix this?
Fixed...
engine.WriteStream(Response.Output, someOrders);
Had a similar issue here, so I'll put down the solution I found for anyone else who comes by and needs it.
Source: https://bytes.com/topic/asp-net/answers/484628-response-outputstream-truncates-xmltextwriter
After doing your write, make sure you also flush your stream writer before completing the request. Otherwise the missing data might end up being left behind and not actually appended to the OutputStream. :)
I'm new to breeze.js and I'm having a little trouble coming up with a good way to combine executeQuery and executeQueryLocally.
The use case is this: I want to use breeze data caching to hide the flakiness of a 3rd party web service. I'd like to come up with a pattern that queries the service and falls back to the cache if the service is unavailable when called.
I've been chewing on this for a couple of days now - any suggestions or advice would be appreciated!
I think that this solution can be a good way:
executeQuery= function(query){
operating(true);
return manager.executeQuery(query).fail(fail);
function fail(error){
//You can decide if you want to query locally depending on the type of error
//Example: if(error.status===404) ;
return executeQueryLocally(query);
}
}
executeQueryLocally= function(query){
return manager.executeQuery(query).using(FetchStrategy.FromLocalCache).fail(fail);
function fail(error){
//You can't get the information, so you can throw an error
//Or that you want
throw Error('Impossible to get the requested data');
}
}
//Example calling this methods
var getCustomers= function(resultArrayObservable,inlineCountObservable){
var query = new breeze.EntityQuery("Customers").inlineCount(true);
return executeQuery(query).then(success);
function success(data){
inlineCountObservable(data.inlineCount);
resultArrayObservable(standarizeCustomerDtos(mapCustomerDtosToKos(data.results)));
}
};
With this solution I have tried to to do easy to check in every query if it is something that is going wrong and not to repeat code.
I hope this can help you.
How can I print a map from the OpenLayers? I want to add print button in my OpenLayers page =) I have MapFish extension for my geoserver, but don`t know how to make request to it. Any other ideas are welcome) Help please.
I had a similar problem using a reverse proxy, because I discovered the answer from info.json contais local ip reference instead of the public url
to solve brutally i replaced the ip referenze with the public url in the ajax request (see the following code. I hope it can be usefull for others...
this.capabilities.createURL = this.capabilities.createURL.replaceAll("192.168.0.0:8080", "mypublicurl");
this.capabilities.printURL= this.capabilities.printURL.replaceAll("192.168.0.0:8080", "mypublicurl");
Ext.Ajax.request({
url:this.capabilities.createURL,
jsonData:jsonData,
success:function(response){
response.responseText = response.responseText.replaceAll("192.168.0.0:8080", "mypublicurl");
window.open(Ext.decode(response.responseText).getURL);
}
});
The simplest way is to use GeoExt.PrintMapPanel (geoext example). And be sure to read GeoServer Printing Module.
UPD GET request example. You must modify url, "baseURL", "layers". If you specify an existing layer, this request must return pdf file.
http://demo.opengeo.org/geoserver/pdf/print.pdf?spec={"units":"degrees","srs":"EPSG:4326","layout":"A4","dpi":75,"mapTitle":"Printing Demo","comment":"This is a simple map printed from GeoExt.","layers":[{"baseURL":"http://demo.opengeo.org/geoserver/wms","opacity":1,"singleTile":true,"type":"WMS","layers":["topp:tasmania_state_boundaries"],"format":"image/jpeg","styles":[""]}],"pages":[{"center":[146.56000000001,-41.56],"scale":8192000,"rotation":0}]}
What is the difference between:
Msxml2.DOMDocument
Msxml2.XMLHTTP
? And of course, the other question is which one will work best for my purpose as described below?
The context is this - I have code that makes many calls to retrieve web pages. I am looking for the most efficient object for this task. For example, something like this:
Dim oXmlHttp : Set oXmlHttp = CreateObject("MSXML2.XMLHTTP")
oXmlHttp.Open "GET", sUri, False
oXmlHttp.Send
If Err Then
getWebPage = "ERROR - could not get the source text of the webpage."
Exit Function
End If
sResponse = oXmlHttp.responseBody
This seems to work the same way if I create an object using:
Dim oXmlHttp : Set oXmlHttp = CreateObject("MSXML2.XMLHTTP")
Can anyone explain or point me to a reference that clearly outlines the differences (and intended usages) for each of those?
If you want to learn more about MSXML, these links may help:
http://msdn.microsoft.com/en-us/library/aa468547.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms766487(v=vs.85).aspx
In short, XMLHTTP is used to retrieve information, while DOMDocument is used to structure and parse it.
This page explains it better: http://msdn.microsoft.com/en-us/library/windows/desktop/ms760218(v=vs.85).aspx
DOMDocument "Represents the top node of the XML DOM tree." while XMLHTTP "Provides client-side protocol support for communication with HTTP servers."