Created
July 24, 2017 18:31
-
-
Save bramhaghosh/4b4a603c4cc50e09da37b54e99bdbad7 to your computer and use it in GitHub Desktop.
mulitpart range req response
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
var mpbody bytes.Buffer | |
mpw := multipart.NewWriter(&mpbody) | |
defer mpw.Close() | |
mpw.SetBoundary(m.boundary) | |
for _, rng := range ranges { | |
start, end := rng[0], rng[1] | |
mimeh := make(textproto.MIMEHeader) | |
mimeh.Set("Content-Type", m.contentType) | |
mimeh.Set("Content-Range", fmt.Sprintf("bytes %d-%d/%d", start, end, len(m.body))) | |
seg := m.body[start : end+1] | |
pw, err := mpw.CreatePart(mimeh) | |
if err != nil { | |
return err | |
} | |
if _, err := pw.Write(seg); err != nil { | |
return err | |
} | |
} | |
res.ContentLength = int64(len(mpbody.Bytes())) | |
res.Body = ioutil.NopCloser(bytes.NewReader(mpbody.Bytes())) | |
res.Header.Set("Content-Type", fmt.Sprintf("multipart/byteranges; boundary=%s", m.boundary)) | |
return nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment