Fossil SCM

Change the --httptrace option to store both the request and the reply in separate text files. Nothing is sent to stderr any more.

drh 2010-12-21 15:28 trunk
Commit abe892304a60f9e90137c410b3587c56541cf6ee
+7 -7
--- src/http.c
+++ src/http.c
@@ -163,26 +163,29 @@
163163
164164
/* When tracing, write the transmitted HTTP message both to standard
165165
** output and into a file. The file can then be used to drive the
166166
** server-side like this:
167167
**
168
- ** ./fossil http <http-trace-1.txt
168
+ ** ./fossil test-http <http-request-1.txt
169169
*/
170170
if( g.fHttpTrace ){
171171
static int traceCnt = 0;
172172
char *zOutFile;
173173
FILE *out;
174174
traceCnt++;
175
- zOutFile = mprintf("http-trace-%d.txt", traceCnt);
176
- printf("HTTP SEND: (%s)\n%s%s=======================\n",
177
- zOutFile, blob_str(&hdr), blob_str(&payload));
175
+ zOutFile = mprintf("http-request-%d.txt", traceCnt);
178176
out = fopen(zOutFile, "w");
179177
if( out ){
180178
fwrite(blob_buffer(&hdr), 1, blob_size(&hdr), out);
181179
fwrite(blob_buffer(&payload), 1, blob_size(&payload), out);
182180
fclose(out);
183181
}
182
+ free(zOutFile);
183
+ zOutFile = mprintf("http-reply-%d.txt", traceCnt);
184
+ out = fopen(zOutFile, "w");
185
+ transport_log(out);
186
+ free(zOutFile);
184187
}
185188
186189
/*
187190
** Send the request to the server.
188191
*/
@@ -278,13 +281,10 @@
278281
}
279282
z[j] = 0;
280283
fossil_fatal("server sends error: %s", z);
281284
}
282285
if( isCompressed ) blob_uncompress(pReply, pReply);
283
- if( g.fHttpTrace ){
284
- /*printf("HTTP RECEIVE:\n%s\n=======================\n",blob_str(pReply));*/
285
- }
286286
287287
/*
288288
** Close the connection to the server if appropriate.
289289
**
290290
** FIXME: There is some bug in the lower layers that prevents the
291291
--- src/http.c
+++ src/http.c
@@ -163,26 +163,29 @@
163
164 /* When tracing, write the transmitted HTTP message both to standard
165 ** output and into a file. The file can then be used to drive the
166 ** server-side like this:
167 **
168 ** ./fossil http <http-trace-1.txt
169 */
170 if( g.fHttpTrace ){
171 static int traceCnt = 0;
172 char *zOutFile;
173 FILE *out;
174 traceCnt++;
175 zOutFile = mprintf("http-trace-%d.txt", traceCnt);
176 printf("HTTP SEND: (%s)\n%s%s=======================\n",
177 zOutFile, blob_str(&hdr), blob_str(&payload));
178 out = fopen(zOutFile, "w");
179 if( out ){
180 fwrite(blob_buffer(&hdr), 1, blob_size(&hdr), out);
181 fwrite(blob_buffer(&payload), 1, blob_size(&payload), out);
182 fclose(out);
183 }
 
 
 
 
 
184 }
185
186 /*
187 ** Send the request to the server.
188 */
@@ -278,13 +281,10 @@
278 }
279 z[j] = 0;
280 fossil_fatal("server sends error: %s", z);
281 }
282 if( isCompressed ) blob_uncompress(pReply, pReply);
283 if( g.fHttpTrace ){
284 /*printf("HTTP RECEIVE:\n%s\n=======================\n",blob_str(pReply));*/
285 }
286
287 /*
288 ** Close the connection to the server if appropriate.
289 **
290 ** FIXME: There is some bug in the lower layers that prevents the
291
--- src/http.c
+++ src/http.c
@@ -163,26 +163,29 @@
163
164 /* When tracing, write the transmitted HTTP message both to standard
165 ** output and into a file. The file can then be used to drive the
166 ** server-side like this:
167 **
168 ** ./fossil test-http <http-request-1.txt
169 */
170 if( g.fHttpTrace ){
171 static int traceCnt = 0;
172 char *zOutFile;
173 FILE *out;
174 traceCnt++;
175 zOutFile = mprintf("http-request-%d.txt", traceCnt);
 
 
176 out = fopen(zOutFile, "w");
177 if( out ){
178 fwrite(blob_buffer(&hdr), 1, blob_size(&hdr), out);
179 fwrite(blob_buffer(&payload), 1, blob_size(&payload), out);
180 fclose(out);
181 }
182 free(zOutFile);
183 zOutFile = mprintf("http-reply-%d.txt", traceCnt);
184 out = fopen(zOutFile, "w");
185 transport_log(out);
186 free(zOutFile);
187 }
188
189 /*
190 ** Send the request to the server.
191 */
@@ -278,13 +281,10 @@
281 }
282 z[j] = 0;
283 fossil_fatal("server sends error: %s", z);
284 }
285 if( isCompressed ) blob_uncompress(pReply, pReply);
 
 
 
