Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible issue with gzip compressed responses #9

Open
marcoancona opened this issue Oct 11, 2019 · 4 comments
Open

Possible issue with gzip compressed responses #9

marcoancona opened this issue Oct 11, 2019 · 4 comments

Comments

@marcoancona
Copy link

marcoancona commented Oct 11, 2019

The request library does not handle compression by default.
Here is what happens when I try to use NTLM with xhr:

sending ews request
[12:22:46] { url: 'https://mail.ethz.ch/ews/exchange.asmx',
  headers:
   { 'Content-Type': 'text/xml; charset=utf-8',
     Accept: 'text/xml',
     'Accept-Encoding': 'gzip,deflate' },
  type: 'POST',
  data:
   '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><soap:Header><t:RequestServerVersion Version="Exchange2013"></t:RequestServerVersion></soap:Header><soap:Body><m:SyncFolderItems><m:ItemShape><t:BaseShape>IdOnly</t:BaseShape></m:ItemShape><m:SyncFolderId><t:FolderId Id="AAMkAGYwNGUyMjFkLTM3OTktNDg5Ny05NzVjLWMyYTljY2JkM2M3MAAuAAAAAAARKSXOhqJ0QI/Ek83LeF2yAQAZInWUlV8eRp82TZbpfwoPAAAAcIb+AAA="></t:FolderId></m:SyncFolderId><m:SyncScope>NormalItems</m:SyncScope></m:SyncFolderItems></soap:Body></soap:Envelope>' }

The response is not parsed correctly:

{ status: 200,
  headers:
   { 'cache-control': 'private',
     'transfer-encoding': 'chunked',
     'content-type': 'text/xml; charset=utf-8',
     'content-encoding': 'gzip',
     vary: 'Accept-Encoding',
     server: 'Microsoft-IIS/10.0',
     'x-calculatedbetarget': 'mailm111.d.ethz.ch',
     'x-diaginfo': 'MAILM111',
     'x-beserver': 'MAILM111',
     'x-aspnet-version': '4.0.30319',
     'x-powered-by': 'ASP.NET',
     'x-feserver': 'MAILM212',
     date: 'Fri, 11 Oct 2019 10:22:46 GMT',
     connection: 'close' },
  finalUrl: '',
  responseType: '',
  statusText: 'OK',
  responseText:
   '\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0004\u0000��\u0007`\u001cI�%&/m�{�J�J��t�\b�`\u0013$ؐ@\u0010������\u001diG#)�*��eVe]f\u0016@�흼��{���{���;�N\'���?\\fd\u0001l��J�ɞ!���\u001f?~|\u001f?"\u001e�\u001e�\u0016ez��MQ-?�hw��Q�/�լX^|�Ѻ=�>���8z�<:]^�e��Sj�l\u001e5�}4o�գ�w��<_d͘>o�l5�ꋻ��n�o��\b��;�fy}�x��u^S�?)]�-ϫ��+�\u0001�p���b���4y�.�ً�b������\u0003m\u0018|~�Ծ��{;�\u000f~��\u0007��.�\u0010��=�\u0017Ŵ���\u001dO�����t�-/�\r�YL�����Χw��U�(�\u000f���]3�P����W��n�p�������\f�5.nn�],�6[N��\u001e=����<zRͮ�\u001e��B���������YUR�gm�h^�ͪZ6�g\u0016_�p��i�\u000bG���\u0011�\u0003K��\u0017\nx\u0003��$5���YC��z=%�!��j�\u001f��N뺪\u001f��|�=�n�6?��~sv,����/.~�ϧ��U��Nw�o��xs�3��Խ\u0017�>��y�jo�ӿ����;{�ً�/�\'{���\u0007��_�~�t����e��������������������ߧ�Y~���y�v���~�����\u0017��{���՗O����\u0007�g��u�b�{����뷻_��z�;o~⧿�v�W�W\u000f���S.�����>���_�����k�`�\u0007�\u001f�^\u000f_���\u000f^����U���׫��_?�r�{?=�_�x��w�\u0017_��}ޖ5\r����N������/�j�^�|�\'��??{����ɛ�O�`����׷_���o����.��wz���ճ���Z��.\u001e��\u0007����2��r�1�h�����\u0002tz~���\u001d����\u0016_~^�g�{�{��A��w�OϮ��<=����{���y�d��˧;��x�{}�;W_�����u���{����;߾zzzZ��W�O����\u0007��x��\u000f?��?y]��O>����������\u001f|Z���O>+v����O~��ۯ��E��/�S�D���������O��^�����\u0017?}�s||�zSd�/��i��3p��q����\\���yִ`���+0�Q[�s4\u001e��^=avn �71��y����;����`�a����\u0003���\u0017\u0006\u0000\u0000',
  getAllResponseHeaders: [Function],
  getResponseHeader: [Function] }
[12:22:46] [xmldom error]	element parse error: Error: invalid tagName::]^�e��Sj�l 
@#[line:1,col:140]
[12:22:46] [xmldom warning]	unclosed xml attribute 
@#[line:1,col:164]
[12:22:46] [xmldom warning]	attribute "��B���������YUR�gm�h^�ͪZ6�g" missed value!! "��B���������YUR�gm�h^�ͪZ6�g" instead2!! 

I believe the problem is related to request/request#539 of the new request library used by xhr (fetch was not affected by this).
The problem seems to be fixed by adding gzip: true in the request options, although I am not sure this covers 100% of cases.

@marcoancona
Copy link
Author

The workaround is to set AcceptGzipEncoding = false on the ExchangeService, but I believe the defaults for the Service and the response parsers should be compatible with each other.

@gautamsi
Copy link
Member

xhr is still not perfect, it is good that you found solution.

use gzip: true in constructor, all the options of constructors are passed in to the request options.

constructor(requestOptions: CoreOptions);

https://github.com/ewsjs/xhr/blob/5a40d48be49bf0b7a57e9bca128d7cc4824f99b3/src/xhrApi.ts#L277-L228

@marcoancona
Copy link
Author

Yes this also works (and is possibly a better workaround)

@gautamsi
Copy link
Member

I will also activate this setting for ExchangeService to make sure it is still compliant with official spec and you don't need to use custom xhr for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants