Skip to content

Commit 9107f51

Browse files
committed
Add exception handling for issues when reading ImageBytes headers.
1 parent 9ab96cb commit 9107f51

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

Remote Server/ServerForm.cs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5489,19 +5489,33 @@ private void ReturnImageArray(RequestData requestData)
54895489
}
54905490
if (DebugTraceState) LogMessage1(requestData, requestData.Elements[URL_ELEMENT_METHOD], $"Response compression type: {compressionType}");
54915491

5492-
// Determine whether the client supports base64 hand-off transfer, if so, this will be used
5493-
if (requestData.Request.Headers[SharedConstants.BASE64_HANDOFF_HEADER] == SharedConstants.BASE64_HANDOFF_SUPPORTED) // Client supports base64 hand-off
5492+
try
5493+
{
5494+
// Determine whether the client supports base64 hand-off transfer, if so, this will be used
5495+
if (requestData.Request.Headers[SharedConstants.BASE64_HANDOFF_HEADER] == SharedConstants.BASE64_HANDOFF_SUPPORTED) // Client supports base64 hand-off
5496+
{
5497+
base64HandoffRequested = true;
5498+
requestData.Response.AddHeader(SharedConstants.BASE64_HANDOFF_HEADER, SharedConstants.BASE64_HANDOFF_SUPPORTED); // Add a header indicating to the client that a binary formatted image is available for faster processing
5499+
if (DebugTraceState) LogMessage1(requestData, requestData.Elements[URL_ELEMENT_METHOD], $"Base64 encoding supported - Header {SharedConstants.BASE64_HANDOFF_SUPPORTED} = {requestData.Request.Headers[SharedConstants.BASE64_HANDOFF_SUPPORTED]}");
5500+
}
5501+
}
5502+
catch (Exception ex)
54945503
{
5495-
base64HandoffRequested = true;
5496-
requestData.Response.AddHeader(SharedConstants.BASE64_HANDOFF_HEADER, SharedConstants.BASE64_HANDOFF_SUPPORTED); // Add a header indicating to the client that a binary formatted image is available for faster processing
5497-
if (DebugTraceState) LogMessage1(requestData, requestData.Elements[URL_ELEMENT_METHOD], $"Base64 encoding supported - Header {SharedConstants.BASE64_HANDOFF_SUPPORTED} = {requestData.Request.Headers[SharedConstants.BASE64_HANDOFF_SUPPORTED]}");
5504+
LogMessage1(requestData, requestData.Elements[URL_ELEMENT_METHOD], $"Exception testing for base64 hand-off header:\r\n{ex}");
54985505
}
54995506

5500-
// Determine whether the client request that the image be returned as a byte array
5501-
if (requestData.Request.Headers[SharedConstants.ACCEPT_HEADER_NAME].ToLowerInvariant().Contains(SharedConstants.IMAGE_BYTES_MIME_TYPE)) // Client supports image bytes transfer
5507+
try
5508+
{
5509+
// Determine whether the client request that the image be returned as a byte array
5510+
if (requestData.Request.Headers[SharedConstants.ACCEPT_HEADER_NAME].ToLowerInvariant().Contains(SharedConstants.IMAGE_BYTES_MIME_TYPE)) // Client supports image bytes transfer
5511+
{
5512+
imageBytesRequested = true;
5513+
if (DebugTraceState) LogMessage1(requestData, requestData.Elements[URL_ELEMENT_METHOD], $"Image bytes requested - Received header {requestData.Request.Headers[SharedConstants.ACCEPT_HEADER_NAME]}");
5514+
}
5515+
}
5516+
catch (Exception ex)
55025517
{
5503-
imageBytesRequested = true;
5504-
if (DebugTraceState) LogMessage1(requestData, requestData.Elements[URL_ELEMENT_METHOD], $"Image bytes requested - Received header {requestData.Request.Headers[SharedConstants.ACCEPT_HEADER_NAME]}");
5518+
LogMessage1(requestData, requestData.Elements[URL_ELEMENT_METHOD], $"Exception testing for image bytes header:\r\n{ex}");
55055519
}
55065520

55075521
sw.Start(); // Start the timing stopwatch

0 commit comments

Comments
 (0)