Skip to content

Commit

Permalink
remove unknown/unknown Content-Type header (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
atauenis committed Aug 11, 2023
1 parent b69994c commit c909f5c
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions HttpTransit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class HttpTransit
LogWriter Log;

byte[] UTF8BOM = Encoding.UTF8.GetPreamble();
const string NoContentType = "webone/unknown-content-type";

Dictionary<string, string> Variables = new();

Expand All @@ -34,7 +35,7 @@ class HttpTransit
int ResponseCode = 502;
string ResponseBody = ":(";
Stream TransitStream = null;
string ContentType = "text/plain";
string ContentType = NoContentType;
Encoding SourceContentEncoding = Encoding.Default;
Encoding OutputContentEncoding = ConfigFile.OutputEncoding;
bool EnableTransliteration = false;
Expand Down Expand Up @@ -664,16 +665,6 @@ public void ProcessTransit()
ClientResponse.StatusCode = ResponseCode;
ClientResponse.AddHeader("Via", "HTTP/1.0 WebOne/" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);


if (CheckString(ContentType, ConfigFile.TextTypes) || ContentType == "")
{
ClientResponse.AddHeader("Content-Type", ContentType);
}
else
{
ClientResponse.AddHeader("Content-Type", ContentType);
}

if (TransitStream == null)
{
byte[] RespBuffer;
Expand Down Expand Up @@ -1395,7 +1386,7 @@ private void MakeOutput(HttpOperation Operation)
{
HttpStatusCode StatusCode = operation.Response.StatusCode;
Stream ResponseStream = operation.ResponseStream;
string ContentType = operation.ResponseHeaders["Content-Type"] ?? "unknown/unknown";
string ContentType = operation.ResponseHeaders["Content-Type"] ?? NoContentType;
long ContentLength = operation.Response.Content.Headers.ContentLength ?? 0;
this.ContentType = ContentType;
string SrcContentType = ContentType;
Expand Down Expand Up @@ -1513,7 +1504,7 @@ private void MakeOutput(HttpOperation Operation)
if (Program.CheckString(ContentType, ConfigFile.TextTypes))
{
//if server returns text, make edits
Log.WriteLine(" {1} {2}. Body {3}K of {4} [Text].", null, (int)StatusCode, StatusCode, ContentLength / 1024, ContentType);
Log.WriteLine(" {1} {2}. Body {3}K of {4} [Text].", null, (int)StatusCode, StatusCode, ContentLength / 1024, ContentType == NoContentType ? "something" : ContentType);
#if DEBUG
if (Operation.ResponseHeaders["Location"] != null)
{
Expand Down Expand Up @@ -1554,9 +1545,9 @@ private void MakeOutput(HttpOperation Operation)
else
{
if (operation != null)
Log.WriteLine(" {1} {2}. Body {3}K of {4} [Binary].", null, (int)StatusCode, StatusCode, ContentLength / 1024, ContentType);
Log.WriteLine(" {1} {2}. Body {3}K of {4} [Binary].", null, (int)StatusCode, StatusCode, ContentLength / 1024, ContentType == NoContentType ? "something" : ContentType);
else
Log.WriteLine(" {1} {2}. Body is {3} [Binary], incomplete.", null, (int)StatusCode, StatusCode, ContentType);
Log.WriteLine(" {1} {2}. Body is {3} [Binary], incomplete.", null, (int)StatusCode, StatusCode, ContentType == NoContentType ? "something" : ContentType);

#if DEBUG
if (Operation.ResponseHeaders["Location"] != null)
Expand Down

0 comments on commit c909f5c

Please sign in to comment.