Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpClient.DefaultRequestHeaders.ExpectContinue. What purpose does ExpectContinue serve and under what conditions is it set to true or false.

I've been going through some code and have come across

  private readonly HttpClient _client;
 _client = new HttpClient(clientHandler);
 _client.DefaultRequestHeaders.ExpectContinue = false;

The msdn (https://goo.gl/IoZlB1) doesn't contain much information about ExpectContinue. Also the HttpRequestHeader Enumeration on msdn (https://goo.gl/IoZlB1) describes Expect as

The Expect header, which specifies particular server behaviors that are required by the client.

I'm hoping if someone can shed some light on ExpectContinue. What is the purpose of it and what happens if it is true or false?

like image 584
NullReference Avatar asked Nov 03 '15 08:11

NullReference


1 Answers

The continue status is used mostly for sending the request headers first, to see if the server will allow (accept) the request. If the server says OK, it sends a 100-continue and the client proceeds with the request body. Otherwise, server responds with 417 (Expectation Failed).

Think that you are going to upload a 1 GB file to a specific folder on a server. If you start the transfer directly and the server does not accept files bigger than 512 MB or the folder does not exist, the server will not accept the file, and the transfer will be a waste of resources for both sides.

Check the W3C documentation here

See section 8.2.3 Use of the 100 (Continue) Status

like image 171
Oguz Ozgul Avatar answered Nov 02 '22 14:11

Oguz Ozgul