square / okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.
https://square.github.io/okhttp/
Apache License 2.0
45.87k stars 9.16k forks source link

HttpLoggingInterceptor didn't Log GET HEADER (e.q. cookies #2774

Closed skauss closed 8 years ago

skauss commented 8 years ago

Hi the HttpLoggingInterceptor didn't support logging of the HTTP GET Header. In my special case I like to debug the cookies which are send to the server on a HTTP GET Request. The Responce header logged work fine.

Regards Stephan

swankjesse commented 8 years ago

Please provide a test case to demonstrate the problem. As-is we have some tests that suggest this is working. okhttp3.logging.HttpLoggingInterceptorTest#headersGet

skauss commented 8 years ago

Hi swankjesse at the end you find my log output with a modified PersistentCookieJar to log the cookies. In this case you see I have valid cookies which are not logged by the HttpLoggingInterceptor. In the HttpLoggingInterceptorTest Test I miss the test with Cookie Header (GET and POST). Also counter for each call would be greate (AtomicInteger) which is increase for every request and logged like --> POST (1) xxx --> END POST (1) <-- END HTTP (1) I have many parallel request..

Log
HttpLoggingInterceptor.Level.BASIC

debugmacros D/OkHttp: --> GET http://mgtest.host.xx/biz-war/streamUX/Android/5/15/c29743ef-3ab3-4afb-8ad0-1287820895d9/interests?lang=de&cq=2&fragment_name=listname&fragment_start=330&fragment_size=30 http/1.1 debugmacros D/PersistentCookieJar: Valid dd=1; domain=host.xx; path=/ debugmacros D/PersistentCookieJar: Valid dd=1; path=/biz-war/streamUX/Android/5/15/c29743ef-3ab3-4afb-8ad0-1287820895d9 debugmacros D/PersistentCookieJar: Valid JSESSIONID=9C16F24AEA848C9841F247F7EB8F9BAE; path=/biz-war/; httponly debugmacros D/PersistentCookieJar: Valid webid=SVBNQkNGNzNKSjhJMTc1OTkyOTk5MjJYX0RF; domain=host.xx; path=/ debugmacros D/PersistentCookieJar: Valid permInfo=1470421793046727282A08082016A08082016; expires=Sun, 03 Aug 2036 09:00:11 GMT; domain=host.xx; path=/ debugmacros D/PersistentCookieJar: Add Cookie dd=1; path=/biz-war/streamUX/Android/5/15/c29743ef-3ab3-4afb-8ad0-1287820895d9 debugmacros D/PersistentCookieJar: dd=1 debugmacros D/OkHttp: <-- 200 OK http://mgtest.host.xx/biz-war/streamUX/Android/5/15/c29743ef-3ab3-4afb-8ad0-1287820895d9/interests?lang=de&cq=2&fragment_name=listname&fragment_start=330&fragment_size=30 (462ms, unknown-length body)


HttpLoggingInterceptor.Level.HEADERS Missing the cookie which is send to the server

