xref: /haiku/src/apps/haikudepot/util/LoggingUrlProtocolListener.cpp (revision dfbcbde1e1cbe8eb325b72c84598581b7730c30e)
1 /*
2  * Copyright 2017-2021, Andrew Lindesay <apl@lindesay.co.nz>.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 
6 #include "LoggingUrlProtocolListener.h"
7 
8 #include <File.h>
9 #include <HttpRequest.h>
10 
11 #include "Logger.h"
12 
13 using namespace BPrivate::Network;
14 
15 
LoggingUrlProtocolListener(BString traceLoggingIdentifier,bool traceLogging)16 LoggingUrlProtocolListener::LoggingUrlProtocolListener(
17 	BString traceLoggingIdentifier, bool traceLogging)
18 	:
19 	fTraceLogging(traceLogging),
20 	fTraceLoggingIdentifier(traceLoggingIdentifier),
21 	fContentLength(0)
22 {
23 }
24 
25 
~LoggingUrlProtocolListener()26 LoggingUrlProtocolListener::~LoggingUrlProtocolListener()
27 {
28 }
29 
30 
31 void
BytesWritten(BUrlRequest * caller,size_t bytesWritten)32 LoggingUrlProtocolListener::BytesWritten(BUrlRequest* caller,
33 	size_t bytesWritten)
34 {
35 	fContentLength += bytesWritten;
36 }
37 
38 
39 void
DebugMessage(BUrlRequest * caller,BUrlProtocolDebugMessage type,const char * text)40 LoggingUrlProtocolListener::DebugMessage(BUrlRequest* caller,
41 	BUrlProtocolDebugMessage type, const char* text)
42 {
43 	HDTRACE("url->file <%s>; %s", fTraceLoggingIdentifier.String(), text);
44 }
45 
46 
47 size_t
ContentLength()48 LoggingUrlProtocolListener::ContentLength()
49 {
50 	return fContentLength;
51 }
52