I am attempting to implement a firefox extension which filters incoming HTTP responses and handles them accordingly.
I wish to block HTTP responses containing a specific header. Having read through some of the MDC articles, it appears the most common way of observing HTTP responses is by registering an http-on-examine-response observer.
My question is: Using this observer, is it possible to block the HTTP request from further processing (as a by-product, the page will continue to wait for a response)? Or do I need to use some other facet of XPCOM (if so, care to point me in the right direction)?
Thanks in advance,Mike
Should be possible: the "subject" of that notification is a HTTP channel, on which you can call nsIRequest::cancel().
the page will not continue to wait for a response, though, since you blocked the response. Perhaps you've been actually looking for a way to alter an HTTP response?
Related
I am trying to send GET HTTP requests to a paginated endpoint. The challenge is I do not know the page size beforehand therefore I have to send a request to get page number and interate till the end. I have tried Camel HTTP but I was not able to make it send dynamic requests based on first (or previous) response. I am currently testing recipientList to generate HTTP URLs by sending the first request and use the simple method as processor. Since Camel is really new for me, I am not sure if this is the best way to do like this.
I would be really grateful if someone could show some direction on this. Thank you
When I understood your question correct, you have to make an initial request to get the first page.
In the response you probably get the number of pages and then you want to get all remaining pages.
You could give the Camel Loop EIP a try for the remaining pages.
Pseudo-Route:
.from("whatever triggers the page retrieval")
.setHeader("currentPage", constant(1))
.to("http:target/page/1")
// dont know what you want to do with the pages
... continue processing of the first page
.setHeader("numberOfPages", simple("extract the number of pages somehow"))
.loopDoWhile(simple("${header.currentPage} <= ${header.numberOfPages}"))
.toD("http:target/page/${header.currentPage}")
// dont know what you want to do with the pages
... continue processing of the current page
.end
It really depends on what you need to do with the pages you retrieve. For example if you have to aggregate them, I am not sure if you can access an aggregated result from inside the loop.
If you are in a middle-ware that both receives the context and maybe append some data to context to send it to the next interceptor, then which of the two methods i.e. metadata.FromOutgoingContext and metadata.FromIncomingContext shall be called?
If you are writing that middle-ware in the server, then you are receiving that metadata in the incoming request.
You should then use metadata.FromIncomingContext to get the metadata at that point.
The metadata in the "outgoing context" is the one generated by the client when sending an outgoing request to the server.
See here for examples of both:
https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md
I use "github.com/streadway/amqp" for async processing requests via queue (RabbitMQ).
And I use "github.com/gorilla/rpc" to register my service without workaround, but I have to use ugly solution for conversion amqp.Delivery to http.Request (mux.Server can works with http.Request only).
Can I use more elegant solution for this task?
I can't find JSON RPC router for AMQP.
First, RPC and pub-sub (e.g. AMQP) are two very different beasts; trying to use one to implement the other isn't necessarily wrong or bad, but it's definitely suspicious, and implies that there could be a breakdown somewhere in the design. So I would highly recommend reconsidering the design starting with your business goals and make sure that what you're trying to implement is actually the correct way to achieve the desired functionality.
That said, what you're describing is basically possible, but you want to move your abstraction up a level. Trying to send a http.Request via AMQP is mixing protocols in a way that's only going to lead to more problems. The cleaner way to implement this behavior would be to have an HTTP handler that handles http.Requests (as normal), and a AMQP handler that handles amqp.Deliverys (as normal), and have each of those handlers call a shared business logic handler which deals only in your domain model.
So, your HTTP handler would parse an HTTP request and turn it into a domain object - you don't give any concrete details in the question so I'll invent something like maybe myapp.UserRegistration. Your HTTP handler would pass that to a myapp.UserService which would handle the actual business logic of registering a user, it would return a result, which you would then transform into the appropriate type, marshal to JSON, and send back to the client in an http.Response. myapp.UserService would know nothing about HTTP or AMQP; it operates only on your own domain types.
Your AMQP handler would pick up a message, parse it into the same myapp.UserRegistration type, pass it to the same myapp.UserService handler, and get the same response back - ensuring that the business logic for AMQP and HTTP behaves the same way. Then you'd get your response back, and... well, this is AMQP, so you don't get to send a response to the client. I don't know your setup, maybe you have another queue you can send the response back on, maybe you don't care about the response and can discard it. This is where the difference between RPC and AMQP is most apparent.
This also makes your business logic, HTTP handler, and AMQP handler more testable in isolation because you're separating the protocol logic from the business logic, which can be helpful even when you aren't trying to deal with multiple protocols (i.e. it's not a bad idea even if you're only doing HTTP)
I hope that at least gives you enough info to put you on the right track in your implementation. Good luck!
I've played with a number of the controller events but haven't been able to identify one that is called when redirect isn't. Also looked at cms_pageview, but theres no equivalent for all other page types. Is there an event called later in the stack that redirect doesn't trigger or a method for checking if a redirect was requested?
There are a lot of dynamic and generic events which you can consume; best to describe your needs.
Provided that the request is dispatched through the Front Controller, the response is sent in dispatch(), and that response may include a redirect header; you should be able to read the response object headers or status code to see if a redirect has been set.
if (Mage::app()->getResponse()->isRedirect()) {
//this will work assuming that the status code has been set
}
For more see Zend_Controller_Response_Abstract.
What are the strengths of GET over POST and vice versa when creating an ajax request? How do I know which I should use at any given time? Is it a security-minded decision?
Also, what is the difference in how they are actually sent?
GETs should be used for idempotent operations, that is operations that can be safely repeated more than once without changing anything. Browsers will cache GET requests (for normal and AJAX requests)
POSTs should be generally be used for non-idenpotent operations, like saving something. Although you can use them for other operations if you want.
Data for GETs is sent over the URL query string. Data for POSTs is sent separately. Some browsers have a maximum URL length (I think Internet Explorer is 2048 characters), and if the query string becomes too long you'll get an error.
You should use GET and POST requests in AJAX calls just as you would use GET and POST requests in normal calls. Basic rule of thumb:
Will the request modify anything in your Model?
YES: The request will modify (add/update/delete) data from your data store,
or in some other way change the state of the server (cause creation of
a file, for example). Use POST.
NO: The request will not affect the state of anything (database, file system,
sessions, ...) on the server, but merely retrieve information. Use GET.
POST requests are requests that you do not want to accidentally happen. GET requests are requests you are OK with happening by a user pointing a browser to via a URL.
GET requests can be repeated quite simply since their data is based in the URL itself.
You should think about AJAX requests like you think about regular form requests (and their GET and POST)
The Yahoo! Mail team found that when using XMLHttpRequest, POST is implemented in the browsers as a two-step process: sending the headers first, then sending data. So it's best to use GET, which only takes one TCP packet to send (unless you have a lot of cookies). The maximum URL length in IE is 2K, so if you send more than 2K data you might not be able to use GET.
http://developer.yahoo.com/performance/rules.html#ajax_get