Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set Content-Type on GET requests #6

Closed
wendigo opened this issue Nov 24, 2015 · 9 comments
Closed

Can't set Content-Type on GET requests #6

wendigo opened this issue Nov 24, 2015 · 9 comments

Comments

@wendigo
Copy link

wendigo commented Nov 24, 2015

package main
import "github.com/valyala/fasthttp"
import "fmt"

func main() {
    header := fasthttp.RequestHeader{}

    header.SetRequestURI("http://localhost/test")
    header.Set("Accept", "application/json")
    header.Set("Arbitrary", "should-be-present")
    header.SetContentType("application/json")
    header.Set("Content-Type", "application/json")
    fmt.Printf("Header is: %s\n", string(header.String()))
}

Actual result:

Header is: GET http://localhost/test HTTP/1.1
User-Agent: fasthttp client
Accept: application/json
Arbitrary: should-be-present

According to the RFC2616 section 7.2.1 Content-Type should be set on methods containing entity but RFC does not prohibit to set it on other methods. Some APIs are using content-type to select API version on GET requests.

@abacaj
Copy link

abacaj commented Nov 24, 2015

Looks to me like it does set the content-type, but it does not print it with the String() method.

Validate this with fmt.Printf("Content-Type: %s\n", string(header.ContentType()))

@wendigo
Copy link
Author

wendigo commented Nov 25, 2015

It's not sent over the wire. Double checked it.

@wendigo
Copy link
Author

wendigo commented Nov 25, 2015

@AlekSi
Copy link

AlekSi commented Nov 26, 2015

So there is no way to set for PUT too?

@valyala
Copy link
Owner

valyala commented Nov 28, 2015

Fixed

Thanks for the bug report :)

@valyala valyala closed this as completed Nov 28, 2015
@valyala
Copy link
Owner

valyala commented Nov 29, 2015

So there is no way to set for PUT too?

@AlekSi, PUT requests are now supported - see the commit 6a340b7 .

@wendigo
Copy link
Author

wendigo commented Dec 2, 2015

👍

@AlekSi
Copy link

AlekSi commented Dec 2, 2015

What about PATCH?

@valyala
Copy link
Owner

valyala commented Dec 2, 2015

@AlekSi , done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants