Last post Nov 15, 2016 08:09 AM by PatriceSc
Nov 14, 2016 08:49 AM|oozhn|LINK
I have a RESTFul Webservice that allows user to download files. The user will send a request with a couple of HTTP request headers to specify the files to download.
However, I discovered that the http request headers will get trimmed automatically, for example if the user send the header value - "a", with a space at the end, it will get trimmed and thus the value becomes "a". How can I prevent the values from being trimmed?
Below is my code is to retrieve each header value:
string filename = context.IncomingRequest.Headers["filename"];
"context" refers to WebOperationContext class
Nov 15, 2016 07:26 AM|Brando ZWZ|LINK
According to http header define:
A field value is preceded by optional whitespace. The field value does not include any leading or trailing white space: OWS occurring before the first non-whitespace octet of the field value or after the last non-whitespace octet of the field value
is ignored and should be removed before further processing (as this does not change the meaning of the header field).
So we couldn't disable trimming of HTTP Request Headers.
I suggest you could use some special characters instead of the white space.
And then in your filename replace the special characters with white space.
Nov 15, 2016 08:09 AM|PatriceSc|LINK
Or enclose the string within " characters which will be likely what most dev would expect.