Skip to content

Commit bf18357

Browse files
committed
Enable HTTP/1.0 clients to use Camera.imagearraybase64
1 parent 98d8841 commit bf18357

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

Remote Server/ServerForm.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ private void ProcessRestRequest(HttpListenerContext context)
17671767
response.Headers.Add(HttpResponseHeader.Server, "ASCOM Rest API Server -");
17681768

17691769
// Log the request
1770-
LogMessage1(requestData, SharedConstants.REQUEST_RECEIVED_STRING, string.Format("{0} URL: {1}, Thread: {2}", request.HttpMethod, request.Url.PathAndQuery, Thread.CurrentThread.ManagedThreadId.ToString()));
1770+
LogMessage1(requestData, SharedConstants.REQUEST_RECEIVED_STRING, $"{request.HttpMethod} URL: {request.Url.PathAndQuery}, Protocol: HTTP/{request.ProtocolVersion}, Thread: {Thread.CurrentThread.ManagedThreadId}");
17711771

17721772
// Create a collection of supplied parameters: query variables in the URL string for HTTP GET requests and form parameters from the request body for HTTP PUT requests.
17731773

@@ -4945,7 +4945,26 @@ private void ReturnImageArrayBase64(RequestData requestData)
49454945
}
49464946
long timeToCompressResponse = sw.ElapsedMilliseconds - lastTime; lastTime = sw.ElapsedMilliseconds; // Record the duration
49474947

4948-
requestData.Response.SendChunked = true;
4948+
// Set chunked transfer mode if the requested protocol is HTTP/1.1 or later
4949+
try
4950+
{
4951+
if (requestData.Response.ProtocolVersion.CompareTo(new Version(1, 1)) >= 0) // Protocol is HTTP/1.1 or later
4952+
{
4953+
LogMessage1(requestData, requestData.Elements[URL_ELEMENT_METHOD], $"### Protocol is HTTP/1.1 or later - Setting response.SendChuncked = true");
4954+
requestData.Response.SendChunked = true;
4955+
}
4956+
else // Protocol is HTTP/1.0
4957+
{
4958+
LogMessage1(requestData, requestData.Elements[URL_ELEMENT_METHOD], $"### Protocol is HTTP/1.0 - NOT setting chuncked transfer mode");
4959+
}
4960+
}
4961+
catch (Exception ex)
4962+
{
4963+
// Something went wrong when evaluating the HTTP protocol version or when setting chunked transfer mode. This is not considered fatal here because
4964+
// we are able to use the request object "as-is" without changing it. If there is a significant issue, the request will fail later in the process and will be dealt with then.
4965+
LogException1(requestData, requestData.Elements[URL_ELEMENT_METHOD], $"Exception while evaluating HTTP protocol version or setting chunked mode\r\n{ex}");
4966+
}
4967+
49494968
requestData.Response.AddHeader(SharedConstants.BASE64_HANDOFF_HEADER, SharedConstants.BASE64_HANDOFF_SUPPORTED); // Add a header indicating that the content is base64 serialised
49504969
requestData.Response.ContentType = "image/tiff"; // Must use image/tiff to ensure fast data transmission. All other content types are slower e.g. text/plain takes 8 seconds while image/tiff takes 1 second.
49514970
requestData.Response.ContentLength64 = bytesToSend.Length;

Setup/ASCOM Remote Setup.iss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#define public RemoteClientBaseClassesName "ASCOM.RemoteClientBaseClasses" ; Remote client support DLL name
1616
#define public ASCOMRemoteDocumentationFileName "ASCOM Remote Installation and Configuration.pdf"; ASCOM Remote documentation file
1717

18-
; Specifiy debug or release build; #define public BuildType "Debug" ; Type of build - Release or Debug
19-
#define public BuildType "Release" ; Type of build - Release or Debug
18+
; Specifiy debug or release build#define public BuildType "Debug" ; Type of build - Release or Debug
19+
;#define public BuildType "Release" ; Type of build - Release or Debug
2020

2121
[Setup]
2222
AppID={{0ee690ae-7927-4ee7-b851-f5877c077ff5}

0 commit comments

Comments
 (0)