@@ -289,57 +289,63 @@ internal static void AddResponseHeader(HttpResponseMessage response, KeyValuePai
289
289
// content header collection
290
290
case "content-type" :
291
291
MediaTypeHeaderValue mediaType = null ;
292
- if ( MediaTypeHeaderValue . TryParse ( header . Value . ToString ( ) , out mediaType ) )
292
+ if ( response . Content != null && MediaTypeHeaderValue . TryParse ( header . Value . ToString ( ) , out mediaType ) )
293
293
{
294
294
response . Content . Headers . ContentType = mediaType ;
295
295
}
296
296
break ;
297
297
case "content-length" :
298
298
long contentLength ;
299
- if ( long . TryParse ( header . Value . ToString ( ) , out contentLength ) )
299
+ if ( response . Content != null && long . TryParse ( header . Value . ToString ( ) , out contentLength ) )
300
300
{
301
301
response . Content . Headers . ContentLength = contentLength ;
302
302
}
303
303
break ;
304
304
case "content-disposition" :
305
305
ContentDispositionHeaderValue contentDisposition = null ;
306
- if ( ContentDispositionHeaderValue . TryParse ( header . Value . ToString ( ) , out contentDisposition ) )
306
+ if ( response . Content != null && ContentDispositionHeaderValue . TryParse ( header . Value . ToString ( ) , out contentDisposition ) )
307
307
{
308
308
response . Content . Headers . ContentDisposition = contentDisposition ;
309
309
}
310
310
break ;
311
311
case "content-encoding" :
312
312
case "content-language" :
313
313
case "content-range" :
314
- response . Content . Headers . Add ( header . Key , header . Value . ToString ( ) ) ;
314
+ if ( response . Content != null )
315
+ {
316
+ response . Content . Headers . Add ( header . Key , header . Value . ToString ( ) ) ;
317
+ }
315
318
break ;
316
319
case "content-location" :
317
320
Uri uri ;
318
- if ( Uri . TryCreate ( header . Value . ToString ( ) , UriKind . Absolute , out uri ) )
321
+ if ( response . Content != null && Uri . TryCreate ( header . Value . ToString ( ) , UriKind . Absolute , out uri ) )
319
322
{
320
323
response . Content . Headers . ContentLocation = uri ;
321
324
}
322
325
break ;
323
326
case "content-md5" :
324
327
byte [ ] value ;
325
- if ( header . Value is string )
326
- {
327
- value = Convert . FromBase64String ( ( string ) header . Value ) ;
328
- }
329
- else
328
+ if ( response . Content != null )
330
329
{
331
- value = header . Value as byte [ ] ;
330
+ if ( header . Value is string )
331
+ {
332
+ value = Convert . FromBase64String ( ( string ) header . Value ) ;
333
+ }
334
+ else
335
+ {
336
+ value = header . Value as byte [ ] ;
337
+ }
338
+ response . Content . Headers . ContentMD5 = value ;
332
339
}
333
- response . Content . Headers . ContentMD5 = value ;
334
340
break ;
335
341
case "expires" :
336
- if ( DateTimeOffset . TryParse ( header . Value . ToString ( ) , out dateTimeOffset ) )
342
+ if ( response . Content != null && DateTimeOffset . TryParse ( header . Value . ToString ( ) , out dateTimeOffset ) )
337
343
{
338
344
response . Content . Headers . Expires = dateTimeOffset ;
339
345
}
340
346
break ;
341
347
case "last-modified" :
342
- if ( DateTimeOffset . TryParse ( header . Value . ToString ( ) , out dateTimeOffset ) )
348
+ if ( response . Content != null && DateTimeOffset . TryParse ( header . Value . ToString ( ) , out dateTimeOffset ) )
343
349
{
344
350
response . Content . Headers . LastModified = dateTimeOffset ;
345
351
}
0 commit comments