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

[PATCH] Added Curl Option to Override Request Method

From
Drew Green via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 26, 2022, 11:01 UTC
Message-ID
<pull.1225.git.1650970894143.gitgitgadget@gmail.com>
From: agreenbhm <agreenbhm@gmail.com>

Added support for environment variable "CURLOPT_CUSTOMREQUEST" to allow setting the curl option to override the default request method used by HTTP Git operations. Primary reason for this is to allow support for cloning repositories where only GET requests are allowed but not POSTs. When cloning a repo first a GET is made to the server and then a POST is made to the "git-upload-pack" endpoint. In some corporate environments with strong controls only GET requests are allowed to known repository hosts (such as GitHub) to prevent data leakage by sending data. Using this new environmental variable, a user can set "CURLOPT_CUSTOMREQUEST=GET" which will change the second request from a POST to a GET, bypassing web proxy restrictions on the type of requests allowed. Tested with GitHub, changing the request from POST to GET still results in the expected behavior of the repo successfully being cloned.

Signed-off-by: agreenbhm <agreenbhm@gmail.com>
---
    Added Curl Option to Override Request Method
    
    Added support for environment variable "CURLOPT_CUSTOMREQUEST" to allow
    setting the curl option to override the default request method used by
    HTTP Git operations. Primary reason for this is to allow support for
    cloning repositories where only GET requests are allowed but not POSTs.
    When cloning a repo first a GET is made to the server and then a POST is
    made to the "git-upload-pack" endpoint. In some corporate environments
    with strong controls only GET requests are allowed to known repository
    hosts (such as GitHub) to prevent data leakage by sending data. Using
    this new environmental variable, a user can set
    "CURLOPT_CUSTOMREQUEST=GET" which will change the second request from a
    POST to a GET, bypassing web proxy restrictions on the type of requests
    allowed. Tested with GitHub, changing the request from POST to GET still
    results in the expected behavior of the repo successfully being cloned.
    
    Signed-off-by: agreenbhm agreenbhm@gmail.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1225%2Fagreenbhm%2Fmaster-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1225/agreenbhm/master-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1225
 http.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/http.c b/http.c
index 229da4d1488..2ca13b848a5 100644
--- a/http.c
+++ b/http.c
@@ -1235,6 +1235,8 @@ struct active_request_slot *get_active_slot(void)
 	curl_easy_setopt(slot->curl, CURLOPT_HTTPAUTH, http_auth_methods);
 	if (http_auth.password || curl_empty_auth_enabled())
 		init_curl_http_auth(slot->curl);
+	if(getenv("CURLOPT_CUSTOMREQUEST"))
+		curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, getenv("CURLOPT_CUSTOMREQUEST"));
 
 	return slot;
 }

base-commit: 6cd33dceed60949e2dbc32e3f0f5e67c4c882e1e
-- 
gitgitgadget
Next: Drew Green via GitGitGadget
Message 1 of 5 in “Added Curl Option to Override Request Method”
  1. Added Curl Option to Override Request MethodDrew Green via GitGitGadget, Apr 26, 2022
  2. Added Curl Option to Override Request Method v2Drew Green via GitGitGadget, Apr 26, 2022
  3. brian m. carlsonApr 26, 2022
  4. Drew GreenApr 26, 2022
  5. brian m. carlsonApr 27, 2022

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.