git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/2] Change how HTTP response body is returned

From
Jeff King <peff@peff.net>
Date
Jan 4, 2019, 10:30 UTC
Message-ID
<20190104103042.GB26185@sigill.intra.peff.net>
In-Reply-To
<20181229194447.157763-2-masayasuzuki@google.com>
On Sat, Dec 29, 2018 at 11:44:46AM -0800, Masaya Suzuki wrote:
Show 15 quoted lines
> +/*
> + * A callback for CURLOPT_WRITEFUNCTION. The return value is the bytes consumed
> + * from ptr.
> + */
>  static size_t rpc_in(char *ptr, size_t eltsize,
>  		size_t nmemb, void *buffer_)
>  {
>  	size_t size = eltsize * nmemb;
> -	struct rpc_state *rpc = buffer_;
> +	struct rpc_in_data *data = buffer_;
> +	long response_code;
> +
> +	if (curl_easy_getinfo(data->slot->curl, CURLINFO_RESPONSE_CODE,
> +			      &response_code) != CURLE_OK)
> +		return size;

This hunk was unexpected to me. The function here is just writing out the data, and I expected we'd handle the error after the whole transfer is done. But we do that anyway eventually via run_slot() (which uses handle_curl_result). I guess the goal here is to start throwing away data when we see an error, rather than storing it?

That makes some sense, though I do wonder if there's any case where curl would call our WRITEFUNCTION before it knows the HTTP status. That implies a body before our header, which seems impossible, though.

> +	if (response_code != 200)
> +		return size;

The current behavior with CURLOPT_FAILONERROR treats codes >= 400 as an error. And in handle_curl_result(), we treat >= 300 as an error (since we only see 3xx for a disabled redirect). I suppose it's unlikely for us to see any success code besides 200, but we probably ought to be following the same rules here.

-Peff
Previous: Junio C HamanoNext: Masaya Suzuki
Message 12 of 29 in “Change how HTTP response body is returned”
  1. 1/2 Change how HTTP response body is returnedMasaya Suzuki, Dec 28, 2018
  2. 2/2 Unset CURLOPT_FAILONERRORMasaya Suzuki, Dec 28, 2018
  3. Eric SunshineDec 28, 2018
  4. Masaya SuzukiDec 28, 2018
  5. Eric SunshineDec 28, 2018
  6. Masaya SuzukiDec 28, 2018
  7. 0/2 Show HTTP headers of failed requests with GIT_CURL_VERBOSEMasaya Suzuki, Dec 29, 2018
  8. 1/2 Change how HTTP response body is returnedMasaya Suzuki, Dec 29, 2018
  9. Junio C HamanoJan 3, 2019
  10. Jeff KingJan 4, 2019
  11. Junio C HamanoJan 4, 2019
  12. Jeff KingJan 4, 2019
  13. 2/2 Unset CURLOPT_FAILONERRORMasaya Suzuki, Dec 29, 2018
  14. Jeff KingJan 4, 2019
  15. Masaya SuzukiJan 7, 2019
  16. 0/5 Show HTTP headers of failed requests with GIT_CURL_VERBOSEMasaya Suzuki, Jan 8, 2019
  17. 1/5 http: support file handles for HTTP_KEEP_ERRORMasaya Suzuki, Jan 8, 2019
  18. SZEDER GáborJan 9, 2019
  19. 2/5 http: enable keep_error for HTTP requestsMasaya Suzuki, Jan 8, 2019
  20. 3/5 remote-curl: define struct for CURLOPT_WRITEFUNCTIONMasaya Suzuki, Jan 8, 2019
  21. 4/5 remote-curl: unset CURLOPT_FAILONERRORMasaya Suzuki, Jan 8, 2019
  22. 5/5 test: test GIT_CURL_VERBOSE=1 shows an errorMasaya Suzuki, Jan 8, 2019
  23. 0/5 Show HTTP headers of failed requests with GIT_CURL_VERBOSEMasaya Suzuki, Jan 10, 2019
  24. 1/5 http: support file handles for HTTP_KEEP_ERRORMasaya Suzuki, Jan 10, 2019
  25. 2/5 http: enable keep_error for HTTP requestsMasaya Suzuki, Jan 10, 2019
  26. 3/5 remote-curl: define struct for CURLOPT_WRITEFUNCTIONMasaya Suzuki, Jan 10, 2019
  27. 4/5 remote-curl: unset CURLOPT_FAILONERRORMasaya Suzuki, Jan 10, 2019
  28. 5/5 test: test GIT_CURL_VERBOSE=1 shows an errorMasaya Suzuki, Jan 10, 2019
  29. Junio C HamanoJan 10, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.