// TODO: Put strings into the resources. // public static XFullCorrelationId GetFrom(HttpHeaders headers, bool requirePresence) { headers.EnsureNotNull(nameof(headers)); // if (headers.TryGetValues(name: Name, values: out var headerValues)) { var errorMessagePrologue = $"HTTP header '{Name}' set incorrectly.{Environment.NewLine}"; var headerValuesArray = headerValues.Take(2).ToArray(); if (headerValuesArray.Length == 1 && headerValuesArray[0] != null) { var correlationIdPathString = headerValuesArray[0]; XFullCorrelationId correlationIdPath; try { correlationIdPath = XFullCorrelationId.Parse(idString: correlationIdPathString.Arg(nameof(correlationIdPathString))); } catch (Exception exception) { throw new EonException(message: $"{errorMessagePrologue}Header value is not valid.{Environment.NewLine}\tHeader value:{correlationIdPathString.FmtStr().GNLI2()}", innerException: exception); } return(correlationIdPath); } else if (headerValuesArray.Length > 1) { throw new EonException(message: $"{errorMessagePrologue}Header have multiple values ({headerValuesArray.Length} values), whereas only one value expected."); } else { throw new EonException(message: $"{errorMessagePrologue}Header value is missing."); } }
public static void SetFor(HttpHeaders headers, XFullCorrelationId fullCorrelationId) { headers.EnsureNotNull(nameof(headers)); // var header = CreateFrom(fullCorrelationId: fullCorrelationId); headers.Remove(header.Key); headers.Add(header.Key, header.Value); }
public static void Set(this HttpHeaders headers, string name, string value) { headers.EnsureNotNull(nameof(headers)); name.EnsureNotNull(nameof(name)).EnsureNotEmpty(); // headers.Remove(name); if (!headers.TryAddWithoutValidation(name: name, value: value)) { headers.Add(name: name, value: value); } }