I want to modify custom request headers for page-data.json in Gatsby react framework. Specifically I want to set custom request header of cache-control to cache-control: public, max-age=0, must-revalidate. Is there a way to do this?
To set custom headers
Sign in to the AWS Management Console and open the Amplify Console.
In the navigation pane, choose the app to set custom headers for.
Choose App settings > Custom headers.
In Custom header specification, choose Edit and add below code and click Save.
customHeaders:
- pattern: 'page-data.json'
headers:
- key: 'cache-control'
value: 'public, max-age=0, must-revalidate'
Related
I want to use HERE maps autocomplete in my project.
But when a i send request like the one in documentation
this.axios.get('http://autocomplete.geocoder.api.here.com/6.2/suggest.json
?app_id={YOUR_APP_ID}
&app_code={YOUR_APP_CODE}
&query=Pariser+1+Berl
&beginHighlight=<b>
&endHighlight=</b>'
)
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error)
})
i get an error
OPTIONS http://autocomplete.geocoder.api.here.com/6.2/suggest.json?{...} 405
Access to XMLHttpRequest at 'http://autocomplete.geocoder.api.here.com/6.2/suggest.json?{...}' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
In Chrome developer console in network panel i check this
Provisional headers are shown
Access-Control-Request-Headers: x-auth-token, content-type
Access-Control-Request-Method: GET
I set content-type in request headers to application/json and Provisional headers changed
to Access-Control-Request-Headers: x-auth-token
Access-Control-Request-Method: GET
So if i understand right, i should set x-auth-token header. But where can i take this token?
Or may be this problem has another reason?
There's nothing about such problems in documentaion.
The problem was simple and a bit stupid.
When user authenticated in my app I added default header to axios
axios.defaults.headers.common['X-Auth-Token'] = token
so this header was sended to all requests.
But HERE-map API doesn't want this header in requests and this was the cause of the problem.
The solution was to remove this header from requests to HERE-map API.
For those who have defined by default the header :
'Content-Type': 'application/json'
You must deactivate it, there should not be any HttpHeaders on the call request to Here API services.
temporary install Allow-Control-Allow-Origin google chrome plugin .. installed then you can show top right side click on that and switch the button then refresh then again call your api and get the response.
I'm using Restangular. I would like to get full response so I set
Restangular.setFullResponse(true);
but then I discovered that my custom headers does not work. Documentation for setFullResponse() method says:
in order for Restangular to access custom HTTP headers, your server must respond having the Access-Control-Expose-Headers: set.
I would like to send my custom headers but I don't want to change server settings. Is it possible?
If I leave default settings i.e.setFullResponse(false) there is no issue with custom headers. Is there another solution except changing server settings?
The sentence you cite from the setFullResponse() docs is about what headers from the response your Restangular app will be able to access. And what that is saying is, it’s not possible to access most of the headers from the response unless the server’s already configured to send the right response-header names in the Access-Control-Expose-Headers header.
Without the server setting any value for that header, the only response headers that browsers will let you access from client-side JavaScript in your web app are the Cache-Control,
Content-Language,
Content-Type,
Expires,
Last-Modified
&
Pragma response headers.
See https://fetch.spec.whatwg.org/#cors-safelisted-response-header-name for the spec on that.
I would like to send my custom headers but I don't want to change server settings. Is it possible?
If you mean you want to send custom headers in a request from your client-side Restangular code to the server, please provide more details about exactly which custom headers you want to send.
There too though, there’s another CORS header your server must send in the response: the Access-Control-Allow-Headers response header. If the server isn’t configured to send that with the right header names listed, then your request will fail. The reason in that case is, you will hit https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests.
I'm using Asp.Net Core RC2 and Kestrel as my web server. I need to ensure that requests (in this case all of them) are responded to with a no-cache header so that the browsers get the newest version (not 304).
Is there a way in Startup to configure Kestrel or a way to inject this step into the pipeline?
EDIT: no-store may be a better choice in my situation: https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching "no-store Response is not allowed to be cached and must be fetched in full on every request."
You can use middleware to work with headers. For example, you can force no-cache cache-control by adding the following to the top of your Startup's Configure method:
app.Use(async (httpContext, next) =>
{
httpContext.Response.Headers[HeaderNames.CacheControl] = "no-cache";
await next();
});
I am running a set of ASP.NET pages on IIS 7.5, Windows 2008 R2. I do not have access to the ASP.NET source code.
Each of these pages is emitted with the default Content-Type header:
Content-Type: text/html; charset=utf-8
However, these pages are producing KML and as such should instead be emitting this Content-Type header:
Content-Type: application/vnd.google-earth.kml; charset=utf-8
I tried to override the default Content-Type header in IIS Manager as follows:
Default Web Site => Application Folder => IIS Group => HTTP Reponse Headers => Add:
Add Custom HTTP Response Header
Name: [Content-Type]
Value: [application/vnd.google-earth.kml; charset=utf-8]
After doing so, the Content-Type header was changed but not in a desirable way:
text/html; charset=utf-8,application/vnd.google-earth.kml; charset=utf-8
As you can see, instead of replacing the default Content-Type header, the value I provided was appended to the existing Content-Type header.
Question: Is there some way to override the Content-Type header in IIS Manager? Or, is the only solution to acquire the ASP.NET source and explicitly set the Content-Type header there?
How can we change content type in request header of http request for restful web services? From where do we exactly change it?
Add HTTP Header Manager and add your desired header there:
TL;DR To add Content type header you must have HTTP Header Manager associated to HTTP Request
You must add it for :
GET, DELETE, PUT and PATCH require a Content-Type.
Without overriding your request will be sent with defaults as:
Connection: keep-alive
Content-Length: [length of body]
Content-Type: text/plain
Host: [your host]
User-Agent: Apache-HttpClient/4.5.7 (Java/1.8.0_191)
Unlike using postman (advantage over JMeter), where you choose your content type in the same component,
In JMeter you must have HTTP Header Manager which can be added as
Child component of HTTP Request - effect only one request
Same or above HTTP Request's hierarchy - may/will impact other HTTP requests in scope
Notice you can have multiple Header Managers:
JMeter now supports multiple Header Managers. The header entries are merged to form the list for the sampler. If an entry to be merged matches an existing header name, it replaces the previous entry. This allows one to set up a default set of headers, and apply adjustments to particular samplers. Note that an empty value for a header does not remove an existing header, it just replace its value.
Notice you can't use it in multipart/form-data:
When using multipart/form-data, this suppresses the Content-Type and Content-Transfer-Encoding headers; only the Content-Disposition header is sent.
It won't be sent it in redirected urls:
Headers are sent for the initial request, and won't be sent for the redirect. This is generally only a problem for manually created test plans, as a test plan created using a recorder would continue from the redirected URL.
Steps to add HTTP Headers
Create an HTTP Request
Thread Group -> HTTP Request
Right-click on the HTTP Request and add config element "HTTP Header
Manager"
HTTP Request -> Add -> Config Element -> HTTP Cache Manager
Via JMeter UI you can add Request Header:
Thread group scope:
Thread group(right-click)-> Add-> Config Element -> HTTP Header Manager
Request scope (#Override Thread group scope):
request (right-click)-> Add-> Config Element -> HTTP Header Manager