ktorio / ktor

Framework for quickly creating connected applications in Kotlin with minimal effort
https://ktor.io
Apache License 2.0
13.09k stars 1.07k forks source link

The DefaultRequest feature overwrites any user specific data #877

Open ansman opened 5 years ago

ansman commented 5 years ago

Ktor Version

1.1.1

Ktor Engine Used(client or server and name)

N/A

JVM Version, Operating System and Relevant Context

N/A

Feedback

When using the DefaultRequest feature it prevents the caller being able to specify its own values.

For example if you do this:

defaultRequest {
  url {
    host = "example.com"
  }
}

all requests will always be against the host example.com even if a user does this:

client.call(Url("https://google.com/foo"))

If anything the name of the feature is misleading and should perhaps be called AllRequests instead.

This is especially hard since a lot of properties in Url have default values of their own so it's hard to know if they have been set explicitly or not.

Tammo0987 commented 5 years ago

Same for the http method here. I was wondering many hours about my bug until i find out, i can not overwrite the default method even if i specify. I would be nice to change the name or to implement something, that a request can overwrite default values.

ColinHebert commented 5 years ago

@e5l, what's the status of this one? Can we update the documentation/naming of the feature to RequestOverride if the behaviour is not providing default value but overriding values set by the user?

cdlans commented 4 years ago

I tried to set the default scheme and host like this:

defaultRequest {
    url(scheme = "https", host = "127.0.0.1")
}

But this means that the default path is now always "/" and I cannot override it in a request. This defaultRequest feature is pretty useless like this :(

My suspicion is that is has something to do with the HttpRequestData being immutable. Maybe once it is set any following request cannot change it anymore?

What do you think @e5l ?

oleg-larshin commented 4 years ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.