CARVIEW |
Select Language
HTTP/2 200
date: Sun, 12 Oct 2025 05:12:26 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"5cfc23d0492fe3a78bca8f0597592e9e"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com github.githubassets.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com marketplace-screenshots.githubusercontent.com/ copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=AW7JNo7clZWQIOoV8ebdFHEbeiyCqMHM50ZQ92IRRdPYDaBhKB48gYxtUVJcOYU3o06InDbPFDDC99nVFRtMSCCnT847%2FwmjjMEXggjyw1Jfa9%2FvP7lFUrvSFoDnmNs0Jrg%2FUndahEvMZ%2Bcv%2BGLV5M7kHesgxSIBH%2BxWpteDgYm3Q4uoZK%2FxuvtsX2vD1GK2BnQcnnMx3xwMYp7cd6h7s5V3LPqrfQ4bMTLb7ZfL5yjE%2FXbdwMx%2BPhb3N%2BD%2BCBa1b8tNm4dI4N94vCNjrWpCkg%3D%3D--Nr%2BY%2BGVFdWJed6yL--S8B54jD%2BJnRfEiTJhFXCYA%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.220543749.1760245946; Path=/; Domain=github.com; Expires=Mon, 12 Oct 2026 05:12:26 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Mon, 12 Oct 2026 05:12:26 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: B336:364294:C24993:10583CE:68EB38BA
Version of the attoparsec example using the parser combinator Combine. · GitHub
Show Gist options
Save m4rw3r/6370f617199af2d6ca78 to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
Created
August 20, 2015 15:19
-
Star
1
(1)
You must be signed in to star a gist -
Fork
2
(2)
You must be signed in to fork a gist
-
Save m4rw3r/6370f617199af2d6ca78 to your computer and use it in GitHub Desktop.
Version of the attoparsec example using the parser combinator Combine.
This file contains hidden or 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
extern crate combine; | |
use combine::*; | |
use std::fs::File; | |
use std::env; | |
// Seems like combine does not support any kind of zero-copy parsing | |
#[derive(Debug, Clone)] | |
struct Request { | |
method: Vec<u8>, | |
uri: Vec<u8>, | |
version: Vec<u8>, | |
} | |
#[derive(Debug)] | |
struct Header { | |
name: Vec<u8>, | |
value: Vec<Vec<u8>>, | |
} | |
fn is_token(c: u8) -> bool { | |
c < 128 && c > 31 && b"()<>@,;:\\\"/[]?={} \t".iter().position(|&i| i == c).is_none() | |
} | |
fn is_horizontal_space(c: u8) -> bool { c == b' ' || c == b'\t' } | |
fn is_space(c: u8) -> bool { c == b' ' } | |
fn is_not_space(c: u8) -> bool { c != b' ' } | |
fn is_http_version(c: u8) -> bool { c >= b'0' && c <= b'9' || c == b'.' } | |
fn main() { | |
let mut contents: Vec<u8> = Vec::new(); | |
{ | |
use std::io::Read; | |
let mut file = File::open(env::args().nth(1).expect("File to read")).ok().expect("Failed to open file"); | |
let _ = file.read_to_end(&mut contents).unwrap(); | |
} | |
// Making a closure, because parser instances cannot be reused | |
let end_of_line = || (satisfy(|&c| c == b'\r').skip(satisfy(|&c| c == b'\n'))).or(satisfy(|&c| c == b'\n')); | |
// Cannot use char() as it requires a char, instead use satisfy and dereference the pointer to | |
// the item | |
let http_version = satisfy(|&c| c == b'H') | |
.skip(satisfy(|&c| c == b'T')) | |
.skip(satisfy(|&c| c == b'T')) | |
.skip(satisfy(|&c| c == b'P')) | |
.skip(satisfy(|&c| c == b'/')) | |
// Need a map() here to be able to use FromIterator<u8> | |
.with(many1(satisfy(|&c| is_http_version(c)).map(|t: &u8| *t))); | |
let request_line = ( | |
// Yet again, dereferencing pointers before checking if it is a token | |
many1(satisfy(|&c: &u8| is_token(c)).map(|t: &u8| *t)), | |
skip_many1(satisfy(|&c: &u8| is_space(c)).map(|t: &u8| *t)), | |
many1(satisfy(|&c: &u8| is_not_space(c)).map(|t: &u8| *t)), | |
skip_many1(satisfy(|&c: &u8| is_space(c)).map(|t: &u8| *t)), | |
http_version, | |
).map(|(method, _, uri, _, version)| Request { | |
method: method, | |
uri: uri, | |
version: version, | |
}); | |
let message_header_line = ( | |
skip_many1(satisfy(|&c| is_horizontal_space(c))), | |
many1(satisfy(|&c| c != b'\r' && c != b'\n').map(|t: &u8| *t)), | |
end_of_line()) | |
.map(|(_, line, _)| line); | |
let message_header = ( | |
many1(satisfy(|&c| is_token(c)).map(|t: &u8| *t)), | |
satisfy(|&c| c == b':'), | |
many1(message_header_line) | |
).map(|(name, _, value)| Header { | |
name: name, | |
value: value, | |
}); | |
let mut request = ( | |
request_line, | |
end_of_line(), | |
many(message_header), | |
end_of_line() | |
).map(|(request, _, headers, _)| (request, headers)); | |
let mut i = 0; | |
let mut buf = &contents[..]; | |
loop { | |
// Needed for inferrence for many(message_header) | |
let r: Result<((Request, Vec<Header>), _), _> = request.parse(buf); | |
match r { | |
Ok(((_, _), b)) => { | |
i = i + 1; | |
buf = b | |
}, | |
Err(e) => { | |
panic!("{:?}", e); | |
} | |
} | |
if buf.is_empty() { | |
break; | |
} | |
} | |
println!("{:?}", i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.