How do you remove standard headers from the HTTP response of Azure Functions? - azure

Is it possible to remove these headers?
I have a .NET solution with several Azure functions that show all the header information in the HTTP response when they are called. There is no web.base.config type file that I can add 'removeServerHeader = true' which I have used to solve this problem previously in ASP.NET projects.
However, in my azure function solution there is only a host.json file and I don't think this can be used to do something similar.
I have seen a fix for this in the git repo here but I'm not exactly sure how to implement it so the headers are removed.
Can anyone help with this please? Or point me in the right direction. Thanks!

Firstly the fix you link is about ASP.NET version header, this is fixed in the function v1, the release version is v1.0.11510, so you won't get this header.
Then is about server header, yes in my test I will get this header too with v1 function Here is the fix detail , it removes X-Powered-By and server header and ther version should be 2.0.12493. So actually you don't have to use the v3 function, the latest v2 function already remove these headers.

Related

Azure Web App returns binary file 'modified' with incorrect size

I have an Azure web app that returns a binary file using FileStreamResult. Works fine...
FileStreamResult fsr = File(blobStream, System.Net.Mime.MediaTypeNames.Application.Octet, "testfile.bin");
return fsr;
I copied this code to another web app, returning the exact same blob item, and it returns a 'corrupted' file that is almost 2x larger (65K vs 117K). Both apps are using the same version of .Net, the same Azure account, the same Azure storage account, the response headers are the same...but something must be different!
Update: The FileStreamResult has the correct data/size in the buffer. If I copy the data out of the FileStream (before returning), it's OK. So the FileStreamResult is correct; the problem happens when the response is generated. Something with how FileStreamResult is converted. I've also tried ActionResult, same problem.
Update 2: Still can't figure it out but...it's swapping out the non-UTF-8 chars with the EF BF BD unicode replacement characters. I'm not sure why. I thought the content type of application/octet-stream would indicate the data is not interpreted. Also can't find why one web app does this but the other does not.
You could update the package Swashbuckle.AspNetCore to the latest version 4.0.1.
Here is a similar issue you could refer to.
Finally success...turns out there was an ActionFilterAttribute on the base controller that was forcing the encoding.

Azure Functions NodeJs: Remove Http Response Header

I have an HTTP triggered, NodeJs Azure Function, and I'm looking to remove the "X-Powered-By" header from my response, but have found no way to do so.
I've tried adding both this and this azure site extensions, but neither has worked for me,
Setting the response header manually, i.e. res.headers = { ['x-powered-by']: null } is ineffective.
Based on the comments made on this github issue: https://github.com/Azure/Azure-Functions/issues/290 it would seem that using either extension should have removed the headers you wanted.
Modifying the response headers will likely won't work as they are probably added further down the pipeline by the function host and not overridable, see:
Access Azure Function runtime settings
Azure functions recently removed the x-aspnet-version header, further removal of other headers is tracked as part of the azure-webjobs-script-sdk here
You should leave a comment on the github issue and you can further discuss with the team working on this.
There is an extension called Remove Custom Headers that works for Web Apps but not for functions that have their own resource group. So, what you can do is:
1. Create a regular Web App
2. Create a function and make sure you use the same Hosting Plan as the Web App (do not use Consumption).
3. Once the function is created, install the extension named: "Remove Custom Headers"
4. Restart the function and the headers (Server and X-Powered-By) should disappear.

GET / POST using Clarion

