dzieciou / curl-logger

Logs HTTP requests sent by REST-assured as CURL commands.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

curl customiser

blacky0x0 opened this issue · comments

What is about customising?
Enable or disable parameters or headers like:

  • -i
  • --insecure
  • --verbose
  • --compressed
  • Host
  • Connection
  • User-Agent

It will make curl query very short and simple.

Interesting idea. Can you provide a pull request with an implementation of your idea?

Well I don't know how to implement it carefully. I wrote my own FormattedCurlLoggingInterceptor#process and delete all required strings by pattern with replaceFirst. It's very dirty solution.

@blacky0x0 I know it's been a year since you requested this feature. I have just completed it.

Does it do what you wanted?

There's README.md file in feature/2 branch that explains how to use it.

Sure, I'll check it and write feedback

The Authorization, Content-Type headers and data-binary are on the place.

Yes, that's what I wanted before. It's tidy and looks great.
But I've tested my app and discovered that without User-Agent header the system changes own behaviour because it relies on it.
More precisely, it asks for pin-code.

I want to configure Http2Curl.HEADERS_TO_SKIP_IN_SHORT_FORM to be able to add / remove items.
@dzieciou Can it be configured? What do you think about it?

@blacky0x0

The idea behind the library is to enable reproducing a certain case that occured. As you have shown with your User-Agent example, by removing certain headers curl-logger would generate curl that generates different requests that trigger in different system responses. That would undermine the original purpose of the library.

On the other head, I understand, sometimes we need to modify generated curl to test different variations of the same case. And doing this manually might be tedious. Adding possibility to decide which header to include in curl expression is an easy change but it opens a door for other similar feature requests to remove "--binary-data" parameter, replace "--insecure" parameter with its shorter form "-k", etc.

Therefore, I think modifying curl expression should be an option but it should be done by the user of the library more explicitly, so s/he is aware what exactly is modified. Practically, I am thinking of giving more control to the users on constructing curl:

RestAssuredConfig config = new CurlLoggingRestAssuredConfigBuilder()
  .modifyCurl(curl -> curl.removeHeader("Host").addParameter("-k"))
  .build();

This would require significant change in Http2Curl architecture but it would solve your problem, right?

Updated. Let me know if it does what you wanted.

Exactly!
To be precise I log all requests, responses and curl-commands.
I want to skip all keys and headers which have no matter in specific case.
It will simplify readability of curl-commands.