ews-javascript-api
ews-javascript-api copied to clipboard
Possibility to set User-Agent
We need to set User-Agent for our project as it's required by customer security policy.
In ExchangeSerivceBase.js there is a line that set User-Agent but it is commented out:
// request.headers["User-Agent"] = this.UserAgent || ExchangeServiceBase.defaultUserAgent; //todo:fix -> Noje.js is refusing to set this unsafe header -//
I tried to uncomment it and it seems working fine. At least I got no errors and I can see that the header is set (using override(https) to hijack requests sent, will try wireahark later).
Would it be possible to restore this feature?
Another question if I set user-agent using ExchangeService.UserAgent = 'my-user-agent' it adds ...(ExchangeService/undefined):
set UserAgent(value: string) {
this.userAgent = `${value} (${ExchangeServiceBase.defaultUserAgent})`;
}
why?
because the value for EwsUtilities.BuildVersion is not assigned,
before running anything, somewhere in code call EwsUtilities.BuildVersion = 'default_build_version';, it should then get you ExchangeService/default_build_version.
you can use your custom string there.
I can add this to next iteration, no promise on release timeline. you can however use patch-packages npm package to let you fix this for now.
Ok, thanks. Will try to patch.
I have a stupid question: why don't let set the UserAgent string arbitrarily?
This is based on original c# code by microsoft
I uncommented the line where the user agent is added to the header and in my code I added this line:
EwsUtilities.BuildVersion = 'MY-AGENT';
I got this header:
user-agent:
'ExchangeServicesClient/MY-AGENT (ExchangeServicesClient/undefined)'
So I think the setting user agent should be modified as well. Will do it using patch-module.
PS If I set
ExchangeServiceBase.defaultUserAgent = 'MY-AGENT';
then I got: user-agent: 'ExchangeServicesClient/MY-AGENT (ExchangeServicesClient/'MY-AGENT)'
Thanks