286
287 /*
288 ** Close the connection to the server if appropriate.
289 **
290 ** FIXME: There is some bug in the lower layers that prevents the
291
--- src/http_transport.c
+++ src/http_transport.c
@@ -35,10 +35,11 @@
3535
i64 nSent; /* Number of bytes sent */
3636
i64 nRcvd; /* Number of bytes received */
3737
FILE *pFile; /* File I/O for FILE: */
3838
char *zOutFile; /* Name of outbound file for FILE: */
3939
char *zInFile; /* Name of inbound file for FILE: */
40
+ FILE *pLog; /* Log output here */
4041
} transport = {
4142
0, 0, 0, 0, 0, 0, 0
4243
};
4344
4445
/*
@@ -226,10 +227,14 @@
226227
free(transport.pBuf);
227228
transport.pBuf = 0;
228229
transport.nAlloc = 0;
229230
transport.nUsed = 0;
230231
transport.iCursor = 0;
232
+ if( transport.pLog ){
233
+ fclose(transport.pLog);
234
+ transport.pLog = 0;
235
+ }
231236
if( g.urlIsSsh ){
232237
/* No-op */
233238
}else if( g.urlIsHttps ){
234239
#ifdef FOSSIL_ENABLE_SSL
235240
ssl_close();
@@ -301,10 +306,22 @@
301306
fossil_system(zCmd);
302307
free(zCmd);
303308
transport.pFile = fopen(transport.zInFile, "rb");
304309
}
305310
}
311
+
312
+/*
313
+** Log all input to a file. The transport layer will take responsibility
314
+** for closing the log file when it is done.
315
+*/
316
+void transport_log(FILE *pLog){
317
+ if( transport.pLog ){
318
+ fclose(transport.pLog);
319
+ transport.pLog = 0;
320
+ }
321
+ transport.pLog = pLog;
322
+}
306323
307324
/*
308325
** This routine is called when the inbound message has been received
309326
** and it is time to start sending again.
310327
*/
@@ -340,10 +357,14 @@
340357
got = fread(zBuf, 1, N, transport.pFile);
341358
}else{
342359
got = socket_receive(0, zBuf, N);
343360
}
344361
/* printf("received %d of %d bytes\n", got, N); fflush(stdout); */
362
+ if( transport.pLog ){
363
+ fwrite(zBuf, 1, got, transport.pLog);
364
+ fflush(transport.pLog);
365
+ }
345366
return got;
346367
}
347368
348369
/*
349370
** Read N bytes of content from the wire and store in the supplied buffer.
350371
--- src/http_transport.c
+++ src/http_transport.c
@@ -35,10 +35,11 @@
35 i64 nSent; /* Number of bytes sent */
36 i64 nRcvd; /* Number of bytes received */
37 FILE *pFile; /* File I/O for FILE: */
38 char *zOutFile; /* Name of outbound file for FILE: */
39 char *zInFile; /* Name of inbound file for FILE: */
 