debugmacros D/OkHttp: --> GET http://mgtest.host.xx/biz-war/streamUX/Android/5/15/c29743ef-3ab3-4afb-8ad0-1287820895d9/interests?lang=de&cq=2&fragment_name=listname&fragment_start=300&fragment_size=30 http/1.1 debugmacros D/OkHttp: --> END GET debugmacros D/PersistentCookieJar: Valid dd=1; domain=host.xx; path=/ debugmacros D/PersistentCookieJar: Valid dd=1; path=/biz-war/streamUX/Android/5/15/c29743ef-3ab3-4afb-8ad0-1287820895d9 debugmacros D/PersistentCookieJar: Valid JSESSIONID=0445F724978836670D0BB003EDCE1032; path=/biz-war/; httponly debugmacros D/PersistentCookieJar: Valid webid=SVBNSkY1MkRMN1VQMDU0NzMxNjAwODZYX0RF; domain=host.xx; path=/ debugmacros D/PersistentCookieJar: Valid permInfo=1470421793046800882A08082016A08082016; expires=Sun, 03 Aug 2036 09:06:14 GMT; domain=host.xx; path=/ debugmacros D/PersistentCookieJar: Add Cookie dd=1; path=/biz-war/streamUX/Android/5/15/c29743ef-3ab3-4afb-8ad0-1287820895d9 debugmacros D/PersistentCookieJar: dd=1 debugmacros D/OkHttp: <-- 200 OK http://mgtest.host.xx/biz-war/streamUX/Android/5/15/c29743ef-3ab3-4afb-8ad0-1287820895d9/interests?lang=de&cq=2&fragment_name=listname&fragment_start=300&fragment_size=30 (260ms) debugmacros D/OkHttp: Server: nginx debugmacros D/OkHttp: Date: Mon, 08 Aug 2016 07:06:27 GMT debugmacros D/OkHttp: Content-Type: application/json;charset=UTF-8 debugmacros D/OkHttp: Transfer-Encoding: chunked debugmacros D/OkHttp: Connection: keep-alive debugmacros D/OkHttp: Set-Cookie: dd=1; dd=1; JSESSIONID=0445F724978836670D0BB003EDCE1032; webid=SVBNSkY1MkRMN1VQMDU0NzMxNjAwODZYX0RF; permInfo=1470421793046800882A08082016A08082016 debugmacros D/OkHttp: Accept-Charset: big5, big5-hkscs, cesu-8, euc-jp, euc-kr, gb18030, gb2312, gbk, ibm-thai, ibm00858, ibm01140, ibm01141, ibm01142, ibm01143, ibm01144, ibm01145, ibm01146, ibm01147, ibm01148, ibm01149, ibm037, ibm1026, ibm1047, ibm273, ibm277, ibm278, ibm280, ibm284, ibm285, ibm290, ibm297, ibm420, ibm424, ibm437, ibm500, ibm775, ibm850, ibm852, ibm855, ibm857, ibm860, ibm861, ibm862, ibm863, ibm864, ibm865, ibm866, ibm868, ibm869, ibm870, ibm871, ibm918, iso-2022-cn, iso-2022-jp, iso-2022-jp-2, iso-2022-kr, iso-8859-1, iso-8859-13, iso-8859-15, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-9, jis_x0201, jis_x0212-1990, koi8-r, koi8-u, shift_jis, tis-620, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-32be, utf-32le, utf-8, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, windows-31j, x-big5-hkscs-2001, x-big5-solaris, x-compound_text, x-euc-jp-linux, x-euc-tw, x-eucjp-open, x-ibm1006, x-ibm1025, x-ibm1046, x-ibm1097, x-ibm1098, x-ibm1112, x-ibm1122, x-ibm1123, x-ibm1124, x-ibm1364, x-ibm1381, x-ibm1383, x-ibm300, x-ibm33722, x-ibm737, x-ibm833, x-ibm834, x-ibm856, x-ibm874, x-ibm875, x-ibm921, x-ibm922, x-ibm930, x-ibm933, x-ibm935, x-ibm937, x-ibm939, x-ibm942, x-ibm942c, x-ibm943, x-ibm943c, x-ibm948, x-ibm949, x-ibm949c, x-ibm950, x-ibm964, x-ibm970, x-iscii91, x-iso-2022-cn-cns, x-iso-2022-cn-gb, x-iso-8859-11, x-jis0208, x-jisautodetect, x-johab, x-macarabic, x-maccentraleurope, x-maccroatian, x-maccyrillic, x-macdingbat, x-macgreek, x-machebrew, x-maciceland, x-macroman, x-macromania, x-macsymbol, x-macthai, x-macturkish, x-macukraine, x-ms932_0213, x-ms950-hkscs, x-ms950-hkscs-xp, x-mswin-936, x-pck, x-sjis_0213, x-utf-16le-bom, x-utf-32be-bom, x-utf-32le-bom, x-windows-50220, x-windows-50221, x-windows-874, x-windows-949, x-windows-950, x-windows-iso2022jp debugmacros D/OkHttp: <-- END HTTP

Post Missing the cookie which is send to the server

debugmacros D/OkHttp: --> POST https://mgtest.host.xx/biz-war/devsessionUX/Android/5/15/c29743ef-3ab3-4afb-8ad0-1287820895d9/UserLogin?lang=de&cq=1 http/1.1 debugmacros D/OkHttp: Content-Type: application/json; charset=utf-8 debugmacros D/OkHttp: Content-Length: 48 debugmacros D/OkHttp: --> END POST

regards Stephan PS : I use com.squareup.okhttp3:okhttp:3.4.1 ; com.squareup.okhttp3:logging-interceptor:3.4.1

swankjesse commented 8 years ago

Please use a network interceptor instead of an application interceptor if you want to see which cookies are added by OkHttp.

skauss commented 8 years ago

Thanks It works. But I didn't under stand why I have to use a NetworkInterceptor. The JavaDoc didn't light me up.

swankjesse commented 8 years ago

This might help: https://github.com/square/okhttp/wiki/Interceptors

Cookies aren’t added until the request reaches OkHttp’s core.