Get the OS/Platform in Nancy - nancy

Is there an equivalent of the 'Platform' in Nancyfx?
In as asp.net I can do the following:
Request.Browser.Platform

Nothing out of the box right now, but you have access to the headers so you could parse it out of it yourself.
You should parse the User-Agent HTTP header that you can read from Request.Headers["User-Agent"] .. you could add an extension method for it, or on Request
If you create something reusable then please consider contirbuting it back to the framework
Thanks!

Related

What is the best way to route to different controllers in CakePHP depending on HTTP header values?

I'm looking for a way to route URLs to different controllers depending on the value of the HTTP 'Accept' header.
All I have found so far is the official CakePHP documentation on routes but it is not very detailled.
Is this possible using route configurations or do I have to do this another way (e.g. by implementing a DispatcherFilter to inspect the CakeRequest)?
I want a set-up where I can seamlessly distribute responsibilities
between server side and client side: e.g. letting the client handle
the view creation instead of the server responding with an HTML
document.
Guess you're using something like AngularJS? Well, then you expect a data format back instead of HTML I guess. So request application/json via the accept header and / or the extension. Cake can detect both and respond accordingly.
Read about JSON and XML views in the manual.
http://book.cakephp.org/2.0/en/views/json-and-xml-views.html

FiddlerCore autoresponder

I'm trying to use fiddlercore for vb.net. I'm trying to redirect a url to a different one as how the auto responder would work. So basically Id do something like if uri.contains(".ashx") redirect traffic too (".png") If that makes any sense
I fixed it by reading up on the documentation some more.

extjs 4 rest proxy and zend 2 restful controller

I want to post data to Zend 2 restful controller from EXTJS 4 rest proxy.
But when I inspect with the firebug I found that there is the post data ,but I am not able to fetch that data .How to get that post data to use it in my methods.
Where I am getting wrong I cant figure it out.
Anyone having steps to post data from rest Extjs 4 proxy method to Zend?
The standard way in PHP to load JSON from the HTTP Request Body is to use
$some_json = file_get_contents('php://input');
$some_object = json_decode($some_json);
I don't know whether Zend2 has their own way of doing it.
ExtJS send params like sort, page, filter, etc. into the URL, e.g.: http://myhost.com/?page=2&sort=myfield.
In this case you simply need to intercept the query params from your RESTController Action:
$page = $this->params()->fromQuery('page');
$sort = $this->params()->fromQuery('sort');
Data transmission to a ZF2 REST controller depends on the HTTP Method you are using:
GET, PUT, DELETE receives an $id argument;
POST used to create a new record and receives a $data argument.
For further information you can have a look in here:
http://framework.zend.com/manual/current/en/modules/zend.mvc.controllers.html#the-abstractrestfulcontroller
If you are interested, I am developing my REST proxy for Sencha, I have tested with ExtJS and Sencha Touch frameworks and it supports pagination, remote filters, remote sorting and so on.
It's developed with Zend Framework 2 and may support different DB types on the same installation. Have a look at:
http://apiskeleton.asaconsult.com/
I have exactly the same problem. Now, the reasons why the previous replies don´t work is because Zend Studio 10 has a new feature for configuring REST services from a visual editor that receives parameters and creates routes. This service designer is actually accepting the parameters form the body for the POST action of the Restful service but it somehow ignores the JSon sent from ExtJS. To make things worse, if you test the service using the integrated GUI in Zend Studio 10 it works perfectly and the JSon produced is 100% the same as the one from ExtJS ( I actually performed some data transforms to get to that point ), and it doesn't work.
The real issue is that there is 'something' within the POST method that is different in the ExtJS Request, than the JSon being expected from the framework itself that abstracts the code for deserializing this JSon from the developer.
The real question is, What is the Zend Server Gateway library expecting that ExtJS is sending in a different way in the POST body? I would enormously appreciate if any of the thousands of experts here could please check that out and come with a correct answer. The one that will answer this will have to have or to download a trial of Zend Studio 10 and check for himself how the Visual Service Tool that comes with ZS10 works. I have found so far that ExtJS4 produces it´s JSon like this:
{"data":
{"IdCurso":"0","Nombre":"NodeJS","IdEstadoCurso":"1",
"IdTipoPeriodo":"1","CantPeriodo":"1","CantAsignatura":"1","IdPlantel":"1"}
}
And the Zend GUI for testing the service, produces (and the service accepts) JSon like this:
{
'data' : '{"Nombre":"NodeJS","IdEstadoCurso":"1","IdTipoPeriodo":"1","CantPeriodo":"1","CantAsignatura":"1","IdPlantel":"1","IdCurso":"0"}'
}
As you can see data is enclosed on single quotes, and its content is as well for Zend Framework to consume it without issue. ExtJS uses double quotes, as well as is not quoting the content of the data package itself.
This is a Patch that actually works, Not the definitive solution, if somebody finds a better one, that would be great.
Try this as the first instruction in your add() (POST) method:
$data = json_decode($this->getRequest()->getContent());
You may need to add afer that:
$data = (array) $data;
After that, keep writing your code with the $data variable normally as you would do if the parameter would actually work.

