-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Fr0stM0urne/gzip_decode_fix
Fix for python3 http client when accept-encoding is gzip
- Loading branch information
Showing
42 changed files
with
442 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.log | ||
node_modules | ||
coverage* | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CURL *hnd = curl_easy_init(); | ||
|
||
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET"); | ||
curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har"); | ||
|
||
struct curl_slist *headers = NULL; | ||
headers = curl_slist_append(headers, "accept-encoding: deflate, gzip, br"); | ||
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); | ||
|
||
curl_easy_setopt(hnd, CURLOPT_ACCEPT_ENCODING, ""); | ||
|
||
CURLcode ret = curl_easy_perform(hnd); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(require '[clj-http.client :as client]) | ||
|
||
(client/get "http://mockbin.com/har" {:headers {:accept-encoding "deflate, gzip, br"}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var clientHandler = new HttpClientHandler | ||
{ | ||
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, | ||
}; | ||
var client = new HttpClient(clientHandler); | ||
var request = new HttpRequestMessage | ||
{ | ||
Method = HttpMethod.Get, | ||
RequestUri = new Uri("http://mockbin.com/har"), | ||
}; | ||
using (var response = await client.SendAsync(request)) | ||
{ | ||
response.EnsureSuccessStatusCode(); | ||
var body = await response.Content.ReadAsStringAsync(); | ||
Console.WriteLine(body); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var client = new RestClient("http://mockbin.com/har"); | ||
var request = new RestRequest(Method.GET); | ||
request.AddHeader("accept-encoding", "deflate, gzip, br"); | ||
IRestResponse response = client.Execute(request); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"io" | ||
) | ||
|
||
func main() { | ||
|
||
url := "http://mockbin.com/har" | ||
|
||
req, _ := http.NewRequest("GET", url, nil) | ||
|
||
res, _ := http.DefaultClient.Do(req) | ||
|
||
defer res.Body.Close() | ||
body, _ := io.ReadAll(res.Body) | ||
|
||
fmt.Println(res) | ||
fmt.Println(string(body)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
GET /har HTTP/1.1 | ||
Accept-Encoding: deflate, gzip, br | ||
Host: mockbin.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.prepare("GET", "http://mockbin.com/har") | ||
.setHeader("accept-encoding", "deflate, gzip, br") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
HttpRequest request = HttpRequest.newBuilder() | ||
.uri(URI.create("http://mockbin.com/har")) | ||
.header("accept-encoding", "deflate, gzip, br") | ||
.method("GET", HttpRequest.BodyPublishers.noBody()) | ||
.build(); | ||
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); | ||
System.out.println(response.body()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
OkHttpClient client = new OkHttpClient(); | ||
|
||
Request request = new Request.Builder() | ||
.url("http://mockbin.com/har") | ||
.get() | ||
.addHeader("accept-encoding", "deflate, gzip, br") | ||
.build(); | ||
|
||
Response response = client.newCall(request).execute(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
HttpResponse<String> response = Unirest.get("http://mockbin.com/har") | ||
.header("accept-encoding", "deflate, gzip, br") | ||
.asString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import axios from "axios"; | ||
|
||
const options = { | ||
method: 'GET', | ||
url: 'http://mockbin.com/har', | ||
headers: {'accept-encoding': 'deflate, gzip, br'} | ||
}; | ||
|
||
axios.request(options).then(function (response) { | ||
console.log(response.data); | ||
}).catch(function (error) { | ||
console.error(error); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const options = {method: 'GET', headers: {'accept-encoding': 'deflate, gzip, br'}}; | ||
|
||
fetch('http://mockbin.com/har', options) | ||
.then(response => response.json()) | ||
.then(response => console.log(response)) | ||
.catch(err => console.error(err)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const settings = { | ||
"async": true, | ||
"crossDomain": true, | ||
"url": "http://mockbin.com/har", | ||
"method": "GET", | ||
"headers": { | ||
"accept-encoding": "deflate, gzip, br" | ||
} | ||
}; | ||
|
||
$.ajax(settings).done(function (response) { | ||
console.log(response); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const data = null; | ||
|
||
const xhr = new XMLHttpRequest(); | ||
xhr.withCredentials = true; | ||
|
||
xhr.addEventListener("readystatechange", function () { | ||
if (this.readyState === this.DONE) { | ||
console.log(this.responseText); | ||
} | ||
}); | ||
|
||
xhr.open("GET", "http://mockbin.com/har"); | ||
xhr.setRequestHeader("accept-encoding", "deflate, gzip, br"); | ||
|
||
xhr.send(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
val client = OkHttpClient() | ||
|
||
val request = Request.Builder() | ||
.url("http://mockbin.com/har") | ||
.get() | ||
.addHeader("accept-encoding", "deflate, gzip, br") | ||
.build() | ||
|
||
val response = client.newCall(request).execute() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var axios = require("axios").default; | ||
|
||
var options = { | ||
method: 'GET', | ||
url: 'http://mockbin.com/har', | ||
headers: {'accept-encoding': 'deflate, gzip, br'} | ||
}; | ||
|
||
axios.request(options).then(function (response) { | ||
console.log(response.data); | ||
}).catch(function (error) { | ||
console.error(error); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const fetch = require('node-fetch'); | ||
|
||
let url = 'http://mockbin.com/har'; | ||
|
||
let options = {method: 'GET', headers: {'accept-encoding': 'deflate, gzip, br'}}; | ||
|
||
fetch(url, options) | ||
.then(res => res.json()) | ||
.then(json => console.log(json)) | ||
.catch(err => console.error('error:' + err)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const http = require("http"); | ||
|
||
const options = { | ||
"method": "GET", | ||
"hostname": "mockbin.com", | ||
"port": null, | ||
"path": "/har", | ||
"headers": { | ||
"accept-encoding": "deflate, gzip, br" | ||
} | ||
}; | ||
|
||
const req = http.request(options, function (res) { | ||
const chunks = []; | ||
|
||
res.on("data", function (chunk) { | ||
chunks.push(chunk); | ||
}); | ||
|
||
res.on("end", function () { | ||
const body = Buffer.concat(chunks); | ||
console.log(body.toString()); | ||
}); | ||
}); | ||
|
||
req.end(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const request = require('request'); | ||
|
||
const options = { | ||
method: 'GET', | ||
url: 'http://mockbin.com/har', | ||
headers: {'accept-encoding': 'deflate, gzip, br'} | ||
}; | ||
|
||
request(options, function (error, response, body) { | ||
if (error) throw new Error(error); | ||
|
||
console.log(body); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const unirest = require("unirest"); | ||
|
||
const req = unirest("GET", "http://mockbin.com/har"); | ||
|
||
req.headers({ | ||
"accept-encoding": "deflate, gzip, br" | ||
}); | ||
|
||
req.end(function (res) { | ||
if (res.error) throw new Error(res.error); | ||
|
||
console.log(res.body); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
NSDictionary *headers = @{ @"accept-encoding": @"deflate, gzip, br" }; | ||
|
||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mockbin.com/har"] | ||
cachePolicy:NSURLRequestUseProtocolCachePolicy | ||
timeoutInterval:10.0]; | ||
[request setHTTPMethod:@"GET"]; | ||
[request setAllHTTPHeaderFields:headers]; | ||
|
||
NSURLSession *session = [NSURLSession sharedSession]; | ||
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request | ||
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { | ||
if (error) { | ||
NSLog(@"%@", error); | ||
} else { | ||
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; | ||
NSLog(@"%@", httpResponse); | ||
} | ||
}]; | ||
[dataTask resume]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
open Cohttp_lwt_unix | ||
open Cohttp | ||
open Lwt | ||
|
||
let uri = Uri.of_string "http://mockbin.com/har" in | ||
let headers = Header.add (Header.init ()) "accept-encoding" "deflate, gzip, br" in | ||
|
||
Client.call ~headers `GET uri | ||
>>= fun (res, body_stream) -> | ||
(* Do stuff with the result *) |
Oops, something went wrong.