how to get request header and response header by webkitGTK - webkit

I want to get the request header before the webkitGTK begin to send request and load the page. Then I want to get the response headers. However, I don't find such API in webkitGTK.

In Webkit1 the signal you want is WebKitWebView::resource-request-starting: The request argument contains a WebKitNetworkRequest which has a SoupMessage which will allow you to modify the request headers. The same signal has resource argument which has a response-received which in turn will contain a WebKitNetworkResponse. The SoupMessage of that response will have the response headers you want.
In Webkit2GTK the WebKitWebView::resource-load-started should be useful for at least monitoring: request and resource arguments work almost like the WebKit1 versions. The bit that I'm not 100% sure about is whether you can modify the request headers here -- or if you have to implement a WebExtension and use the WebKitWebPage::send-request signal.

Related

HTTP response body for server command request

I am solving one question with my team about REST API specification.
We have a case where in some requests we are sending only some particular command via HTTP request for example : We are using POST (now considering PATCH request) to endpoint : /server/startSomeOperation . Backend developers told us that this request is only telling hardware to start some functionality on backend that affects the measurement of the user but it really has nothing to return. My question is :
Should we (according to some REST API specification) always return body of such a request when we know that no additional returned data will be needed except HTTP status code? Until now we were strictly following the rule that every request needs to have some sort of body returned but until now every body response even when it was a command to a server made sense.
Should we (according to some REST API specification) always return body of such a request when we know that no additional returned data will be needed except HTTP status code?
No - it is perfectly fine to send a 204 No Content or a 205 Reset Content when the semantics of your response is well aligned with the standard meaning of those codes.
You also have the option of declaring that the "representation of the status of, or results obtained from, the action" is zero bytes long, in which case you could use a 200 OK with a Content-Length header.

can resolveWithFullResponse: true make response heavier network-wise?

https://github.com/request/request-promise
I want to measure and possibly minimise the payload of response.
So I want to get content-length header. I will not get header unles i specify resolveWithFullResponse to request. The question is, how it works, in detail? Can it make server response larger in terms of network load?
When i get specific page with browser, i got different (3 times smaller, in my case) content-length header value, compared to getting the same page with request-promise with resolveWithFullResponse: true.
So is request-promise just trim response it gets, if you do not specify resoveWithFullResponse, or it requests more data in case it is set?
resolveWithFullResponse just means that instead of receiving the response body in your .then, you'll receive the full IncomingMessage object for the response, with all the headers, status codes, and other attached information instead.
It does not affect the network request being made.

Sending GET request parameters in body

I have an API which accepts many parameters.
Passing the values of the parameters will exceed the length of the URL Header.
I am using Postman client to pass the parameters in the body but this is not working any ideas on how to make this work.
The API accepts many parameters because the backend is legacy and is exposed as an API by a service bus.
Older versions of Postman didn't allow you to send body data with get request.
Yet, if your server receives data as URL parameters you won't be able just to change the way of sending them and include them to the body (server won't accept them).
So if the length of parameters is indeed so big and the server indeed can receive the same data from body instead of from parameters then the Postman is just not the tool that you can use (maybe cURL is for you).
If your server allows to send data only as URL parameters and they are so long (more then 2000 chars What is the maximum length of a URL in different browsers?) then I think you have no chances to test this API.
UPDATE: new Version 7.20.1 now allows to send Body with GET request
Workaround:
Change the request type to POST.
Set the value of your body
Change request type to GET
Send request and the body is included
Postman is already added this feature of sending body in get
request.
But i still i recommended to go for post request (if body is present) since many projects like angular http client does't have updated protocols yet.
Latest Postman supports body object for Get request
just choose json format as shown in pic above
If you want to make a GET request in Postman then you can use Params or Body to pass parameters, but not both. Either Params only or Body only. If you specify both Params and Body, Postman will select and send only Params (in GET request of course). So if you want it to send Body, clear Params.

Restangular: How to get HTTP response header?

I have a REST server which returns a Link HTTP header with a response to a PUT to indicate the URL of the newly-created entity:
Link:<entities/6>; rel="created"
Is there any possibility to read that link header with Restangular?
The only facility to intercept HTTP requests with Restangular I've met so far is to register a response interceptor in the app config:
restangular.addResponseInterceptor(function (data, operation, what, url, response, deferred) {
console.log(response.headers())
return response.data;
});
However, with above demo implementation in place, the only HTTP header which gets logged is content-type. Still, I can see in the browser development toolbar that a response comes indeed with many additional HTTP response headers, such as Server, Date, and the aforementioned Link.
Why do I not have access to the full array of HTTP response headers through addResponseInterceptor()? Is there any way to capture the HTTP response header in question using Restangular?
Note: I don't search for an answer using HAL or any other special response body format. I would rather like to know whether I can use plain HTTP headers with Restangular or not (if not, I will probably resort to HAL or something).
You don't need a ResponseInterceptor to do this. You just need to set fullResponse to true to get the whole response (including the http headers) every time you do any request.
Restangular.setFullResponse(true);
You can set it globally in your app configuration. Something like this:
angular.module('YourApp')
.config(['RestangularProvider',
function (RestangularProvider) {
RestangularProvider.setFullResponse(true);
...
Then, every time you receive a response, you can access all the response headers.
Restangular.all('users').getList().then(function(response) {
$scope.users = response.data;
console.log(response.headers);
}
Example:
response.headers('Link')
NOTE: Be careful because using fullResponse, the response data is located in response.data, not directly in response.
EDIT: As #STEVER points, you also need to expose the headers in your server API.
Example:
Access-Control-Expose-Headers: Link
You can get more detailed information in Restangular documentation
Hope it helps.

How to set a header (specifically cookie) in the response of a Worklight Adapter Procedure

It's obvious how to set headers accessing a backend system via invokeHttp method, but I can't for the life of my find a way to write a cookie or even write a response header in the response back from the adapter procedure. I'd like to be able to write a Set-Cookie header in the HTTP response back to the client. I also want this to be a true HTTP header, not just part of the JSON body.
This is currently not possible in Worklight. We do have a feature request for it, though, so it may happen some day...
Feel free to add an additional feature request to highlight the need for it: http://www.ibm.com/developerworks/rfe/