Remove response header in grails - grails

How can I remove a Header from response in grails. I have a filter which filters requests and in case response contains a specific header I want to remove it is this possible?
Thanks,

It looks like the only way to do this is to have your servlet filter wrap the response with an implementation of HttpServletResponseWrapper that filters out the header you want to remove. So you're not physically removing the header, but when the response is generated only the headers that your response wrapper returns will be included in the HTTP response.
I've not tried this, so if it does work, please let me know!

Related

How to use etags for caching?

Can anyone tell me how to pass etag correctly for this url?
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,id&playlistId=UUwpy_3CqtfwM7tg2JgQQQyA&maxResults=50&key={API_KEY}.
I was passing like this, but didn't work.
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,id&playlistId=UUwpy_3CqtfwM7tg2JgQQQyA&maxResults=50&key={API_KEY}&If-None-Match="p4VTdlkQv3HQeTEaXgvLePAydmU/vKZr9jiSytaO7UdTbhKbIrwbX20"
If-None-Match is request header, and not query param. Need set this header in headers of request. https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader

How to format odd headers when adding to the TIdHTTP component via AddValue()

I am using
idhttp.Request.CustomHeaders.AddValue(x,y);
This is working fine for me, but now I have come across a different header and am not sure how to add it or what value, string to use.
In the past, I have used
'SOAPACTION','http://url/action'
But what would I need to do for the mustUnderstand part, or in the ReplyTo and Address parts?
How would I AddValue(x,y) them?
I have tried
...AddValue('SOAPACTION','http://URL/Action');
...AddValue('mustUnderstand','1');
But I am getting errors, and the host IT says that my headers are not correct.
<s:Header>
<a:Action s:mustUnderstand="1">http://URL/Action</a:Action>
<a:MessageID>A Valid GUIID</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">URL STRING</a:To>
</s:Header>
Previous simple headers have worked, but I am not sure how to add these headers.
SOAPAction is a valid HTTP header for SOAP messaging, but mustUnderstand and ReplyTo are not HTTP headers, so DO NOT add them with TIdHTTP.Request.CustomHeaders.AddValue() at all. They are components of the <Header> element inside of a SOAP <Envelope> message, so they belong inside the XML data that you post to the server via TIdHTTP (as per the example XML that you showed). You are confusing HTTP headers and SOAP headers. They are two different things.
If the webserver IT is telling you that your HTTP or SOAP headers are wrong, it should also be telling you what exactly is wrong with them so you can fix it.
This is not an Indy issue. You are simply not preparing your SOAP message the way the webserver is expecting. But we don't have those details to advise you with. The webserver IT does.

Alamofire GET request isn't working correctly

I am sending out a GET request like so.
let parameters: Parameters = [
"filter": ["fruit": "apple"]
]
Alamofire.request(urlStr, method: .get, parameters: parameters, encoding:URLEncoding.default).responseJSON { response in
print(response.request!)
}
However, the GET request doesn't work correctly. I believe the parameters are not correct at all. This is the URL request that is printed out using the following code print(response.request!)
https://api.example.com/fruits?apiKey=1&filter%5Bfruit%5D=apple
However, using postman I can send the correct request and get the correct response using the following URL request.
https://api.example.com/fruits?apiKey=1&filter={"fruit":"apple"}
I don't know how to fix this. I tried many encoding types, but none of it worked. Any tips or suggestions are appreciated
Edit: I do get a response from the server using alamofire, but it isn't correct data because the paramters are ignored. However, the response I get from postman is correct.
Morning Curt,
Since there is no published specification for how to encode collection types, the convention of appending [] to the key for array values (foo[]=1&foo[]=2), and appending the key surrounded by square brackets for nested dictionary values (foo[bar]=baz) [is used].
In my opinion you should really avoid passing array objects in query strings. You could change your request to something like:
apiKey=1&fruit=apple
Where does presence of field fruit itself indicates response should be filtered.
Moreover:
Instead of using GET, you should consider using POST or PUT and passing values via JSON, XML, or another well-defined format. This could require server side changes obviously.
If server side is out of your control, you should consider manually encoding these parameters instead.
Source
You can find here an example of manually encoding.
Happy coding!

Reading response headers in Swagger

I am using swagger 2.1.0. I am able to send a header in a request, thanks to this example.
But now my question, the key which is to send with this example-call is received in a header of the previous response. How can I read the headers of the previous response, so I can extract the value to send?
Maybe better, more simple: How can I read the headers which come with a response?

Assembling SOAP Header manually with Savon

I've been dealing with a "soap message header incorrect" error message when submiting a SOAP request using Savon.
I copy/pasted the exact same xml generated by Savon into SOAPUI and I don't get that error and I get the expected response.
So, since I'm tired of trying different things, I want to assemble my own header without Savon help on that.
What I want to do is something like:
soap.header = "<wbs:Session><wbs:SessionId></wbs:SessionId><wbs:SequenceNumber></wbs:SequenceNumber></wbs:Session>"
However I get this error from Savon:
can't convert Symbol into String
Why?
Thank you in advance.
Its likely caused by the fact you havent set any values.
I was getting this error when I had a hash containing just one custom object on return, as it was trying to access parts of the hash that had automatically been removed. (it removed unnesscary layer of hash for me :#)
I believe the header will only accept a Hash - from the savon.rb page:
Besides the body element, SOAP requests can also contain a header with
additional information. Savon sees this header as just another Hash following
the same conventions as the SOAP body Hash.
soap.header = { "SecretKey" => "secret" }

Resources