headzoo / surf

Stateful programmatic web browsing in Go.
MIT License
1.49k stars 160 forks source link

Fixing http request handling #19

Closed lalyos closed 9 years ago

lalyos commented 9 years ago

Before this fix all Header handling was adding to the header values, not setting them:

Here is a sample of the traced headers, for calling browser a couple of times

[HACK] before login
===== [DUMP] =====
 GET /account/login/ HTTP/1.1
Host: hub.docker.com
User-Agent: Surf/1.0 (Darwin 14.3.0; go1.4.2)

[HACK] submit login ...
===== [DUMP] =====
 POST /account/login/ HTTP/1.1
Host: hub.docker.com
Referer: https://hub.docker.com/account/login/
User-Agent: Surf/1.0 (Darwin 14.3.0; go1.4.2)
User-Agent: Surf/1.0 (Darwin 14.3.0; go1.4.2)

[HACK] login success
  - csrftoken [] T5CW6NekaS40J9AiARgS8ma7m9lZFBiQ
  - docker_sso_username [] sequenceiq
  - sessionid [] bpvtto7wf0vpg3fdwyzsvxk4tujqj533
===== [DUMP] =====
 GET /u/sequenceiq/alpine-dig/ HTTP/1.1
Host: registry.hub.docker.com
Content-Type: application/x-www-form-urlencoded
Cookie: csrftoken=STwCpsKaEwT9mqfZ5ZTJSmDPf3ZixK5M
Referer: https://hub.docker.com/account/login/
User-Agent: Surf/1.0 (Darwin 14.3.0; go1.4.2)
User-Agent: Surf/1.0 (Darwin 14.3.0; go1.4.2)
User-Agent: Surf/1.0 (Darwin 14.3.0; go1.4.2)
progrium commented 9 years ago

+1 super important fix for our basic use for surf

headzoo commented 9 years ago

Thanks. I'll merge this into the dev branch today, run it through the tests, and merge into master if everything works.

headzoo commented 9 years ago

I merged this pull request into the dev branch, which I'll most likely merge into master later on today.