Fossil SCM

Enhance the test-httpmsg command with the new --xfer option and with an optional extra argument to specify the output file.

drh 2021-12-22 14:03 trunk
Commit 450cfbbfac77886dba8e62521d41c2fe74c057bbf31d95e93c39000c4060cde5
1 file changed +22 -4
+22 -4
--- src/http.c
+++ src/http.c
@@ -479,23 +479,29 @@
479479
}
480480
481481
/*
482482
** COMMAND: test-httpmsg
483483
**
484
-** Usage: %fossil test-httpmsg URL ?PAYLOAD? ?OPTIONS?
484
+** Usage: %fossil test-httpmsg ?OPTIONS? URL ?PAYLOAD? ?OUTPUT?
485485
**
486486
** Send an HTTP message to URL and get the reply. PAYLOAD is a file containing
487487
** the payload, or "-" to read payload from standard input. a POST message
488488
** is sent if PAYLOAD is specified and is non-empty. If PAYLOAD is omitted
489489
** 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.
490495
**
491496
** Options:
492497
**
493498
** --compress Use ZLIB compression on the payload
494499
** --mimetype TYPE Mimetype of the payload
495500
** --out FILE Store the reply in FILE
496501
** -v Verbose output
502
+** --xfer PAYLOAD in a Fossil xfer protocol message
497503
*/
498504
void test_httpmsg_command(void){
499505
const char *zMimetype;
500506
const char *zInFile;
501507
const char *zOutFile;
@@ -504,22 +510,34 @@
504510
505511
zMimetype = find_option("mimetype",0,1);
506512
zOutFile = find_option("out","o",1);
507513
if( find_option("verbose","v",0)!=0 ) mHttpFlags |= HTTP_VERBOSE;
508514
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
+ }
509519
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?");
512523
}
513524
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
+ }
514532
url_parse(g.argv[2], 0);
515533
if( g.url.protocol[0]!='h' ){
516534
fossil_fatal("the %s command supports only http: and https:", g.argv[1]);
517535
}
518536
if( zInFile ){
519537
blob_read_from_file(&in, zInFile, ExtFILE);
520
- if( zMimetype==0 ){
538
+ if( zMimetype==0 && (mHttpFlags & HTTP_GENERIC)!=0 ){
521539
if( fossil_strcmp(zInFile,"-")==0 ){
522540
zMimetype = "application/x-unknown";
523541
}else{
524542
zMimetype = mimetype_from_name(zInFile);
525543
}
526544
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button