Questions tagged [go-http]

This tag is for questions related to Go's HTTP package

Go's net/http package provides HTTP client and server implementations.

67 questions
17
votes
2 answers

when to use hijack in golang?

I don't understand why we use hijack, since I can write something into response body directly, could anyone explain this? func writeSome(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "write some thing") } it is same as this: func…
crafet
  • 386
  • 2
  • 5
  • 13
8
votes
0 answers

Dial tcp I/O timeout on simultaneous requests

I am building a tool in Go that needs to make a very large number of simultaneous HTTP requests to many different servers. My initial prototype in Python had no problem doing a few hundred simultaneous requests. However, I have found that in Go this…
Neverbolt
  • 89
  • 1
  • 3
7
votes
1 answer

How do you use Go 1.16 embed features in subfolders/packages?

Go 1.16 is out and I want to use the new embed features. I can get it to work if everything is in the main package. But it's not clear how to handle accessing resources from subfolders/packages. Trying to do it with embed.FS support. e.g. I have a…
PrecisionPete
  • 2,417
  • 4
  • 25
  • 42
7
votes
1 answer

Go hijack client connection

Go language http connection hijacking. I know how to hijack on server side. http://golang.org/pkg/net/http/#example_Hijacker But is there way to hijack it on clients side?
Max
  • 5,896
  • 5
  • 39
  • 82
6
votes
1 answer

what is the benefit of using http hijacker

Go http pkg provide a Hijacker interface, can anyone tell when should I use it. I check the comment, after a Hijack call lets the caller take over the connection, the HTTP server library will not do anything else with the connection. I understand…
carter2000
  • 269
  • 1
  • 2
  • 9
4
votes
1 answer

tls: no renegotiation error on HTTP request

I'm trying to make a simple HTTP request in Go, after directly following the guides I keep getting the same error: local error: tls: no renegotiation I don't quite understand how to interpret this? I know it's not an issue on the server as when I…
4
votes
2 answers

How to determine if I've reached the size limit via Go's MaxBytesReader

I am new to Go, and using Mux to accept HTTP POST data. I would like to use the MaxBytesReader to ensure a client does not overwhelm my server. According to the code, there is a requestBodyLimit boolean which indicates whether that limit has been…
poundifdef
  • 16,490
  • 19
  • 82
  • 126
4
votes
2 answers

Golang - Hijack Arguments

When using Hijack() with a http.ResponseWriter instance Hijack() (net.Conn, *bufio.ReadWriter, error) What is the difference between reading from the net.Conn and the *bufio.ReadWriter?
Kim Byer
  • 253
  • 1
  • 4
  • 11
3
votes
2 answers

Go http client timeout vs context timeout

What's the difference between timeout set in http.Client and timeout set in request's context? I've seen 2 ways of setting timeout in http client. First: ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel() req, err…
Jake Muller
  • 571
  • 8
  • 17
3
votes
1 answer

Difference between functioning of net.Listen and http.ListenAndServe

I'm new to Go and Networking. I know both net.Listen and http.ListenAndServe creates a server. But what is the difference between their functionality?
luffy
  • 95
  • 7
2
votes
1 answer

FileServer handles not found css with MIME type error instead of 404

I’m running a basic http.FileServer to serve a static site and I’ve come across an issue where requests for css files that don’t exist are getting canceled with a MIME type error: Refused to apply style from 'http://localhost:8080/assets/main.css'…
Luke Johnson
  • 103
  • 10
2
votes
0 answers

Go equivalent of Python's requests.Session for making many requests with the same basic authentication?

Consider this example for making an HTTP request in Go with basic authentication: package main import ( "encoding/base64" "fmt" "io/ioutil" "net/http" "net/http/httptest" "strings" ) var userName = "myUserName" var password…
Kurt Peek
  • 34,968
  • 53
  • 191
  • 361
2
votes
2 answers

TLS : Handshake Failure Using GoLang tls client

I'm trying to connect to a server over SSL/TLS using golang http/tsl client which is resulting in 'Handshake Faliure(40)' error, but for some reason, this same endpoint works with CURL command. After some debugging, I have collected the following…
2
votes
2 answers

different Content-Type with httptest and curl

I'm trying this Go code package main import ( "github.com/gorilla/mux" "io" "log" "net/http" ) func HealthCheckHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type",…
JuanPablo
  • 21,182
  • 32
  • 102
  • 155
2
votes
2 answers

Add headers for each HTTP request using client

I know that I can add headers to each HTTP request manually using cli := &http.Client{} req, err := http.NewRequest("GET", "https://myhost", nil) req.Header.Add("X-Test", "true") if err != nil { panic(err) } rsp, err := cli.Do(req) but I want…
Kirill
  • 5,718
  • 3
  • 33
  • 67
1
2 3 4 5