question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

change in behaviour of POST between 1.14.0 and 1.15.0

See original GitHub issue

It seems a change was introduced sometime in 1.15.0

This used to work

    fun getSessionInfo(tokenId: String): AmSession {
        logger.debug { "fetching info for session: $tokenId" }
        val (req, res, result) =
            http.request(
                method = Method.POST,
                path = "/json/sessions?_action=getSessionInfo&tokenId=$tokenId"
            )
                    .header("Accept-API-Version" to "resource=2.0")
                    .header("Content-Type" to "application/json")
                    .responseString()
        logger.debug { "\n${req.cUrlString()}\n--> $req\n$res" }
        result.fold({ d ->
            return Json().parse(d)
        }, { err ->
            throw err.exception
        })
    }

and it sent this request

$ curl -i -X POST -H "Accept-Encoding:compress;q=0.5, gzip;q=1.0" -H "Content-Type:application/json" -H "Accept:application/json" -H "Accept-API-Version:resource=2.0" https://authserver/json/sessions?_action=getSessionInfo&tokenId=d5zqRsYnIPTqXvZRZGvdEdOB9Gs.*AAJTSQACMDIAAlNLABxPWFZLMHRhMHBHeXl6YjMrQ1h5Wk5LdGJubFk9AAJTMQACMDE.*
--> "Body : (empty)"
"Headers : (4)"
Accept-Encoding : compress;q=0.5, gzip;q=1.0
Content-Type : application/json
Accept : application/json
Accept-API-Version : resource=2.0

Notice the content type is “application/json” as is expected due to it being requested in code example on line 10

however in newer versions the request is this, notice the content type header being appended for some reason, instead of overwritting

$ curl -i -X POST -H "Accept-Encoding:compress;q=0.5, gzip;q=1.0" -H "Content-Type:application/x-www-form-urlencoded; application/json" -H "Accept:application/json" -H "Accept-API-Version:resource=2.0" https://authserver/json/sessions?_action=getSessionInfo&tokenId=d5zqRsYnIPTqXvZRZGvdEdOB9Gs.*AAJTSQACMDIAAlNLABxPWFZLMHRhMHBHeXl6YjMrQ1h5Wk5LdGJubFk9AAJTMQACMDE.*
--> --> https://authserver/json/sessions?_action=getSessionInfo&tokenId=d5zqRsYnIPTqXvZRZGvdEdOB9Gs.*AAJTSQACMDIAAlNLABxPWFZLMHRhMHBHeXl6YjMrQ1h5Wk5LdGJubFk9AAJTMQACMDE.*
"Body : (empty)"
"Headers : (4)"
Accept-Encoding : compress;q=0.5, gzip;q=1.0
Content-Type : application/x-www-form-urlencoded; application/json
Accept : application/json
Accept-API-Version : resource=2.0

content type now for whatever reason is Content-Type : application/x-www-form-urlencoded; application/json

The server in this instance cant handle that, but the issue is that Fuel is doing something other than what the code tells it to do, it should send Content-Type : application/json as that is what was specified in code

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
markGilchristcommented, Aug 9, 2018

@SleeplessByte @fnunezkanut The reason this was added was to support multiple headers by the same key.

if you change your code from

.header("Accept-API-Version" to "resource=2.0")
                    .header("Content-Type" to "application/json")
                    .responseString()

to

.header(mapOf("Accept-API-Version" to "resource=2.0", "Content-Type" to "application/json"))

I believe that it will overwrite the values if that is what you require. If I have any of the above wrong then please let me know and I will investigate further

1reaction
SleeplessBytecommented, Aug 9, 2018

@kittinunf @markGilchrist

Content-Type is not a header that can be appended to. Changing this into something like

fun header(vararg pairs: Pair<String, Any>?): Request {
    headers.delete(key)
    return appendHeader(pairs)
}

fun appendHeader(pairs: Pair<String, Any>?): Request {
    pairs.filterNotNull().forEach { (key,value) ->
        if (!headers.containsKey(key)) {
            headers += Pair(key, value.toString())
        } else {
            headers[key] =  headers.getValue(key).let { "$it; $value" }
        }
    }
    return this
}

allows you to keep the old behaviour whilst supporting the new behaviour.

Read more comments on GitHub >

github_iconTop Results From Across the Web

tensorflow + numpy compatibility? · Issue #31249 - GitHub
The warning is harmless to end users, and there is no need to downgrade. Aside from emitting a warning, the behavior has not...
Read more >
The conflict is caused by: The user requested tensorboard ...
The key here is this: The conflict is caused by: The user requested tensorboard==2.1.0 tensorflow 1.15.4 depends on tensorboard<1.16.0 and > ...
Read more >
Release 1.15.0
TensorFlow GPU binaries are now built against CUDA 10 and TensorRT 5.0. Support for Python3.7 on all operating systems. Moved NCCL to core....
Read more >
#5328 (ODE solver behaves erratically in two MultiBody ...
Summary changed from ODE solver behaves erratically in two MuliBody examples (issue with state selection?) to ODE solver behaves erratically in two MultiBody ......
Read more >
TensorFlow for Jetson Platform Release Notes
As of the 20.02 release, the TensorFlow package has been renamed from tensorflow-gpu to tensorflow . This change will only affect the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found