Can i create a rewrite in Charles Proxy so there is no response given - charles-proxy

I want to fake the response to a call by having no response at all, instead of whatever the target is returning. (as if the IP i was calling to does not exist at all). Is this possible using Charles Proxy?

You can use rewrite and change status of the response from 200 to 404.

Related

How to mock HTTP Error response with Charles?

Is it possible to intercept the request going through Charles and immediately return 500 error code without sending this request to the server?
Can't find any information on this. All resources suggest to wait for the response and then change HTTP response code to 500.
I assume you have already tried adding a rewrite rule to make the request to be returned with the 500 status. Have you tried combining this with a map local, to an empty file on your disk, for instance? It may work.
If this doesn't work too, I think I would do a Map Remote to another path on my localhost (for instance: http://localhost:8081/exected-response-500) and make that URL to return the 500 status error (in my case I would use a basic Spring Boot app to achieve this).

How can I configure nghttpd to response differently based on the request?

When I start a server with
nghttpd --no-tls -v 8444
And in another terminal I send a request
nghttp -v -y http://127.0.0.1:8444
I see that the server saw my request and responded with 404. Is it possible to configure to respond differently based on the request? (I 'd like to implement some basic logic, different return codes based on request method, path) Can you show me an example for that?
Lets say for GET request with /dog path return 200, and to post request return 404
I don't think this is possible. Nghttpd is a simple webserver to demonstrate the nghttp library and also useful for debugging HTTP/2, but it is not intended as a fully featured web server.
As an aside, I would also question whether a POST should return 404 to a valid path. 404 is "Not Found" which is not right - the resource is found. Most web servers would return the same as a GET request for such a request (as does nghttpd).

Charles Map local - Ignore initial request of same URL with OPTIONS method and map second with GET request

I am trying to stub out a request locally with a response saved within a local file. This is working fine however I need to get to ignore an initial request of the same URL but with a Method type of Options.
The problem is, the local mapping is being mapped to this request instead of the Intended GET request which leads to an error. Is There away way I can specify something extra so the initial options request which comes back is ignored.
Example image
Hope this clear enough
Thanks.
It's a limitation of Charles, that doesn't allow you to specify the matching HTTP Method.
I suggest using other tools like Proxyman, that you can define which Method you need for the Map Local Tool. You can map entire Response HTTP Message (Includes Header and Status Code as well)

HTTP 303 See Other - Content

If I want to return a status code of 303 See Other when a client POSTs data that already exists, am I allowed to return that data in the content (body) of the response (in addition to setting Location), or must the client then GET the Location?
I would like to avoid requiring the client HTTP to make two HTTP calls if at all possible.
Idiomatically, the client should retrieve the data with a GET request.

Can I change the headers of the HTTP request sent by the browser?

I'm looking into a restful design and would like to use the HTTP methods (POST, GET, ...) and HTTP headers as much as possible. I already found out that the HTTP methods PUT and DELETE are not supported from the browser.
Now I'm looking to get different representations of the same resource and would like to do this by changing the Accept header of the request. Depending on this Accept header, the server can serve a different view on the same resource.
Problem is that I didn't find a way to tell my browser to change this header.
The <a..> tag has a type attribute, that can have a mime type, looked like a good candidate but the header was still the browser default (in Firefox it can be changed in about:config with the network.http.accept.default key).
I would partially disagree with Milan's suggestion of embedding the requested representation in the URI.
If anyhow possible, URIs should only be used for addressing resources and not for tunneling HTTP methods/verbs. Eventually, specific business action (edit, lock, etc.) could be embedded in the URI if create (POST) or update (PUT) alone do not serve the purpose:
POST http://shonzilla.com/orders/08/165;edit
In the case of requesting a particular representation in URI you would need to disrupt your URI design eventually making it uglier, mixing two distinct REST concepts in the same place (i.e. URI) and making it harder to generically process requests on the server-side. What Milan is suggesting and many are doing the same, incl. Flickr, is exactly this.
Instead, a more RESTful approach would be using a separate place to encode preferred representation by using Accept HTTP header which is used for content negotiation where client tells to the server which content types it can handle/process and server tries to fulfill client's request. This approach is a part of HTTP 1.1 standard, software compliant and supported by web browsers as well.
Compare this:
GET /orders/08/165.xml HTTP/1.1
or
GET /orders/08/165&format=xml HTTP/1.1
to this:
GET /orders/08/165 HTTP/1.1
Accept: application/xml
From a web browser you can request any content type by using setRequestHeader method of XMLHttpRequest object. For example:
function getOrder(year, yearlyOrderId, contentType) {
var client = new XMLHttpRequest();
client.open("GET", "/order/" + year + "/" + yearlyOrderId);
client.setRequestHeader("Accept", contentType);
client.send(orderDetails);
}
To sum it up: the address, i.e. the URI of a resource should be independent of its representation and XMLHttpRequest.setRequestHeader method allows you to request any representation using the Accept HTTP header.
Cheers!
Shonzilla
I was looking to do exactly the same thing (RESTful web service), and I stumbled upon this firefox addon, which lets you modify the accept headers (actually, any request headers) for requests. It works perfectly.
https://addons.mozilla.org/en-US/firefox/addon/967/
I don't think it's possible to do it in the way you are trying to do it.
Indication of the accepted data format is usually done through adding the extension to the resource name. So, if you have resource like
/resources/resource
and GET /resources/resource returns its HTML representation, to indicate that you want its XML representation instead, you can use following pattern:
/resources/resource.xml
You have to do the accepted content type determination magic on the server side, then.
Or use Javascript as James suggests.
ModHeader extension for Google Chrome, is also a good option. You can just set the Headers you want and just enter the URL in the browser, it will automatically take the headers from the extension when you hit the url. Only thing is, it will send headers for each and every URL you will hit so you have to disable or delete it after use.
Use some javascript!
xmlhttp=new XMLHttpRequest();
xmlhttp.open('PUT',http://www.mydomain.org/documents/standards/browsers/supportlist)
xmlhttp.send("page content goes here");