github.com/alloyci/alloy-runner@v1.0.1-0.20180222164613-925503ccafd6/network/patch_response.go (about)

     1  package network
     2  
     3  import (
     4  	"net/http"
     5  	"strconv"
     6  	"strings"
     7  )
     8  
     9  type TracePatchResponse struct {
    10  	response *http.Response
    11  
    12  	RemoteState string
    13  	RemoteRange string
    14  }
    15  
    16  func (p *TracePatchResponse) IsAborted() bool {
    17  	if p.RemoteState == "canceled" || p.RemoteState == "failed" {
    18  		return true
    19  	}
    20  
    21  	if p.response.StatusCode == http.StatusForbidden {
    22  		return true
    23  	}
    24  
    25  	return false
    26  }
    27  
    28  func (p *TracePatchResponse) NewOffset() int {
    29  	remoteRangeParts := strings.Split(p.RemoteRange, "-")
    30  	newOffset, _ := strconv.Atoi(remoteRangeParts[1])
    31  
    32  	return newOffset
    33  }
    34  
    35  func NewTracePatchResponse(response *http.Response) *TracePatchResponse {
    36  	return &TracePatchResponse{
    37  		response:    response,
    38  		RemoteState: response.Header.Get("Job-Status"),
    39  		RemoteRange: response.Header.Get("Range"),
    40  	}
    41  }