I have Clarion 9 app that I want to be able to communicate with HTTP servers. I come from PHP background. I have 0 idea on what to do.
What I wish to be able to do:
Parse JSON data and convert QUEUE data to JSON [Done]
Have a global variable like 'baseURL' that points to e.g. http://localhost.com [Done]
Call functions such apiConnection.get('/users') would return me the contents of the page. [I'm stuck here]
apiConnection.post('/users', myQueueData) would POST myQueueData contents.
I tried using winhttp.dll by reading it from LibMaker but it didn't read it. Instead, I'm now using wininet.dll which LibMaker successfully created a .lib file for it.
I'm currently using the PROTOTYPE procedures from this code on GitHub https://gist.github.com/ddur/34033ed1392cdce1253c
What I did was include them like:
SimpleApi.clw
PROGRAM
INCLUDE('winInet.equ')
ApiLog QUEUE, PRE(log)
LogTitle STRING(10)
LogMessage STRING(50)
END
MAP
INCLUDE('winInetMap.clw')
END
INCLUDE('equates.clw'),ONCE
INCLUDE('DreamyConnection.inc'),ONCE
ApiConnection DreamyConnection
CODE
IF DreamyConnection.initiateConnection('http://localhost')
ELSE
log:LogTitle = 'Info'
log:LogMessage = 'Failed'
ADD(apiLog)
END
But the buffer that winInet's that uses always returns 0.
I have created a GitHub repository https://github.com/spacemudd/clarion-api with all the code to look at.
I'm really lost in this because I can't find proper documentation of Clarion.
I do not want a paid solution.
It kind of depends which version of Clarion you have.
Starting around v9 they added ClaRunExt which provides this kind of functionality via .NET Interop.
From the help:
Use HTTP or HTTPS to download web pages, or any other type of file. You can also post form data to web servers. Very easy way to send HTTP web requests (and receive responses) to Web Servers, REST Web Services, or standard Web Services, with the most commonly used HTTP verbs; POST, GET, PUT, and DELETE.
Otherwise, search the LibSrc\ directory for "http" and you will get an idea of what is already there. abapi.inc for example, appears to provide a wrapper around wininet.lib.

What is the Azure API version

I'm trying to access the result of a GET request provided by Azure, as shown in the example : https://msdn.microsoft.com/sv-se/library/azure/dn820159.aspx
My problem is that the api-version is a mandatory argument, but I have no idea about what to write inside. I'm a bit lost with the Azure Batch documentation, it doesn't seem to be complete.
I found something in an Azure webpage : https://azure.microsoft.com/en-us/documentation/articles/search-api-versions/ and the api-version was api-version=2015-02-28. However, if I try it in my browser, I have this answer : "key":"Reason","value":"The specified api version string is invalid".
Any idea of what I can put inside the api-version parameter ?
Have a look here
As the time of this writing
The version of the Batch API described here is '2016-07-01.3.1', and
using that version is recommended where possible.
Earlier versions include '2016-02-01.3.0', '2015-12-01.2.1',
'2015-11-01.2.1', '2015-06-01.2.0', '2015-03-01.1.1', and
'2014-10-01.1.0'.
So try specifying '2016-07-01.3.1'

setting Access-Control-Allow-Origin using Rackspace Cloud Java API

I am using the Java API for uploading files to Rackspace Cloud. I am trying to figure out how to set the header "Access-Control-Allow-Origin" on the files that I am uploading. I found another link that talks about setting this header using Python Binding here:
Setting Access-Control-Allow-Origin (CORS) in the Rackspace Cloud Files Python API
Is there a similar API with Java Binding as well? I can't seem to find it.
Thanks!
I'm not much of a Java guy, but per this it looks like metadata needs to be set on your containers, with a key of X-Container-Meta-Access-Control-Allow-Origin, and a value of a space separated list of allowed origins.
Thus you need to use whatever function is used to set container metadata for the jclouds API.
It appears that this could be done on creation like so (based on adaptation of this code):
CreateContainerOptions options = CreateContainerOptions.Builder
.withMetadata(ImmutableMap.of("Access-Control-Allow-Origin", "*"));
swift.getApi().createContainer(Constants.CONTAINER, options);
Looking through the docs, I found the following function in org.jclouds.openstack.swift.CommonSwiftClient:
boolean setContainerMetadata(String container,
Map<String,String> containerMetadata)
It therefore looks like you should be able to do what you're looking for with something like the following:
swift.getApi().setContainerMetadata(container, ImmutableMap.of("Access-Control-Allow-Origin", "*"));

Resources