mrmike / Ok2Curl

Convert OkHttp requests into curl logs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Escape `"` in the the headers

BraisGabin opened this issue · comments

From backend I'm receiving a header like this: etag: "estoesunapruebadeetag" the " are part of the etag.

OkHttp when I call this endpoint again it adds this header: If-None-Match: "estoesunapruebadeetag".

But on curl I see this: -H "If-None-Match:"estoesunapruebadeetag"" when it should be -H "If-None-Match:\"estoesunapruebadeetag\"". The " should be escaped.

Hi @BraisGabin,

Thanks for reporting that. I was trying to reproduce this issue with the unit test but looks like this case is not trivial and I need more time to investigate this.

    @Test
    fun `should generate GET command with etag header with escaped value`() {
        // given
        val curlGenerator = CurlCommandGenerator(configuration)
        val request: Request = Request.Builder()
            .url("http://example.com/")
            .header("If-None-Match", "\"estoesunapruebadeetag\"")
            .build()

        // when
        val command = curlGenerator.generate(request)

        // then
        assertEquals("curl -X GET -H \"If-None-Match:\"estoesunapruebadeetag\"\" \"http://example.com/\"", command)
    }

Could you provide more details how OkHttp is retrying this call?

Sorry, I'm not having the time to provide a reproducer and your test is exactly what I was experienced. I think that we can close this issue for now. If I find the time I'll try to create a reproducer but as I say I don't have that time right now.