Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs
/// <summary>
/// Writes to response output stream and returns response time
/// </summary>
/// <param name="context"></param>
/// <param name="data"></param>
/// <param name="httpStatus"></param>
/// <param name="contentType"></param>
/// <returns>double? - response time</returns>
Writes to response output stream and returns response time
Writes to response output stream and returns response time
private async Task<bool> TryWriteResponse(HttpListenerContext context, string data, HttpStatusCode httpStatus = HttpStatusCode.OK, string contentType = "application/json", ServiceCallEvent serviceCallEvent = null)
        {
            context.Response.Headers.Add(GigyaHttpHeaders.ProtocolVersion, HttpServiceRequest.ProtocolVersion);
            var body = Encoding.UTF8.GetBytes(data ?? "");
            context.Response.StatusCode = (int)httpStatus;
            context.Response.ContentLength64 = body.Length;
            context.Response.ContentType = contentType;
            context.Response.Headers.Add(GigyaHttpHeaders.DataCenter, Environment.Zone);
            context.Response.Headers.Add(GigyaHttpHeaders.Environment, Environment.DeploymentEnvironment);
            context.Response.Headers.Add(GigyaHttpHeaders.ServiceVersion, AppInfo.Version.ToString());
            context.Response.Headers.Add(GigyaHttpHeaders.ServerHostname, CurrentApplicationInfo.HostName);
            context.Response.Headers.Add(GigyaHttpHeaders.SchemaHash, ServiceSchema.Hash);
            try
            {
                await WriteResponseAndMeasureTime(context, body, serviceCallEvent);
                return true;
            }
            catch (HttpListenerException writeEx)
            {
                if (serviceCallEvent != null)
                    serviceCallEvent.Exception = writeEx;
                Log.Warn(_ => _("HttpServiceListener: Failed to write the response of a service call. See exception and tags for details.",
                    exception: writeEx,
                    unencryptedTags: new
                    {
                        remoteEndpoint = context.Request.RemoteEndPoint,
                        rawUrl = context.Request.RawUrl,
                        status = httpStatus
                    },
                    encryptedTags: new { response = data }));
                return false;
            }
        }
private async Task < bool > TryWriteResponse ( HttpListenerContext context , string data , HttpStatusCode httpStatus = HttpStatusCode . OK , string contentType = " " , ServiceCallEvent serviceCallEvent = null ) { context . Response . Headers . Add ( GigyaHttpHeaders . ProtocolVersion , HttpServiceRequest . ProtocolVersion ) ; var body = Encoding . UTF8 . GetBytes ( data ?? " " ) ; context . Response . StatusCode = ( int ) httpStatus ; context . Response . ContentLength64 = body . Length ; context . Response . ContentType = contentType ; context . Response . Headers . Add ( GigyaHttpHeaders . DataCenter , Environment . Zone ) ; context . Response . Headers . Add ( GigyaHttpHeaders . Environment , Environment . DeploymentEnvironment ) ; context . Response . Headers . Add ( GigyaHttpHeaders . ServiceVersion , AppInfo . Version . ToString ( ) ) ; context . Response . Headers . Add ( GigyaHttpHeaders . ServerHostname , CurrentApplicationInfo . HostName ) ; context . Response . Headers . Add ( GigyaHttpHeaders . SchemaHash , ServiceSchema . Hash ) ; try { await WriteResponseAndMeasureTime ( context , body , serviceCallEvent ) ; return true ; } catch ( HttpListenerException writeEx ) { if ( serviceCallEvent != null ) serviceCallEvent . Exception = writeEx ; Log . Warn ( _ => _ ( " " , exception : writeEx , unencryptedTags : new { remoteEndpoint = context . Request . RemoteEndPoint , rawUrl = context . Request . RawUrl , status = httpStatus } , encryptedTags : new { response = data } ) ) ; return false ; } }
Writes to response output stream and returns response time
Writes to response output stream and returns response time
// For some reason, HttpListener.IgnoreWriteExceptions doesn't work here.
double. - response time
double . - response time
context
HttpListenerContext
None
data
string
None
httpStatus
HttpStatusCode
None
contentType
string
None
serviceCallEvent
ServiceCallEvent