@@ -659,7 +659,7 @@ public async Task<Note> CreateNote(double latitude, double longitude, string tex
659659 }
660660 #endregion
661661
662- protected async Task < IEnumerable < T > > GetOfType < T > ( string address , Action < HttpRequestMessage > auth = null ) where T : class
662+ protected async Task < IEnumerable < T > > GetOfType < T > ( string address , Func < HttpRequestMessage , string > auth = null ) where T : class
663663 {
664664 var content = await Get ( address , auth ) ;
665665 var streamSource = new XmlOsmStreamSource ( await content . ReadAsStreamAsync ( ) ) ;
@@ -694,7 +694,7 @@ protected string ToString(double number)
694694 #region Http
695695 protected static readonly Func < string , string > Encode = HttpUtility . UrlEncode ;
696696
697- protected async Task < T > Get < T > ( string address , Action < HttpRequestMessage > auth = null ) where T : class
697+ protected async Task < T > Get < T > ( string address , Func < HttpRequestMessage , string > auth = null ) where T : class
698698 {
699699 var content = await Get ( address , auth ) ;
700700 var stream = await content . ReadAsStreamAsync ( ) ;
@@ -703,14 +703,17 @@ protected async Task<T> Get<T>(string address, Action<HttpRequestMessage> auth =
703703 return element ;
704704 }
705705
706- protected async Task < HttpContent > Get ( string address , Action < HttpRequestMessage > auth = null )
706+ protected async Task < HttpContent > Get ( string address , Func < HttpRequestMessage , string > auth = null )
707707 {
708708 using ( HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Get , address ) )
709709 {
710- _logger ? . LogInformation ( $ "GET: { address } ") ;
711- auth ? . Invoke ( request ) ;
710+ var authString = auth ? . Invoke ( request ) ;
711+ if ( ! string . IsNullOrEmpty ( authString ) )
712+ {
713+ authString = " " + authString ;
714+ }
712715 var response = await _httpClient . SendAsync ( request ) ;
713- await VerifyAndLogReponse ( response ) ;
716+ await VerifyAndLogReponse ( response , $ "GET: { address } { authString } " ) ;
714717 return response . Content ;
715718 }
716719 }
@@ -739,36 +742,34 @@ protected async Task<T> Put<T>(string address, HttpContent requestContent = null
739742 /// <param name="message"></param>
740743 /// <param name="url"></param>
741744 /// <param name="method"></param>
742- protected virtual void AddAuthentication ( HttpRequestMessage message , string url , string method = "GET" ) { }
745+ protected virtual string AddAuthentication ( HttpRequestMessage message , string url , string method = "GET" ) { return "No authentication" ; }
743746
744747 protected async Task < HttpContent > SendAuthRequest ( HttpMethod method , string address , HttpContent requestContent )
745748 {
746749 using ( HttpRequestMessage request = new HttpRequestMessage ( method , address ) )
747750 {
748- _logger ? . LogInformation ( $ "{ method } : { address } ") ;
749- AddAuthentication ( request , address , method . ToString ( ) ) ;
751+ var authString = AddAuthentication ( request , address , method . ToString ( ) ) ;
750752 request . Content = requestContent ;
751753 var response = await _httpClient . SendAsync ( request ) ;
752- await VerifyAndLogReponse ( response ) ;
754+ await VerifyAndLogReponse ( response , $ " { method } : { address } { authString } " ) ;
753755 return response . Content ;
754756 }
755757 }
756758
757- protected async Task VerifyAndLogReponse ( HttpResponseMessage response )
759+ protected async Task VerifyAndLogReponse ( HttpResponseMessage response , string extraMessage )
758760 {
761+ var formattedExtraMessage = string . IsNullOrWhiteSpace ( extraMessage ) ? string . Empty : extraMessage + ": " ;
759762 if ( ! response . IsSuccessStatusCode )
760763 {
761764 var message = await response . Content . ReadAsStringAsync ( ) ;
762- message = $ "Request failed: { response . StatusCode } -{ response . ReasonPhrase } { message } ";
765+ message = $ "{ formattedExtraMessage } failed: { response . StatusCode } -{ response . ReasonPhrase } { message } ";
763766 _logger ? . LogError ( message ) ;
764767 throw new OsmApiException ( response . RequestMessage ? . RequestUri , message , response . StatusCode ) ;
765768 }
766769 else
767770 {
768- var message = $ "Request succeeded: { response . StatusCode } - { response . ReasonPhrase } ";
771+ var message = $ "{ formattedExtraMessage } succeeded ";
769772 _logger ? . LogInformation ( message ) ;
770- var headers = string . Join ( ", " , response . Content . Headers . Select ( h => $ "{ h . Key } : { string . Join ( ";" , h . Value ) } ") ) ;
771- _logger ? . LogDebug ( headers ) ;
772773 }
773774 }
774775 #endregion
0 commit comments