Is there anything wrong with using html files without the ".html" extension?

I was wondering if there is anything wrong with using html and php files without extensions.
For example, if I was to upload a file with an extension, I would get to by using a URL like this:
http://yoursite.com/randompage.html
If I used a file without an extension, I would use a URL like this:
http://yoursite.com/randompage
I know that this can't be the preferred method because it leaves the file without a way to be identified, but is there anything that would stop the site from working properly?
What you want to do is done with url-rewriting .
Basically, you will add a rewrite rule to your web server, so when he receives a request for url yoursite.com/randompage he will change it to yoursite.com/randompage.html. You will find a lot of examples on the web if you google for "mod_rewrite examples" or "url rewrite examples".
Document types are sent from the webserver in http headers, so it is perfectly possible to do what you are asking.
For instance when using Apache, to tell it that any file with no extension is html, in the 'conf' file you can say:
DefaultType text/html
More details at Apache The Definitive Guide
This point to concrete document (randompage.html in this case):
http://yoursite.com/randompage.html
This point to default document in directory:
http://yoursite.com/randompage/
Default document is set in you webserver. This could be for example: index.html, default.html, index.php, default.apsx,...

Embedding bugzilla reports

I am trying to find a way to embed bugzilla's tabular reports in another HTML document. Does anyone know a way to do this? All embedding must happen client-side. I don't have access to backend web server to implement parsing/inlining of contenting. I figure, I could use an iframe, but i haven't found a way to tell bugzilla not to emit its standard header and footer.
Does anyone have experience embedding bugzilla reports into an HTML document on the client side?
Here is an example report... https://bugs.eclipse.org/bugs/report.cgi?x_axis_field=bug_status&y_axis_field=bug_severity&z_axis_field=&query_format=report-table&short_desc_type=allwordssubstr&short_desc=&classification=Technology&product=Sapphire&target_milestone=0.3&longdesc_type=allwordssubstr&longdesc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&status_whiteboard_type=allwordssubstr&status_whiteboard=&keywords_type=allwords&keywords=&emailtype1=substring&email1=&emailtype2=substring&email2=&bug_id_type=anyexact&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&format=table&action=wrap&field0-0-0=noop&type0-0-0=noop&value0-0-0=
You want the &format=simple parameter on your buglist request, e.g.:
https://bugzilla.mozilla.org/buglist.cgi?bug_id=1000,1001,1002&format=simple
Put a URL like that (to your Bugzilla, naturally) in the src attribute of an <iframe>.
Gerv
A little javascript to request the html and enough parsing to find the right snippet might be your only option.
http://ejohn.org/blog/pure-javascript-html-parser/ might be a good parsing option.

Resources