MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sh_http_method

Function sh_http_method

src/pipeline/pass_shell.c:2151–2187  ·  view source on GitHub ↗

The method curl / wget sends: -X / --request / --method; a body (-d, -F, * --data*, --json, --form*, --post-data / --post-file) POST, -T PUT, -I HEAD, * -G back to GET; default GET. */

Source from the content-addressed store, hash-verified

2149 * --data*, --json, --form*, --post-data / --post-file) POST, -T PUT, -I HEAD,
2150 * -G back to GET; default GET. */
2151static const char *sh_http_method(const sh_argv_t *a, int from) {
2152 static const char *const METHODS[] = {"GET", "POST", "PUT", "PATCH",
2153 "DELETE", "HEAD", "OPTIONS", NULL};
2154 const char *method = "GET";
2155 bool get = false;
2156 for (int i = from; i < a->n; i++) {
2157 const char *w = a->v[i];
2158 if (!w) {
2159 continue;
2160 }
2161 const char *named = NULL;
2162 if (sh_eq(w, "-X") || sh_eq(w, "--request") || sh_eq(w, "--method")) {
2163 named = i + SKIP_ONE < a->n ? a->v[i + SKIP_ONE] : NULL;
2164 } else if (sh_starts(w, "-X") && w[PAIR_LEN]) {
2165 named = w + PAIR_LEN;
2166 } else if (sh_starts(w, "--request=") || sh_starts(w, "--method=")) {
2167 named = strchr(w, '=') + SKIP_ONE;
2168 }
2169 for (int m = 0; named && METHODS[m]; m++) {
2170 if (sh_ieq(named, METHODS[m])) {
2171 return METHODS[m];
2172 }
2173 }
2174 if (sh_eq(w, "-G") || sh_eq(w, "--get")) {
2175 get = true;
2176 } else if (sh_eq(w, "-I") || sh_eq(w, "--head")) {
2177 method = "HEAD";
2178 } else if (sh_eq(w, "-T") || sh_starts(w, "--upload-file")) {
2179 method = "PUT";
2180 } else if (sh_eq(w, "-d") || sh_eq(w, "-F") || sh_starts(w, "--data") ||
2181 sh_starts(w, "--json") || sh_starts(w, "--form") ||
2182 sh_starts(w, "--post-data") || sh_starts(w, "--post-file")) {
2183 method = strcmp(method, "GET") == 0 ? "POST" : method;
2184 }
2185 }
2186 return get && strcmp(method, "POST") == 0 ? "GET" : method;
2187}
2188
2189/* curl / wget with a URL the script states (constant words): an HTTP
2190 * request to it, from the command's function. */

Callers 1

sh_httpFunction · 0.85

Calls 3

sh_eqFunction · 0.85
sh_startsFunction · 0.85
sh_ieqFunction · 0.85

Tested by

no test coverage detected