Request Headers
GET /api/v1/downloads/%7Bpath*%7D?path=localdescription%2F13870%2F47323%2F%E5%B8%83%E5%88%A9%E5%A1%94.pdf&_=1531295086568 HTTP/1.1
Host: localhost:9999
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json, text/javascript, */*; q=0.01
DNT: 1
X-Requested-With: XMLHttpRequest
Authorization: Bearer --token-goes-here--
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
Referer: http://localhost:9999/docs/operations
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: ss-pid=eSjiT4TMSv4XHF8uYmGA; ss-id=Y5dGNYkV6v2P5bo6nmv6
Response Headers
HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Content-Type: application/pdf
Vary: Accept
Server: Microsoft-HTTPAPI/2.0
X-Powered-By: ServiceStack/5,11 NET45 Win32NT/.NET
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, OPTIONS
Access-Control-Allow-Headers: Content-Type
Date: Wed, 11 Jul 2018 14:43:35 GMT
NOTE: the preview does not render the Accept header correctly, the last type is * / * (without the extra spaces) but I see only /
// Interfaces
public interface IDownloadResponse : IReturn<IHttpResult>, IReturn
{
}
// Commands
[Route("/api/v1/downloads/{path*}", Verbs = "GET")]
public class TestDownloadCommand : IDownloadResponse
{
public string Path { get; set; }
}
// Return types
public class DownloadResponse : HttpResult
{
public DownloadResponse(FileInfo fileToReturn)
: base(fileToReturn, true)
{
// Add some custom headers named DowloadFileName and DownloadFileSize
Headers.Add(CustomHttpHeaders.DownloadFileName, fileToReturn.Name);
Headers.Add(CustomHttpHeaders.DownloadFileSize, fileToReturn.Length.ToString());
}
public DownloadResponse(DownloadErrorType errorType, string message)
{
StatusCode = HttpStatusCode.NotFound;
StatusDescription = message;
Headers.Add(CustomHttpHeaders.DownloadErrorType, errorType.ToString());
}
}
// Service
public DownloadResponse Get(TestDownloadCommand command)
{
// Construct the full path from the provided partial path
var path = Path.Combine("c:\\data\\fileattachments", command.Path.Replace("/", "\\"));
return new DownloadResponse(new FileInfo(path));
}
The above service code is just the happy flow (it does not test for file existence, in that case we’d return a DownloadResponse with the error message instead of the FileInfo object)