40 } transport = {
41 0, 0, 0, 0, 0, 0, 0
42 };
43
44 /*
@@ -226,10 +227,14 @@
226 free(transport.pBuf);
227 transport.pBuf = 0;
228 transport.nAlloc = 0;
229 transport.nUsed = 0;
230 transport.iCursor = 0;
 
 
 
 
231 if( g.urlIsSsh ){
232 /* No-op */
233 }else if( g.urlIsHttps ){
234 #ifdef FOSSIL_ENABLE_SSL
235 ssl_close();
@@ -301,10 +306,22 @@
301 fossil_system(zCmd);
302 free(zCmd);
303 transport.pFile = fopen(transport.zInFile, "rb");
304 }
305 }
 
 
 
 
 
 
 
 
 
 
 
 
306
307 /*
308 ** This routine is called when the inbound message has been received
309 ** and it is time to start sending again.
310 */
@@ -340,10 +357,14 @@
340 got = fread(zBuf, 1, N, transport.pFile);
341 }else{
342 got = socket_receive(0, zBuf, N);
343 }
344 /* printf("received %d of %d bytes\n", got, N); fflush(stdout); */
 
 
 
 
345 return got;
346 }
347
348 /*
349 ** Read N bytes of content from the wire and store in the supplied buffer.
350
--- src/http_transport.c
+++ src/http_transport.c
@@ -35,10 +35,11 @@
35 i64 nSent; /* Number of bytes sent */
36 i64 nRcvd; /* Number of bytes received */
37 FILE *pFile; /* File I/O for FILE: */
38 char *zOutFile; /* Name of outbound file for FILE: */
39 char *zInFile; /* Name of inbound file for FILE: */
40 FILE *pLog; /* Log output here */
41 } transport = {
42 0, 0, 0, 0, 0, 0, 0
43 };
44
45 /*
@@ -226,10 +227,14 @@
227 free(transport.pBuf);
228 transport.pBuf = 0;
229 transport.nAlloc = 0;
230 transport.nUsed = 0;
231 transport.iCursor = 0;
232 if( transport.pLog ){
233 fclose(transport.pLog);
234 transport.pLog = 0;
235 }
236 if( g.urlIsSsh ){
237 /* No-op */
238 }else if( g.urlIsHttps ){
239 #ifdef FOSSIL_ENABLE_SSL
240 ssl_close();
@@ -301,10 +306,22 @@
306 fossil_system(zCmd);
307 free(zCmd);
308 transport.pFile = fopen(transport.zInFile, "rb");
309 }
310 }
311
312 /*
313 ** Log all input to a file. The transport layer will take responsibility
314 ** for closing the log file when it is done.
315 */
316 void transport_log(FILE *pLog){
317 if( transport.pLog ){
318 fclose(transport.pLog);
319 transport.pLog = 0;
320 }
321 transport.pLog = pLog;
322 }
323
324 /*
325 ** This routine is called when the inbound message has been received
326 ** and it is time to start sending again.
327 */
@@ -340,10 +357,14 @@
357 got = fread(zBuf, 1, N, transport.pFile);
358 }else{
359 got = socket_receive(0, zBuf, N);
360 }
361 /* printf("received %d of %d bytes\n", got, N); fflush(stdout); */
362 if( transport.pLog ){
363 fwrite(zBuf, 1, got, transport.pLog);
364 fflush(transport.pLog);
365 }
366 return got;
367 }
368
369 /*
370 ** Read N bytes of content from the wire and store in the supplied buffer.
371
-7
--- src/xfer.c
+++ src/xfer.c
@@ -552,13 +552,10 @@
552552
zCap = db_column_text(&q, 1);
553553
login_set_capabilities(zCap);
554554
g.userUid = db_column_int(&q, 2);
555555
g.zLogin = mprintf("%b", pLogin);
556556
g.zNonce = mprintf("%b", pNonce);
557
- if( g.fHttpTrace ){
558
- fprintf(stderr, "# login [%s] with capabilities [%s]\n", g.zLogin,zCap);
559
- }
560557
}
561558
}
562559
db_finalize(&q);
563560
return rc;
564561
}
@@ -1282,14 +1279,10 @@
12821279
}
12831280
go = 0;
12841281
12851282
/* Process the reply that came back from the server */
12861283
while( blob_line(&recv, &xfer.line) ){
1287
- if( g.fHttpTrace ){
1288
- printf("\rGOT: %.*s", (int)blob_size(&xfer.line),
1289
- blob_buffer(&xfer.line));
1290
- }
12911284
if( blob_buffer(&xfer.line)[0]=='#' ){
12921285
const char *zLine = blob_buffer(&xfer.line);
12931286
if( memcmp(zLine, "# timestamp ", 12)==0 ){
12941287
char zTime[20];
12951288
double rDiff;
12961289
--- src/xfer.c
+++ src/xfer.c
@@ -552,13 +552,10 @@
552 zCap = db_column_text(&q, 1);
553 login_set_capabilities(zCap);
554 g.userUid = db_column_int(&q, 2);
555 g.zLogin = mprintf("%b", pLogin);
556 g.zNonce = mprintf("%b", pNonce);
557 if( g.fHttpTrace ){
558 fprintf(stderr, "# login [%s] with capabilities [%s]\n", g.zLogin,zCap);
559 }
560 }
561 }
562 db_finalize(&q);
563 return rc;
564 }
@@ -1282,14 +1279,10 @@
1282 }
1283 go = 0;
1284
1285 /* Process the reply that came back from the server */
1286 while( blob_line(&recv, &xfer.line) ){
1287 if( g.fHttpTrace ){
1288 printf("\rGOT: %.*s", (int)blob_size(&xfer.line),
1289 blob_buffer(&xfer.line));
1290 }
1291 if( blob_buffer(&xfer.line)[0]=='#' ){
1292 const char *zLine = blob_buffer(&xfer.line);
1293 if( memcmp(zLine, "# timestamp ", 12)==0 ){
1294 char zTime[20];
1295 double rDiff;
1296
--- src/xfer.c
+++ src/xfer.c
@@ -552,13 +552,10 @@
552 zCap = db_column_text(&q, 1);
553 login_set_capabilities(zCap);
554 g.userUid = db_column_int(&q, 2);
555 g.zLogin = mprintf("%b", pLogin);
556 g.zNonce = mprintf("%b", pNonce);
 
 
 
557 }
558 }
559 db_finalize(&q);
560 return rc;
561 }
@@ -1282,14 +1279,10 @@
1279 }
1280 go = 0;
1281
1282 /* Process the reply that came back from the server */
1283 while( blob_line(&recv, &xfer.line) ){
 
 
 
 
1284 if( blob_buffer(&xfer.line)[0]=='#' ){
1285 const char *zLine = blob_buffer(&xfer.line);
1286 if( memcmp(zLine, "# timestamp ", 12)==0 ){
1287 char zTime[20];
1288 double rDiff;
1289

Keyboard Shortcuts

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