Fossil SCM
Enhance the test-httpmsg command with the new --xfer option and with an optional extra argument to specify the output file.
Commit
450cfbbfac77886dba8e62521d41c2fe74c057bbf31d95e93c39000c4060cde5
Parent
601948b19ba6e44…
1 file changed
+22
-4
+22
-4
| --- src/http.c | ||
| +++ src/http.c | ||
| @@ -479,23 +479,29 @@ | ||
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | /* |
| 482 | 482 | ** COMMAND: test-httpmsg |
| 483 | 483 | ** |
| 484 | -** Usage: %fossil test-httpmsg URL ?PAYLOAD? ?OPTIONS? | |
| 484 | +** Usage: %fossil test-httpmsg ?OPTIONS? URL ?PAYLOAD? ?OUTPUT? | |
| 485 | 485 | ** |
| 486 | 486 | ** Send an HTTP message to URL and get the reply. PAYLOAD is a file containing |
| 487 | 487 | ** the payload, or "-" to read payload from standard input. a POST message |
| 488 | 488 | ** is sent if PAYLOAD is specified and is non-empty. If PAYLOAD is omitted |
| 489 | 489 | ** or is an empty file, then a GET message is sent. |
| 490 | +** | |
| 491 | +** If a second filename (OUTPUT) is given after PAYLOAD, then the reply | |
| 492 | +** is written into that second file instead of being written on standard | |
| 493 | +** output. Use the "--out OUTPUT" option to specify an output file for | |
| 494 | +** a GET request where there is no PAYLOAD. | |
| 490 | 495 | ** |
| 491 | 496 | ** Options: |
| 492 | 497 | ** |
| 493 | 498 | ** --compress Use ZLIB compression on the payload |
| 494 | 499 | ** --mimetype TYPE Mimetype of the payload |
| 495 | 500 | ** --out FILE Store the reply in FILE |
| 496 | 501 | ** -v Verbose output |
| 502 | +** --xfer PAYLOAD in a Fossil xfer protocol message | |
| 497 | 503 | */ |
| 498 | 504 | void test_httpmsg_command(void){ |
| 499 | 505 | const char *zMimetype; |
| 500 | 506 | const char *zInFile; |
| 501 | 507 | const char *zOutFile; |
| @@ -504,22 +510,34 @@ | ||
| 504 | 510 | |
| 505 | 511 | zMimetype = find_option("mimetype",0,1); |
| 506 | 512 | zOutFile = find_option("out","o",1); |
| 507 | 513 | if( find_option("verbose","v",0)!=0 ) mHttpFlags |= HTTP_VERBOSE; |
| 508 | 514 | if( find_option("compress",0,0)!=0 ) mHttpFlags &= ~HTTP_NOCOMPRESS; |
| 515 | + if( find_option("xfer",0,0)!=0 ){ | |
| 516 | + mHttpFlags |= HTTP_USE_LOGIN; | |
| 517 | + mHttpFlags &= ~HTTP_GENERIC; | |
| 518 | + } | |
| 509 | 519 | db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_ANY_SCHEMA, 0); |
| 510 | - if( g.argc!=3 && g.argc!=4 ){ | |
| 511 | - usage("URL ?PAYLOAD?"); | |
| 520 | + verify_all_options(); | |
| 521 | + if( g.argc<3 || g.argc>5 ){ | |
| 522 | + usage("URL ?PAYLOAD? ?OUTPUT?"); | |
| 512 | 523 | } |
| 513 | 524 | zInFile = g.argc==4 ? g.argv[3] : 0; |
| 525 | + if( g.argc==5 ){ | |
| 526 | + if( zOutFile ){ | |
| 527 | + fossil_fatal("output file specified twice: \"--out %s\" and \"%s\"", | |
| 528 | + zOutFile, g.argv[4]); | |
| 529 | + } | |
| 530 | + zOutFile = g.argv[4]; | |
| 531 | + } | |
| 514 | 532 | url_parse(g.argv[2], 0); |
| 515 | 533 | if( g.url.protocol[0]!='h' ){ |
| 516 | 534 | fossil_fatal("the %s command supports only http: and https:", g.argv[1]); |
| 517 | 535 | } |
| 518 | 536 | if( zInFile ){ |
| 519 | 537 | blob_read_from_file(&in, zInFile, ExtFILE); |
| 520 | - if( zMimetype==0 ){ | |
| 538 | + if( zMimetype==0 && (mHttpFlags & HTTP_GENERIC)!=0 ){ | |
| 521 | 539 | if( fossil_strcmp(zInFile,"-")==0 ){ |
| 522 | 540 | zMimetype = "application/x-unknown"; |
| 523 | 541 | }else{ |
| 524 | 542 | zMimetype = mimetype_from_name(zInFile); |
| 525 | 543 | } |
| 526 | 544 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -479,23 +479,29 @@ | |
| 479 | } |
| 480 | |
| 481 | /* |
| 482 | ** COMMAND: test-httpmsg |
| 483 | ** |
| 484 | ** Usage: %fossil test-httpmsg URL ?PAYLOAD? ?OPTIONS? |
| 485 | ** |
| 486 | ** Send an HTTP message to URL and get the reply. PAYLOAD is a file containing |
| 487 | ** the payload, or "-" to read payload from standard input. a POST message |
| 488 | ** is sent if PAYLOAD is specified and is non-empty. If PAYLOAD is omitted |
| 489 | ** or is an empty file, then a GET message is sent. |
| 490 | ** |
| 491 | ** Options: |
| 492 | ** |
| 493 | ** --compress Use ZLIB compression on the payload |
| 494 | ** --mimetype TYPE Mimetype of the payload |
| 495 | ** --out FILE Store the reply in FILE |
| 496 | ** -v Verbose output |
| 497 | */ |
| 498 | void test_httpmsg_command(void){ |
| 499 | const char *zMimetype; |
| 500 | const char *zInFile; |
| 501 | const char *zOutFile; |
| @@ -504,22 +510,34 @@ | |
| 504 | |
| 505 | zMimetype = find_option("mimetype",0,1); |
| 506 | zOutFile = find_option("out","o",1); |
| 507 | if( find_option("verbose","v",0)!=0 ) mHttpFlags |= HTTP_VERBOSE; |
| 508 | if( find_option("compress",0,0)!=0 ) mHttpFlags &= ~HTTP_NOCOMPRESS; |
| 509 | db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_ANY_SCHEMA, 0); |
| 510 | if( g.argc!=3 && g.argc!=4 ){ |
| 511 | usage("URL ?PAYLOAD?"); |
| 512 | } |
| 513 | zInFile = g.argc==4 ? g.argv[3] : 0; |
| 514 | url_parse(g.argv[2], 0); |
| 515 | if( g.url.protocol[0]!='h' ){ |
| 516 | fossil_fatal("the %s command supports only http: and https:", g.argv[1]); |
| 517 | } |
| 518 | if( zInFile ){ |
| 519 | blob_read_from_file(&in, zInFile, ExtFILE); |
| 520 | if( zMimetype==0 ){ |
| 521 | if( fossil_strcmp(zInFile,"-")==0 ){ |
| 522 | zMimetype = "application/x-unknown"; |
| 523 | }else{ |
| 524 | zMimetype = mimetype_from_name(zInFile); |
| 525 | } |
| 526 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -479,23 +479,29 @@ | |
| 479 | } |
| 480 | |
| 481 | /* |
| 482 | ** COMMAND: test-httpmsg |
| 483 | ** |
| 484 | ** Usage: %fossil test-httpmsg ?OPTIONS? URL ?PAYLOAD? ?OUTPUT? |
| 485 | ** |
| 486 | ** Send an HTTP message to URL and get the reply. PAYLOAD is a file containing |
| 487 | ** the payload, or "-" to read payload from standard input. a POST message |
| 488 | ** is sent if PAYLOAD is specified and is non-empty. If PAYLOAD is omitted |
| 489 | ** or is an empty file, then a GET message is sent. |
| 490 | ** |
| 491 | ** If a second filename (OUTPUT) is given after PAYLOAD, then the reply |
| 492 | ** is written into that second file instead of being written on standard |
| 493 | ** output. Use the "--out OUTPUT" option to specify an output file for |
| 494 | ** a GET request where there is no PAYLOAD. |
| 495 | ** |
| 496 | ** Options: |
| 497 | ** |
| 498 | ** --compress Use ZLIB compression on the payload |
| 499 | ** --mimetype TYPE Mimetype of the payload |
| 500 | ** --out FILE Store the reply in FILE |
| 501 | ** -v Verbose output |
| 502 | ** --xfer PAYLOAD in a Fossil xfer protocol message |
| 503 | */ |
| 504 | void test_httpmsg_command(void){ |
| 505 | const char *zMimetype; |
| 506 | const char *zInFile; |
| 507 | const char *zOutFile; |
| @@ -504,22 +510,34 @@ | |
| 510 | |
| 511 | zMimetype = find_option("mimetype",0,1); |
| 512 | zOutFile = find_option("out","o",1); |
| 513 | if( find_option("verbose","v",0)!=0 ) mHttpFlags |= HTTP_VERBOSE; |
| 514 | if( find_option("compress",0,0)!=0 ) mHttpFlags &= ~HTTP_NOCOMPRESS; |
| 515 | if( find_option("xfer",0,0)!=0 ){ |
| 516 | mHttpFlags |= HTTP_USE_LOGIN; |
| 517 | mHttpFlags &= ~HTTP_GENERIC; |
| 518 | } |
| 519 | db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_ANY_SCHEMA, 0); |
| 520 | verify_all_options(); |
| 521 | if( g.argc<3 || g.argc>5 ){ |
| 522 | usage("URL ?PAYLOAD? ?OUTPUT?"); |
| 523 | } |
| 524 | zInFile = g.argc==4 ? g.argv[3] : 0; |
| 525 | if( g.argc==5 ){ |
| 526 | if( zOutFile ){ |
| 527 | fossil_fatal("output file specified twice: \"--out %s\" and \"%s\"", |
| 528 | zOutFile, g.argv[4]); |
| 529 | } |
| 530 | zOutFile = g.argv[4]; |
| 531 | } |
| 532 | url_parse(g.argv[2], 0); |
| 533 | if( g.url.protocol[0]!='h' ){ |
| 534 | fossil_fatal("the %s command supports only http: and https:", g.argv[1]); |
| 535 | } |
| 536 | if( zInFile ){ |
| 537 | blob_read_from_file(&in, zInFile, ExtFILE); |
| 538 | if( zMimetype==0 && (mHttpFlags & HTTP_GENERIC)!=0 ){ |
| 539 | if( fossil_strcmp(zInFile,"-")==0 ){ |
| 540 | zMimetype = "application/x-unknown"; |
| 541 | }else{ |
| 542 | zMimetype = mimetype_from_name(zInFile); |
| 543 | } |
| 544 |