Laravel 5 get response header - laravel-5

I need to get the Http response Link Header from a Shopify orders http request. Unfortunately, the application is still using Laravel 5.1 and not the latest version.
(I believe) The call is being made using Custom HTTP Requests with some docs on this page:
https://laravel.com/docs/5.1/testing
This is the call being made that returns order data but no other info.
$this->shopifyApiCreds->call($params)
This returns a response variable, but I do not know how to return any headers from this response.
Thanks!

Related

How to remove request body from subsequent requests in JMeter

I tried to create a test script in JMeter where I log in by using API. I created a test script by BlazeMeter chrome extension.
Some of my API calls fail because I am getting CloudFront error. I found out the issue is that GET requests contain a request body. GET requests cannot contain a request body on CloudFront. When I tried the same get requests in postman without request body, I didn't get any errors. I got the same error in postman if I added a body request. This way I can confirm this is the issue.
I am looking for a way how to remove body request from subsequent GET requests in JMeter to get rid of this error.
This is the original API call (sampler) with POST login api request:
After the POST request there is a redirection to a page that makes other GET api calls to fetch static files such js files, etc. The problem is that these GET requests also contain the same request body as the original POST call.
As you can see I can fetch statis files if I remove body request:
I tried to add preprocessor and postprocessor for original POST request, but I don't know how to access subsequent GET requests. I can access only original POST request:
Is there a filter or a way how to remove body request from GET requests?
I don't think it's possible, at least not with JMeter 5.5
If you take a look at HTTPSamplerBase source code you will see that the request body is being copied fully from the original HTTP Request sampler:
this.sampler = (HTTPSamplerBase) base.clone();
So the options are in:
Raise an enhancement requests via JMeter Github Issues
Amend HTTPSamplerBase code to remove the request data from generated AsyncSamples
Handle embedded resources download manually using Parallel Controller

Intercept HTTP Request in page

I am trying to make a scraper for a page of a supermarket. I noticed that this supermarket make API HTTP calls via AJAX, and if I enter to Inspect > Network then I can see the request headers of the calls I need.
Inside the requests headers there is an X-Token. If I use this X-Token with the URL via Postman I can get all the info in JSON format, which is better than scraping the web.
The problem is that this X-Token expires (I think, it still works). Is there any possibility to make a call to the page and "intercept" this API call in order to retrieve this X-Token and use it for the next custom requests?
I'am using Ruby on Rails :)

Update a Google Sheet Using HTTP Request in Postman

I have a server needing to update a shared Google Sheet. It generates special tokens for offline use so doesn't work with PHP quickstart module.
I am trying to setup request in Postman for this action:
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update
But get the following result:
Is it possible to use HTTP for this API?
Turns out I had to add ?valueInputOption=RAW on the end of my URL request and removed valueInputOption from the request body JSON.
The valueInputOption should be passed as params to the POST URL, it should not be in the request body.
Also the sheetID and the range should be sent in the URL.
I suppose it should be a POST call not PUT.

Getting the URL from the ajax response using EmberJS

Can anyone help me in how to get the url, from the Ajax response in Ember.
This is to handle a specific use case in which server redirects to another url and returns data from the new url(302 redirect).
If i am able to get the url form the response, then i can check if the requested url is different from the response url and can take the action accordingly.
Note: If we use Angular (tried with Angular4), then we can get the response details including url and header from the response, if you use Http service from '#angular/http'
I am using following config for EmberJS
-ember-cli: 2.14.2
-node: 8.1.0
-os: darwin x64
In comment you specified that you fetch the record using Ember.$.ajax. Ember.$ is not more than an alias for jQuery. So Ember.$.ajax is the same as jQuery.ajax. Following jQuery.ajax documentation success function is called with jqXHR object as third argument. This is a superset of browsers native XMLHttpRequest object. XMLHttpRequest object provides a read-only property responseURL which is what you are looking for.
In general I would recommend to not use jQuery.ajax in modern ember application. There are two great alternatives:
ember-fetch provides a HTML5 fetch polyfill from github wrapped and bundled for ember-cli.
ember-ajax provides a service for making AJAX requests which provides RSVP promises.
There is also work ongoing to migrate away from jQuery.ajax in ember-data.

Unable to add custom header to response

I am unable to add a custom header to a response that is returned from render():
response = render(request, 'my_template.html', {'ctx1': 1, 'ctx2': 2})
response['My-Custom-Header'] = 'abc12345'
return response
This is a response to an Ajax request initiated using jQuery's $.get(). On Chrome, the response has the template rendered properly, but it does not have the custom header. If I print the response object before returning, I see that it has my custom header.
I thought the issue was because of this answer, so I added Django middleware to add a header to all responses:
class CustomHeaderMiddleware():
def process_response(self, request, response):
response['Access-Control-Expose-Headers'] = 'My-Custom-Header'
return response
All my responses now have header Access-Control-Expose-Headers: My-Custom-Header, but I still see this issue.
My request is local; I'm using the Django development web server.
If I send a non-Ajax GET request, whatever custom header I add in Django is visible in the response on Chrome. So this issue seems to be limited to Ajax requests.
I am using Django 1.11.4 and Python2.
[edit]
If I capture the response in WireShark, I see that it does not have My-Custom-Header. Furthermore, if I add a custom header to the response dictionary in the above middleware, the header shows up in Wireshark and is visible in Chrome. So this seems to be a Django issue with responses to Ajax requests.
This issue is unrelated to Ajax. I was calling my view using this template tag. The custom response headers are lost because of line 32 in that code.

Resources